blob: 07231f6472a0b739ac1c79f5aecb13943a350825 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]65bfd9972012-10-19 03:39:3718#include "cc/switches.h"
[email protected]7a846df2012-09-20 19:17:3919#include "content/browser/browser_plugin/browser_plugin_embedder.h"
20#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5921#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1922#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1923#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0424#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4625#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1226#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1627#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3228#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5429#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0530#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0031#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]678c0362012-12-05 08:02:4432#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]f3b1a082011-11-18 00:34:3033#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3234#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5035#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3336#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3737#include "content/browser/web_contents/interstitial_page_impl.h"
38#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]b5a40842012-11-28 15:26:1139#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]d2353452012-01-19 19:53:5640#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3941#include "content/common/browser_plugin_messages.h"
[email protected]795c28972012-12-06 06:13:3942#include "content/common/icon_messages.h"
[email protected]ce9751942011-09-21 01:57:2443#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5144#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0245#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5746#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5847#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1148#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2049#include "content/public/browser/color_chooser.h"
[email protected]2a5e9d02013-01-20 01:09:2550#include "content/public/browser/compositor_util.h"
[email protected]87f3c082011-10-19 18:07:4451#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3652#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1753#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1454#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4655#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1556#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0057#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2758#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0059#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3760#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1461#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3262#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3463#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3864#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4265#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2566#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1067#include "content/public/browser/web_contents_view.h"
[email protected]3c788372013-01-10 08:34:2868#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2169#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4870#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1871#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5472#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0373#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1674#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2975#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5476#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3477#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3778#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5679#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1680#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0182#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5284#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2485#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3686#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3187#include "webkit/glue/webpreferences.h"
88
[email protected]583418cc2013-01-17 14:01:1089#if defined(OS_ANDROID)
90#include "content/browser/android/date_time_chooser_android.h"
91#endif
92
[email protected]f66df822012-05-18 16:52:1793#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5094#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4195#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5796#endif
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]c71fe6402012-08-15 15:22:5598#if defined(USE_AURA) && defined(USE_X11)
[email protected]54944cde2012-12-09 09:24:5999#include "ui/aura/window.h"
[email protected]c71fe6402012-08-15 15:22:55100#include "ui/base/touch/touch_factory.h"
101#endif // defined (USE_AURA) && defined(USE_X11)
102
[email protected]4cc1ab52013-01-21 19:24:34103#if defined(ENABLE_JAVA_BRIDGE)
104#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
105#endif
106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
[email protected]b172aee2012-04-10 17:05:26109// If a WebContentsImpl is told to navigate to a different web site (as
110// determined by SiteInstance), it will replace its current RenderViewHost with
111// a new RenderViewHost dedicated to the new SiteInstance. This works as
112// follows:
[email protected]420ae012009-04-24 05:16:32113//
114// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46115// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32116// - The pending RVH is "suspended," so that no navigation messages are sent to
117// its renderer until the onbeforeunload JavaScript handler has a chance to
118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
120// that it has a pending cross-site request. ResourceDispatcherHost will
121// check for this when the response arrives.
122// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46123// cancel all the pending logic. Otherwise we allow the pending RVH to send
124// the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
126// main resource load on the pending RVH. It checks CrossSiteRequestManager
127// to see that it is a cross-site request, and installs a
128// CrossSiteResourceHandler.
129// - When RDH receives a response, the BufferedResourceHandler determines
130// whether it is a download. If so, it sends a message to the new renderer
131// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26132// pending RVH remains until the next DidNavigate event for this
133// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32134// - After RDH receives a response and determines that it is safe and not a
135// download, it pauses the response to first run the old page's onunload
136// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26137// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32138// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15139// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32140// the ResourceDispatcherHost, who unpauses the response. Data is then sent
141// to the pending RVH.
142// - The pending renderer sends a FrameNavigate message that invokes the
143// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46144// pending RVH.
[email protected]992db4c2011-05-12 15:37:15145// - The previous renderer is kept swapped out in RenderViewHostManager in case
146// the user goes back. The process only stays live if another tab is using
147// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32148
[email protected]6717bf272012-05-11 23:31:25149using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44150
[email protected]8ff00d72012-10-23 19:12:21151namespace content {
[email protected]420ae012009-04-24 05:16:32152namespace {
153
154// Amount of time we wait between when a key event is received and the renderer
155// is queried for its state and pushed to the NavigationEntry.
156const int kQueryStateDelay = 5000;
157
[email protected]6ebdc9b2010-09-27 16:55:57158const int kSyncWaitDelay = 40;
159
[email protected]82114f52012-03-20 22:53:41160const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05161
[email protected]795c28972012-12-06 06:13:39162static int StartDownload(content::RenderViewHost* rvh,
163 const GURL& url,
164 int image_size) {
165 static int g_next_favicon_download_id = 0;
166 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
167 ++g_next_favicon_download_id,
168 url,
169 image_size));
170 return g_next_favicon_download_id;
171}
172
[email protected]2c5569662011-03-22 20:45:02173ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21174 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50175 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16176 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23181 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
182 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16184 break; // Fall through to rest of function.
185 }
[email protected]5e369672009-11-03 23:48:30186
[email protected]59246c572012-02-10 13:32:13187 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
188 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36189 if (entry.restore_type() ==
190 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13191 if (entry.GetHasPostData())
192 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13194 }
[email protected]5e369672009-11-03 23:48:30195
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30197}
198
[email protected]10f417c52011-12-28 21:04:23199void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47200 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21201 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50202 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16203 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51204 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54205 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55206 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
207 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36208 if (!entry.GetBaseURLForDataURL().is_empty()) {
209 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
210 params->history_url_for_data_url = entry.GetVirtualURL();
211 }
[email protected]36fc0392011-12-25 03:59:51212 params->referrer = entry.GetReferrer();
213 params->transition = entry.GetTransitionType();
214 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00215 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55216 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34217 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47218 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48219 params->transferred_request_child_id =
220 entry.transferred_global_request_id().child_id;
221 params->transferred_request_request_id =
222 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22223 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00224 // Avoid downloading when in view-source mode.
225 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44226 params->is_post = entry.GetHasPostData();
227 if(entry.GetBrowserInitiatedPostData()) {
228 params->browser_initiated_post_data.assign(
229 entry.GetBrowserInitiatedPostData()->front(),
230 entry.GetBrowserInitiatedPostData()->front() +
231 entry.GetBrowserInitiatedPostData()->size());
232
233 }
[email protected]6c6b02d2011-09-02 03:36:47234
[email protected]7c16976c2012-08-04 02:38:23235 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
236 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
237 // We may have been redirected when navigating to the current URL.
238 // Use the URL the user originally intended to visit, if it's valid and if a
239 // POST wasn't involved; the latter case avoids issues with sending data to
240 // the wrong page.
241 params->url = entry.GetOriginalRequestURL();
242 } else {
243 params->url = entry.GetURL();
244 }
245
[email protected]951a64832012-10-11 16:26:37246 params->can_load_local_resources = entry.GetCanLoadLocalResources();
247
[email protected]6c6b02d2011-09-02 03:36:47248 if (delegate)
249 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34250}
251
[email protected]f98f5092012-05-19 00:08:14252int GetSwitchValueAsInt(
253 const CommandLine& command_line,
254 const std::string& switch_string,
255 int min_value) {
256 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
257 int int_value;
258 if (base::StringToInt(string_value, &int_value))
259 return std::max(min_value, int_value);
260 else
261 return min_value;
262}
263
[email protected]420ae012009-04-24 05:16:32264} // namespace
265
[email protected]54944cde2012-12-09 09:24:59266WebContents* WebContents::Create(const WebContents::CreateParams& params) {
267 return WebContentsImpl::CreateWithOpener(params, NULL);
[email protected]d1198fd2012-08-13 22:50:19268}
269
270WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59271 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19272 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59273 WebContentsImpl* new_contents = new WebContentsImpl(
274 params.browser_context, NULL);
[email protected]d1198fd2012-08-13 22:50:19275
276 for (SessionStorageNamespaceMap::const_iterator it =
277 session_storage_namespace_map.begin();
278 it != session_storage_namespace_map.end();
279 ++it) {
280 new_contents->GetController().SetSessionStorageNamespace(it->first,
281 it->second);
282 }
283
[email protected]54944cde2012-12-09 09:24:59284 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19285 return new_contents;
[email protected]a81343d232011-12-27 07:39:20286}
[email protected]746d3052012-05-22 15:15:47287
[email protected]299d7f12012-05-23 05:31:15288WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47289 return rvh->GetDelegate()->GetAsWebContents();
290}
291
[email protected]b172aee2012-04-10 17:05:26292// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32293
[email protected]b172aee2012-04-10 17:05:26294WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21295 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19296 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42297 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19298 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57299 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44300 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05301 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34302 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23303 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
304 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34305 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21306 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56307 upload_size_(0),
308 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47309 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57310 capturing_contents_(false),
311 is_being_destroyed_(false),
312 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55313 dialog_creator_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01314 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56315 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38316 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21317 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
318 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00319 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43320 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20321 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35322}
initial.commit09911bf2008-07-26 23:55:29323
[email protected]b172aee2012-04-10 17:05:26324WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32325 is_being_destroyed_ = true;
326
[email protected]b24b68a2012-09-24 21:57:26327 for (std::set<RenderWidgetHostImpl*>::iterator iter =
328 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
329 (*iter)->DetachDelegate();
330 }
331 created_widgets_.clear();
332
[email protected]3ab9cb82011-06-03 18:02:07333 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55334 if (dialog_creator_)
335 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07336
[email protected]da8543762012-03-20 08:52:20337 if (color_chooser_)
338 color_chooser_->End();
339
[email protected]420ae012009-04-24 05:16:32340 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32341
[email protected]ca13a442012-04-17 14:00:12342 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21343 NotificationService::current()->Notify(
344 NOTIFICATION_WEB_CONTENTS_DESTROYED,
345 Source<WebContents>(this),
346 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32347
348 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07349#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32350 // If we still have a window handle, destroy it. GetNativeView can return
351 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42352 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52353 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58354 if (host && host->GetView())
355 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42356 }
[email protected]420ae012009-04-24 05:16:32357#endif
[email protected]7ab1e7d62009-10-14 23:32:01358
359 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15360 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55361 base::TimeTicks now = base::TimeTicks::Now();
362 base::TimeTicks unload_start_time = close_start_time_;
363 if (!before_unload_end_time_.is_null())
364 unload_start_time = before_unload_end_time_;
365 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
366 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01367 }
[email protected]b5a1d11c2011-02-17 03:09:42368
[email protected]2db9bd72012-04-13 20:20:56369 FOR_EACH_OBSERVER(WebContentsObserver,
370 observers_,
371 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08372
[email protected]6934a702011-12-20 00:04:51373 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42374}
375
[email protected]d1198fd2012-08-13 22:50:19376WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59377 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19378 WebContentsImpl* opener) {
[email protected]54944cde2012-12-09 09:24:59379 WebContentsImpl* new_contents = new WebContentsImpl(
380 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19381
[email protected]54944cde2012-12-09 09:24:59382 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19383 return new_contents;
384}
385
[email protected]dd8c8232012-11-03 00:49:36386WebContentsImpl* WebContentsImpl::CreateGuest(
387 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53388 SiteInstance* site_instance,
[email protected]3de10bb32013-01-08 21:57:33389 int routing_id,
390 WebContentsImpl* opener_web_contents,
[email protected]dd8c8232012-11-03 00:49:36391 int guest_instance_id,
392 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]b5a40842012-11-28 15:26:11393
[email protected]3de10bb32013-01-08 21:57:33394 WebContentsImpl* new_contents = new WebContentsImpl(browser_context,
395 opener_web_contents);
[email protected]7a846df2012-09-20 19:17:39396
397 // This makes |new_contents| act as a guest.
398 // For more info, see comment above class BrowserPluginGuest.
[email protected]b5a40842012-11-28 15:26:11399 new_contents->browser_plugin_guest_.reset(
400 BrowserPluginGuest::Create(
401 guest_instance_id,
402 new_contents,
403 params));
404
[email protected]3de10bb32013-01-08 21:57:33405 WebContents::CreateParams create_params(browser_context, site_instance);
406 create_params.routing_id = routing_id;
407 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11408
[email protected]7a846df2012-09-20 19:17:39409 return new_contents;
410}
411
[email protected]b172aee2012-04-10 17:05:26412WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
413 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54414 WebPreferences prefs;
415
416 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
417
418 prefs.developer_extras_enabled = true;
419 prefs.javascript_enabled =
420 !command_line.HasSwitch(switches::kDisableJavaScript);
421 prefs.web_security_enabled =
422 !command_line.HasSwitch(switches::kDisableWebSecurity);
423 prefs.plugins_enabled =
424 !command_line.HasSwitch(switches::kDisablePlugins);
425 prefs.java_enabled =
426 !command_line.HasSwitch(switches::kDisableJava);
427
428 prefs.uses_page_cache =
429 command_line.HasSwitch(switches::kEnableFastback);
430 prefs.remote_fonts_enabled =
431 !command_line.HasSwitch(switches::kDisableRemoteFonts);
432 prefs.xss_auditor_enabled =
433 !command_line.HasSwitch(switches::kDisableXSSAuditor);
434 prefs.application_cache_enabled =
435 !command_line.HasSwitch(switches::kDisableApplicationCache);
436
437 prefs.local_storage_enabled =
438 !command_line.HasSwitch(switches::kDisableLocalStorage);
439 prefs.databases_enabled =
440 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01441#if defined(OS_ANDROID)
442 prefs.webaudio_enabled =
443 command_line.HasSwitch(switches::kEnableWebAudio);
444#else
[email protected]64d69de42012-02-06 00:19:54445 prefs.webaudio_enabled =
446 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01447#endif
[email protected]64d69de42012-02-06 00:19:54448
449 prefs.experimental_webgl_enabled =
450 GpuProcessHost::gpu_enabled() &&
451 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07452#if defined(OS_ANDROID)
453 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
454#else
[email protected]64d69de42012-02-06 00:19:54455 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07456#endif
[email protected]64d69de42012-02-06 00:19:54457
[email protected]5a073092012-06-08 00:42:51458 prefs.flash_3d_enabled =
459 GpuProcessHost::gpu_enabled() &&
460 !command_line.HasSwitch(switches::kDisableFlash3d);
461 prefs.flash_stage3d_enabled =
462 GpuProcessHost::gpu_enabled() &&
463 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19464
[email protected]64d69de42012-02-06 00:19:54465 prefs.gl_multisampling_enabled =
466 !command_line.HasSwitch(switches::kDisableGLMultisampling);
467 prefs.privileged_webgl_extensions_enabled =
468 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
469 prefs.site_specific_quirks_enabled =
470 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
471 prefs.allow_file_access_from_file_urls =
472 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
473 prefs.show_composited_layer_borders =
474 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
475 prefs.show_composited_layer_tree =
476 command_line.HasSwitch(switches::kShowCompositedLayerTree);
477 prefs.show_fps_counter =
478 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08479 prefs.accelerated_compositing_for_overflow_scroll_enabled =
[email protected]1315fdf2012-12-12 19:45:16480 command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll);
481 prefs.accelerated_compositing_for_scrollable_frames_enabled =
482 command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames);
[email protected]ab3dd632013-01-09 23:19:08483 prefs.composited_scrolling_for_frames_enabled =
484 command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames);
[email protected]8611a852012-05-23 22:11:19485 prefs.show_paint_rects =
486 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52487 prefs.render_vsync_enabled =
488 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54489 prefs.accelerated_compositing_enabled =
490 GpuProcessHost::gpu_enabled() &&
491 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54492 prefs.force_compositing_mode =
[email protected]2a5e9d02013-01-20 01:09:25493 content::IsForceCompositingModeEnabled() &&
[email protected]9b19cf82012-06-13 06:23:23494 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54495 prefs.fixed_position_compositing_enabled =
496 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
497 prefs.accelerated_2d_canvas_enabled =
498 GpuProcessHost::gpu_enabled() &&
499 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58500 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27501 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]a7f899e2013-01-09 12:15:44502 prefs.antialiased_2d_canvas_disabled =
503 command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
[email protected]64d69de42012-02-06 00:19:54504 prefs.accelerated_painting_enabled =
505 GpuProcessHost::gpu_enabled() &&
506 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
507 prefs.accelerated_filters_enabled =
508 GpuProcessHost::gpu_enabled() &&
509 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
[email protected]9bdcfd642012-11-14 21:24:26510 prefs.accelerated_compositing_for_3d_transforms_enabled =
511 prefs.accelerated_compositing_for_animation_enabled =
[email protected]64d69de42012-02-06 00:19:54512 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]9bdcfd642012-11-14 21:24:26513 prefs.accelerated_compositing_for_plugins_enabled =
[email protected]64d69de42012-02-06 00:19:54514 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
[email protected]9bdcfd642012-11-14 21:24:26515 prefs.accelerated_compositing_for_video_enabled =
[email protected]64d69de42012-02-06 00:19:54516 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54517 prefs.fullscreen_enabled =
518 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43519 prefs.css_sticky_position_enabled =
520 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29521 prefs.css_shaders_enabled =
522 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01523 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03524 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]8eb51382012-11-20 00:42:33525 prefs.css_grid_layout_enabled =
526 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]d7932532012-11-21 21:10:31527
528 bool touch_device_present = false;
[email protected]c71fe6402012-08-15 15:22:55529#if defined(USE_AURA) && defined(USE_X11)
[email protected]d7932532012-11-21 21:10:31530 touch_device_present =
[email protected]c71fe6402012-08-15 15:22:55531 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
532#endif
[email protected]25ee94f2012-09-11 19:16:16533#if defined(OS_WIN)
[email protected]d7932532012-11-21 21:10:31534 touch_device_present = ui::IsTouchDevicePresent();
[email protected]25ee94f2012-09-11 19:16:16535#endif
[email protected]d849b122012-07-18 07:35:26536#if defined(OS_ANDROID)
[email protected]d7932532012-11-21 21:10:31537 touch_device_present = true;
538#endif
539 const std::string touch_enabled_switch =
540 command_line.HasSwitch(switches::kTouchEvents) ?
541 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
542 switches::kTouchEventsAuto;
543
544 if (touch_enabled_switch.empty() ||
545 touch_enabled_switch == switches::kTouchEventsEnabled) {
546 prefs.touch_enabled = true;
547 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
548 prefs.touch_enabled = touch_device_present;
549 } else if (touch_enabled_switch != switches::kTouchEventsDisabled) {
550 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
551 }
552
553 prefs.device_supports_touch = prefs.touch_enabled && touch_device_present;
554#if defined(OS_ANDROID)
[email protected]d849b122012-07-18 07:35:26555 prefs.device_supports_mouse = false;
556#endif
[email protected]64d69de42012-02-06 00:19:54557
[email protected]b9c96ff2012-11-26 22:24:40558 prefs.touch_adjustment_enabled =
559 !command_line.HasSwitch(switches::kDisableTouchAdjustment);
560
[email protected]2a5e9d02013-01-20 01:09:25561#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
[email protected]64d69de42012-02-06 00:19:54562 bool default_enable_scroll_animator = true;
563#else
[email protected]64d69de42012-02-06 00:19:54564 bool default_enable_scroll_animator = false;
565#endif
566 prefs.enable_scroll_animator = default_enable_scroll_animator;
567 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
568 prefs.enable_scroll_animator = true;
569 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
570 prefs.enable_scroll_animator = false;
571
572 prefs.visual_word_movement_enabled =
573 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54574
575 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32576 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54577 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39578 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21579 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54580 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21581 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54582 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21583 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19584 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21585 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19586 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21587 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54588 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21589 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54590 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21591 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]9bdcfd642012-11-14 21:24:26592 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
593 prefs.accelerated_compositing_for_animation_enabled = false;
[email protected]c521d7462012-10-03 22:28:20594 }
[email protected]8ff00d72012-10-23 19:12:21595 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]9bdcfd642012-11-14 21:24:26596 prefs.accelerated_compositing_for_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54597
598 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45599 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32600 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]9bdcfd642012-11-14 21:24:26601 prefs.accelerated_compositing_for_video_enabled = false;
602 prefs.accelerated_compositing_for_animation_enabled = false;
603 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
604 prefs.accelerated_compositing_for_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54605 }
606 }
607
[email protected]b9535422012-02-09 01:47:59608 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58609 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54610 prefs.loads_images_automatically = true;
611 prefs.javascript_enabled = true;
612 }
613
614 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
615
[email protected]2ee33532013-01-17 12:27:03616 // Force accelerated compositing and 2d canvas off for chrome: and about:
617 // pages (unless it's specifically allowed).
618 if ((url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]64d69de42012-02-06 00:19:54619 (url.SchemeIs(chrome::kAboutScheme) &&
620 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25621 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54622 prefs.accelerated_compositing_enabled = false;
623 prefs.accelerated_2d_canvas_enabled = false;
624 }
[email protected]43d9d782012-03-01 15:40:09625
[email protected]2ee33532013-01-17 12:27:03626 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
627 prefs.show_fps_counter = false;
628
[email protected]f98f5092012-05-19 00:08:14629 if (command_line.HasSwitch(switches::kDefaultTileWidth))
630 prefs.default_tile_width =
631 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
632 if (command_line.HasSwitch(switches::kDefaultTileHeight))
633 prefs.default_tile_height =
634 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
635 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
636 prefs.max_untiled_layer_width =
637 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
638 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
639 prefs.max_untiled_layer_height =
640 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
641
[email protected]ffabb1e2012-10-12 19:51:17642 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
643 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19644 // Only apply when using DIP coordinate system as this setting interferes
645 // with fixed layout mode.
[email protected]9bdcfd642012-11-14 21:24:26646 // TODO(danakj): Fixed layout mode is going away, so turn this on always.
[email protected]2486dce2012-05-23 17:18:19647 prefs.apply_default_device_scale_factor_in_compositor = true;
648 }
649
[email protected]9bdcfd642012-11-14 21:24:26650 prefs.apply_page_scale_factor_in_compositor =
[email protected]16ad47f82012-12-05 21:06:06651 command_line.HasSwitch(switches::kEnablePinch);
[email protected]f49dece2013-01-12 19:04:28652
653 if (command_line.HasSwitch(switches::kEnableCssTransformPinch)) {
654 prefs.apply_default_device_scale_factor_in_compositor = false;
655 prefs.apply_page_scale_factor_in_compositor = false;
656 }
657
[email protected]9bdcfd642012-11-14 21:24:26658 prefs.per_tile_painting_enabled =
659 command_line.HasSwitch(cc::switches::kEnablePerTilePainting);
[email protected]cf6cb622012-11-16 02:00:19660 prefs.accelerated_animation_enabled =
[email protected]9bdcfd642012-11-14 21:24:26661 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
662
[email protected]de023762012-07-26 17:10:17663 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
664 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10665
[email protected]e755a382012-09-13 17:16:35666 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
667 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12668
[email protected]6b4dcb072012-06-18 22:26:51669 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
670
[email protected]5c90d03d2013-01-10 17:16:02671 prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport);
672
[email protected]76f7d4882012-10-26 21:09:22673 prefs.deferred_image_decoding_enabled =
674 command_line.HasSwitch(switches::kEnableDeferredImageDecoding);
675
[email protected]8ff00d72012-10-23 19:12:21676 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54677
[email protected]97456602012-10-03 18:44:25678 // Disable compositing in guests until we have compositing path implemented
679 // for guests.
[email protected]747c30652012-12-18 20:35:53680 bool guest_compositing_enabled = command_line.HasSwitch(
681 switches::kEnableBrowserPluginCompositing);
682 if (rvh->GetProcess()->IsGuest() && !guest_compositing_enabled) {
[email protected]97456602012-10-03 18:44:25683 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06684 prefs.accelerated_compositing_enabled = false;
685 }
[email protected]97456602012-10-03 18:44:25686
[email protected]64d69de42012-02-06 00:19:54687 return prefs;
688}
689
[email protected]b172aee2012-04-10 17:05:26690RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28691 return &render_manager_;
692}
693
[email protected]7bb761892012-07-20 09:32:47694bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
695 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56696 if (GetWebUI() &&
697 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17698 return true;
[email protected]d2353452012-01-19 19:53:56699 }
[email protected]f82d57b52011-04-27 19:13:17700
[email protected]d8c660432011-12-22 20:51:25701 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
702 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10703 while ((observer = it.GetNext()) != NULL)
704 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53705 return true;
[email protected]403415a2011-01-10 18:57:53706
[email protected]7bb761892012-07-20 09:32:47707 // Message handlers should be aware of which RenderViewHost sent the
708 // message, which is temporarily stored in message_source_.
709 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18710 bool handled = true;
711 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26712 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58713 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
714 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24715 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
716 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18717 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
718 OnDidLoadResourceFromMemoryCache)
719 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
720 OnDidDisplayInsecureContent)
721 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
722 OnDidRunInsecureContent)
723 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
724 OnDocumentLoadedInFrame)
725 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26726 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
727 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17728 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
729 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25730 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26731 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59732 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21733 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20734 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
735 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
736 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16737 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45738 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10739 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20740 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
741 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
742 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
743 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29744 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50745 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50746 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
747 OnRequestPpapiBrokerPermission)
[email protected]b479912c2013-01-23 00:07:08748 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID,
749 OnBrowserPluginAllocateInstanceID)
[email protected]795c28972012-12-06 06:13:39750 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
751 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10752#if defined(OS_ANDROID)
753 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
754 OnFindMatchRectsReply)
755 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
756 OnOpenDateTimeDialog)
757#endif
[email protected]8607c832013-01-18 14:11:57758 IPC_MESSAGE_HANDLER(ViewHostMsg_FrameDetached, OnFrameDetached)
[email protected]724159a2010-12-30 01:11:18759 IPC_MESSAGE_UNHANDLED(handled = false)
760 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47761 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18762
763 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21764 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18765 GetRenderProcessHost()->ReceivedBadMessage();
766 }
767
768 return handled;
769}
770
[email protected]b172aee2012-04-10 17:05:26771void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18772 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21773 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43774 if (delegate_)
775 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18776}
777
[email protected]d1198fd2012-08-13 22:50:19778NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56779 return controller_;
780}
781
[email protected]d1198fd2012-08-13 22:50:19782const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56783 return controller_;
784}
785
[email protected]8ff00d72012-10-23 19:12:21786BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55787 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30788}
789
[email protected]b172aee2012-04-10 17:05:26790const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31791 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23792 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51793 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31794}
795
[email protected]8ff00d72012-10-23 19:12:21796WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31797 return delegate_;
798}
799
[email protected]8ff00d72012-10-23 19:12:21800void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31801 // TODO(cbentzel): remove this debugging code?
802 if (delegate == delegate_)
803 return;
804 if (delegate_)
805 delegate_->Detach(this);
806 delegate_ = delegate;
807 if (delegate_)
808 delegate_->Attach(this);
809}
810
[email protected]8ff00d72012-10-23 19:12:21811RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41812 RenderViewHostImpl* host = render_manager_.current_host();
813 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16814}
815
[email protected]b172aee2012-04-10 17:05:26816RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31817 return render_manager_.current_host();
818}
819
[email protected]a04c9d02012-11-14 21:04:34820void WebContentsImpl::GetRenderViewHostAtPosition(
821 int x,
822 int y,
823 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
824 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
825 if (embedder)
826 embedder->GetRenderViewHostAtPosition(x, y, callback);
827 else
828 callback.Run(GetRenderViewHost(), x, y);
829}
830
[email protected]6b618e62012-08-16 12:59:18831int WebContentsImpl::GetRoutingID() const {
832 if (!GetRenderViewHost())
833 return MSG_ROUTING_NONE;
834
835 return GetRenderViewHost()->GetRoutingID();
836}
837
[email protected]b172aee2012-04-10 17:05:26838RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return render_manager_.GetRenderWidgetHostView();
840}
841
[email protected]8ff00d72012-10-23 19:12:21842WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return view_.get();
844}
845
[email protected]8ff00d72012-10-23 19:12:21846WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]3c788372013-01-10 08:34:28847 WebUIControllerFactory* factory =
848 GetContentClient()->browser()->GetWebUIControllerFactory();
849 if (!factory)
850 return NULL;
[email protected]d2353452012-01-19 19:53:56851 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]3c788372013-01-10 08:34:28852 WebUIController* controller =
853 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22854 if (controller) {
855 web_ui->SetController(controller);
856 return web_ui;
857 }
858
859 delete web_ui;
860 return NULL;
861}
862
[email protected]8ff00d72012-10-23 19:12:21863WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31864 return render_manager_.web_ui() ? render_manager_.web_ui()
865 : render_manager_.pending_web_ui();
866}
867
[email protected]8ff00d72012-10-23 19:12:21868WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31869 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34870}
871
[email protected]86ef6a392012-05-11 22:03:11872void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22873 if (GetUserAgentOverride() == override)
874 return;
875
876 renderer_preferences_.user_agent_override = override;
877
878 // Send the new override string to the renderer.
879 RenderViewHost* host = GetRenderViewHost();
880 if (host)
881 host->SyncRendererPrefs();
882
883 // Reload the page if a load is currently in progress to avoid having
884 // different parts of the page loaded using different user agents.
885 NavigationEntry* entry = controller_.GetActiveEntry();
886 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
887 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53888
889 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
890 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11891}
892
893const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22894 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11895}
896
[email protected]b172aee2012-04-10 17:05:26897const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55898 // Transient entries take precedence. They are used for interstitial pages
899 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23900 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08901 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21902 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30903 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23904 if (entry) {
[email protected]b5cca982011-05-26 04:42:08905 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23906 }
[email protected]7ade2732011-02-10 00:13:58907 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
908 render_manager_.pending_web_ui() : render_manager_.web_ui();
909 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54910 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55911 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54912 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35913 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22914 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54915 if (!title.empty())
916 return title;
917 }
918 }
919
920 // We use the title for the last committed entry rather than a pending
921 // navigation entry. For example, when the user types in a URL, we want to
922 // keep the old page's title until the new load has committed and we get a new
923 // title.
[email protected]96d185d2009-04-24 03:28:54924 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23925 if (entry) {
[email protected]b5cca982011-05-26 04:42:08926 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23927 }
[email protected]987fc3a2011-05-26 14:18:09928
929 // |page_title_when_no_navigation_entry_| is finally used
930 // if no title cannot be retrieved.
931 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54932}
933
[email protected]b172aee2012-04-10 17:05:26934int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46935 return GetMaxPageIDForSiteInstance(GetSiteInstance());
936}
937
[email protected]b172aee2012-04-10 17:05:26938int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
939 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33940 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
941 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46942
[email protected]b6583592012-01-25 19:52:33943 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34944}
945
[email protected]b172aee2012-04-10 17:05:26946void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46947 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
948}
949
[email protected]b172aee2012-04-10 17:05:26950void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33951 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46952 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33953 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34954}
955
[email protected]b172aee2012-04-10 17:05:26956void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
957 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57958}
959
[email protected]b172aee2012-04-10 17:05:26960SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58961 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54962}
963
[email protected]b172aee2012-04-10 17:05:26964SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38965 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
966 render_manager_.pending_render_view_host() :
967 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58968 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38969}
970
[email protected]b172aee2012-04-10 17:05:26971bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31972 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49973}
974
[email protected]b172aee2012-04-10 17:05:26975bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31976 return waiting_for_response_;
977}
978
[email protected]b172aee2012-04-10 17:05:26979const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31980 return load_state_;
981}
982
[email protected]b172aee2012-04-10 17:05:26983const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31984 return load_state_host_;
985}
986
[email protected]b172aee2012-04-10 17:05:26987uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31988 return upload_size_;
989}
990
[email protected]b172aee2012-04-10 17:05:26991uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31992 return upload_position_;
993}
994
[email protected]b172aee2012-04-10 17:05:26995const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31996 return encoding_;
997}
998
[email protected]b172aee2012-04-10 17:05:26999bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311000 return displayed_insecure_content_;
1001}
1002
[email protected]b172aee2012-04-10 17:05:261003void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:311004 capturing_contents_ = cap;
1005}
1006
[email protected]b172aee2012-04-10 17:05:261007bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311008 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1009 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1010 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1014 int error_code) {
[email protected]443b80e2010-12-14 00:42:231015 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341016 return;
1017
[email protected]443b80e2010-12-14 00:42:231018 crashed_status_ = status;
1019 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211020 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341021}
1022
[email protected]b172aee2012-04-10 17:05:261023base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311024 return crashed_status_;
1025}
1026
[email protected]b172aee2012-04-10 17:05:261027bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311028 return is_being_destroyed_;
1029}
1030
[email protected]b172aee2012-04-10 17:05:261031void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341032 if (delegate_)
1033 delegate_->NavigationStateChanged(this, changed_flags);
1034}
1035
[email protected]3e324142012-06-25 18:26:331036base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1037 return last_selected_time_;
1038}
1039
[email protected]9e2e4632012-07-27 16:38:411040void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541041 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041042 RenderWidgetHostViewPort* rwhv =
1043 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161044 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411045 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431046#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161047 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431048#endif
1049 }
[email protected]96d185d2009-04-24 03:28:541050
[email protected]5ac20162010-11-24 23:33:111051 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381052
[email protected]9e2e4632012-07-27 16:38:411053 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591054
1055 // The resize rect might have changed while this was inactive -- send the new
1056 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581057 RenderViewHostImpl* rvh =
1058 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591059 if (rvh) {
1060 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1061 }
[email protected]96d185d2009-04-24 03:28:541062
[email protected]3e324142012-06-25 18:26:331063 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211064 NotificationService::current()->Notify(
1065 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1066 Source<WebContents>(this),
1067 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311068}
1069
[email protected]b172aee2012-04-10 17:05:261070void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311071 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521072 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1073 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261074 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521075 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331076 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521077 // calls us).
[email protected]c30585c2012-02-16 15:02:041078 RenderWidgetHostViewPort* rwhv =
1079 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161080 if (rwhv)
1081 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541082 }
1083
[email protected]375fa1b2012-05-22 22:05:371084 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211085 NotificationService::current()->Notify(
1086 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1087 Source<WebContents>(this),
1088 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371089}
1090
[email protected]b172aee2012-04-10 17:05:261091bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311092 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271093 return WillNotifyDisconnection() &&
1094 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581095 !static_cast<RenderViewHostImpl*>(
1096 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311097}
1098
[email protected]b172aee2012-04-10 17:05:261099void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271100 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251101 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271102}
1103
[email protected]b172aee2012-04-10 17:05:261104WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441105 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451106 // We pass our own opener so that the cloned page can access it if it was
1107 // before.
[email protected]54944cde2012-12-09 09:24:591108 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451109 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591110 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191111 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221112 FOR_EACH_OBSERVER(WebContentsObserver,
1113 observers_,
1114 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271115 return tc;
1116}
1117
[email protected]b172aee2012-04-10 17:05:261118gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271119 return view_->GetContentNativeView();
1120}
1121
[email protected]b172aee2012-04-10 17:05:261122gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271123 return view_->GetNativeView();
1124}
1125
[email protected]b172aee2012-04-10 17:05:261126void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271127 view_->GetContainerBounds(out);
1128}
1129
[email protected]b172aee2012-04-10 17:05:261130void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271131 view_->Focus();
1132}
1133
[email protected]14392a52012-05-02 20:28:441134void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211135 const NotificationSource& source,
1136 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441137 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211138 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1139 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441140 break;
[email protected]8ff00d72012-10-23 19:12:211141 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1142 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501143 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1144 i != pending_widget_views_.end(); ++i) {
1145 if (host->GetView() == i->second) {
1146 pending_widget_views_.erase(i);
1147 break;
1148 }
1149 }
1150 break;
1151 }
[email protected]14392a52012-05-02 20:28:441152 default:
1153 NOTREACHED();
1154 }
1155}
1156
[email protected]54944cde2012-12-09 09:24:591157void WebContentsImpl::Init(const WebContents::CreateParams& params) {
1158 render_manager_.Init(
1159 params.browser_context, params.site_instance, params.routing_id);
[email protected]d1198fd2012-08-13 22:50:191160
[email protected]8ff00d72012-10-23 19:12:211161 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191162 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1163 if (view_.get()) {
1164 CHECK(render_view_host_delegate_view_);
1165 } else {
[email protected]b5a40842012-11-28 15:26:111166 if (browser_plugin_guest_.get() &&
1167 CommandLine::ForCurrentProcess()->HasSwitch(
1168 switches::kEnableBrowserPluginCompositing)) {
1169 WebContentsViewGuest* rv = new WebContentsViewGuest(
1170 this,
1171 browser_plugin_guest_.get());
1172 render_view_host_delegate_view_ = rv;
1173 view_.reset(rv);
1174 } else {
1175 WebContentsViewDelegate* delegate =
1176 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1177 view_.reset(CreateWebContentsView(
1178 this, delegate, &render_view_host_delegate_view_));
1179 }
[email protected]d1198fd2012-08-13 22:50:191180 CHECK(render_view_host_delegate_view_);
1181 }
1182 CHECK(view_.get());
1183
[email protected]ed245db2012-12-18 08:00:451184 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591185 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191186
1187 // Listen for whether our opener gets destroyed.
1188 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211189 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1190 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191191 }
1192
1193 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211194 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1195 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191196#if defined(ENABLE_JAVA_BRIDGE)
1197 java_bridge_dispatcher_host_manager_.reset(
1198 new JavaBridgeDispatcherHostManager(this));
1199#endif
[email protected]583418cc2013-01-17 14:01:101200
1201#if defined(OS_ANDROID)
1202 date_time_chooser_.reset(new DateTimeChooserAndroid());
1203#endif
[email protected]d1198fd2012-08-13 22:50:191204}
1205
[email protected]14392a52012-05-02 20:28:441206void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1207 // Clear the opener if it has been closed.
1208 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211209 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1210 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441211 opener_ = NULL;
1212 }
1213}
1214
[email protected]b172aee2012-04-10 17:05:261215void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311216 observers_.AddObserver(observer);
1217}
1218
[email protected]b172aee2012-04-10 17:05:261219void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311220 observers_.RemoveObserver(observer);
1221}
1222
[email protected]b172aee2012-04-10 17:05:261223void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341224 if (delegate_)
1225 delegate_->ActivateContents(this);
1226}
1227
[email protected]b172aee2012-04-10 17:05:261228void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121229 if (delegate_)
1230 delegate_->DeactivateContents(this);
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481234 if (delegate_)
1235 delegate_->LostCapture();
1236}
1237
[email protected]b24b68a2012-09-24 21:57:261238void WebContentsImpl::RenderWidgetDeleted(
1239 RenderWidgetHostImpl* render_widget_host) {
1240 if (is_being_destroyed_) {
1241 // |created_widgets_| might have been destroyed.
1242 return;
1243 }
1244
1245 std::set<RenderWidgetHostImpl*>::iterator iter =
1246 created_widgets_.find(render_widget_host);
1247 if (iter != created_widgets_.end())
1248 created_widgets_.erase(iter);
1249}
1250
[email protected]b172aee2012-04-10 17:05:261251bool WebContentsImpl::PreHandleKeyboardEvent(
1252 const NativeWebKeyboardEvent& event,
1253 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481254 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131255 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481256}
1257
[email protected]b172aee2012-04-10 17:05:261258void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481259 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131260 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481261}
1262
[email protected]b172aee2012-04-10 17:05:261263void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431264 if (delegate_)
1265 delegate_->HandleMouseDown();
1266}
1267
[email protected]b172aee2012-04-10 17:05:261268void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481269 if (delegate_)
1270 delegate_->HandleMouseUp();
1271}
1272
[email protected]590a634e2012-07-19 16:38:231273void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481274 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231275 delegate_->HandlePointerActivate();
1276}
1277
1278void WebContentsImpl::HandleGestureBegin() {
1279 if (delegate_)
1280 delegate_->HandleGestureBegin();
1281}
1282
1283void WebContentsImpl::HandleGestureEnd() {
1284 if (delegate_)
1285 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481286}
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471289 if (delegate_)
1290 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1291}
1292
[email protected]b172aee2012-04-10 17:05:261293bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381294 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121295}
1296
[email protected]a9c81f02012-06-01 00:15:441297void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1298 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371299 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441300 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371301 } else {
1302 GotResponseToLockMouseRequest(false);
1303 }
1304}
1305
[email protected]b172aee2012-04-10 17:05:261306void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371307 if (delegate_)
1308 delegate_->LostMouseLock();
1309}
1310
[email protected]bafe6cd2012-05-23 23:09:501311void WebContentsImpl::CreateNewWindow(
1312 int route_id,
[email protected]97714c82012-06-06 10:15:131313 const ViewHostMsg_CreateWindow_Params& params,
1314 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501315 if (delegate_ && !delegate_->ShouldCreateWebContents(
1316 this, route_id, params.window_container_type, params.frame_name,
1317 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091318 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501319 return;
1320 }
1321
1322 // We usually create the new window in the same BrowsingInstance (group of
1323 // script-related windows), by passing in the current SiteInstance. However,
1324 // if the opener is being suppressed, we create a new SiteInstance in its own
1325 // BrowsingInstance.
1326 scoped_refptr<SiteInstance> site_instance =
1327 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571328 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501329 GetSiteInstance();
1330
1331 // Create the new web contents. This will automatically create the new
1332 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191333 WebContentsImpl* new_contents =
1334 new WebContentsImpl(GetBrowserContext(),
1335 params.opener_suppressed ? NULL : this);
1336
1337 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341338 //
1339 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191340 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211341 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571342 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591343 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211344 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341345 BrowserContext::GetStoragePartition(GetBrowserContext(),
1346 site_instance);
[email protected]d1198fd2012-08-13 22:50:191347 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341348 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191349 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1350 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1351 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1352 new_contents->GetController().SetSessionStorageNamespace(
1353 partition_id,
1354 session_storage_namespace);
[email protected]54944cde2012-12-09 09:24:591355 CreateParams create_params(GetBrowserContext(), site_instance);
1356 create_params.routing_id = route_id;
[email protected]ed245db2012-12-18 08:00:451357 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591358 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191359
[email protected]bafe6cd2012-05-23 23:09:501360 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1361
1362 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211363 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501364
1365 // TODO(brettw): It seems bogus that we have to call this function on the
1366 // newly created object and give it one of its own member variables.
1367 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1368
1369 // Save the created window associated with the route so we can show it
1370 // later.
1371 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1372 pending_contents_[route_id] = new_contents;
1373 }
1374
1375 if (delegate_) {
1376 delegate_->WebContentsCreated(
1377 this, params.opener_frame_id, params.target_url, new_contents);
1378 }
1379
1380 if (params.opener_suppressed) {
1381 // When the opener is suppressed, the original renderer cannot access the
1382 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001383 bool was_blocked = false;
1384 if (delegate_) {
1385 gfx::Rect initial_pos;
1386 delegate_->AddNewContents(
1387 this, new_contents, params.disposition, initial_pos,
1388 params.user_gesture, &was_blocked);
1389 }
1390 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211391 OpenURLParams open_params(params.target_url,
1392 Referrer(),
1393 CURRENT_TAB,
1394 PAGE_TRANSITION_LINK,
1395 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001396 new_contents->OpenURL(open_params);
1397 }
[email protected]bafe6cd2012-05-23 23:09:501398 }
1399}
1400
1401void WebContentsImpl::CreateNewWidget(int route_id,
1402 WebKit::WebPopupType popup_type) {
1403 CreateNewWidget(route_id, false, popup_type);
1404}
1405
1406void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1407 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1408}
1409
1410void WebContentsImpl::CreateNewWidget(int route_id,
1411 bool is_fullscreen,
1412 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211413 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501414 RenderWidgetHostImpl* widget_host =
1415 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261416 created_widgets_.insert(widget_host);
1417
[email protected]83918ec2013-01-10 15:37:191418 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1419 view_->CreateViewForPopupWidget(widget_host));
1420 if (!widget_view)
1421 return;
[email protected]bafe6cd2012-05-23 23:09:501422 if (!is_fullscreen) {
1423 // Popups should not get activated.
1424 widget_view->SetPopupType(popup_type);
1425 }
1426 // Save the created widget associated with the route so we can show it later.
1427 pending_widget_views_[route_id] = widget_view;
1428
1429#if defined(OS_MACOSX)
1430 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1431 // to allow it to survive the trip without being hosted.
1432 base::mac::NSObjectRetain(widget_view->GetNativeView());
1433#endif
1434}
1435
1436void WebContentsImpl::ShowCreatedWindow(int route_id,
1437 WindowOpenDisposition disposition,
1438 const gfx::Rect& initial_pos,
1439 bool user_gesture) {
1440 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001441 if (contents) {
1442 WebContentsDelegate* delegate = GetDelegate();
1443 if (delegate) {
1444 delegate->AddNewContents(
1445 this, contents, disposition, initial_pos, user_gesture, NULL);
1446 }
1447 }
[email protected]bafe6cd2012-05-23 23:09:501448}
1449
1450void WebContentsImpl::ShowCreatedWidget(int route_id,
1451 const gfx::Rect& initial_pos) {
1452 ShowCreatedWidget(route_id, false, initial_pos);
1453}
1454
1455void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1456 ShowCreatedWidget(route_id, true, gfx::Rect());
1457}
1458
1459void WebContentsImpl::ShowCreatedWidget(int route_id,
1460 bool is_fullscreen,
1461 const gfx::Rect& initial_pos) {
1462 if (delegate_)
1463 delegate_->RenderWidgetShowing();
1464
1465 RenderWidgetHostViewPort* widget_host_view =
1466 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1467 if (!widget_host_view)
1468 return;
1469 if (is_fullscreen) {
1470 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1471 } else {
1472 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1473 }
[email protected]89054502012-06-03 10:29:241474
1475 RenderWidgetHostImpl* render_widget_host_impl =
1476 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1477 render_widget_host_impl->Init();
1478 // Only allow privileged mouse lock for fullscreen render widget, which is
1479 // used to implement Pepper Flash fullscreen.
1480 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501481
1482#if defined(OS_MACOSX)
1483 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1484 // properly embedded (or purposefully ignored) we can release the retain we
1485 // took in CreateNewWidget().
1486 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1487#endif
1488}
1489
1490WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1491 PendingContents::iterator iter = pending_contents_.find(route_id);
1492
1493 // Certain systems can block the creation of new windows. If we didn't succeed
1494 // in creating one, just return NULL.
1495 if (iter == pending_contents_.end()) {
1496 return NULL;
1497 }
1498
1499 WebContentsImpl* new_contents = iter->second;
1500 pending_contents_.erase(route_id);
1501
1502 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1503 !new_contents->GetRenderViewHost()->GetView())
1504 return NULL;
1505
1506 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1507 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1508 return new_contents;
1509}
1510
1511RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1512 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1513 if (iter == pending_widget_views_.end()) {
1514 DCHECK(false);
1515 return NULL;
1516 }
1517
1518 RenderWidgetHostView* widget_host_view = iter->second;
1519 pending_widget_views_.erase(route_id);
1520
1521 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1522 if (!widget_host->GetProcess()->HasConnection()) {
1523 // The view has gone away or the renderer crashed. Nothing to do.
1524 return NULL;
1525 }
1526
1527 return widget_host_view;
1528}
1529
1530void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211531 const ContextMenuParams& params,
1532 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501533 // Allow WebContentsDelegates to handle the context menu operation first.
1534 if (delegate_ && delegate_->HandleContextMenu(params))
1535 return;
1536
[email protected]ba16e3a2012-09-07 04:14:521537 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501538}
1539
[email protected]f13b4202012-06-12 23:53:231540void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091541 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211542 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231543 if (delegate_)
1544 delegate_->RequestMediaAccessPermission(this, request, callback);
1545 else
[email protected]8ff00d72012-10-23 19:12:211546 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231547}
1548
[email protected]b172aee2012-04-10 17:05:261549void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231550 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331551 if (delegate_)
1552 delegate_->UpdatePreferredSize(this, pref_size);
1553}
1554
[email protected]b172aee2012-04-10 17:05:261555void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341556 if (delegate_)
1557 delegate_->ResizeDueToAutoResize(this, new_size);
1558}
1559
[email protected]b172aee2012-04-10 17:05:261560WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201561 if (!delegate_)
1562 return NULL;
[email protected]00c37fc2011-08-02 00:22:501563
[email protected]e5d549d2011-12-28 01:29:201564 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201565 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341566}
1567
[email protected]6b618e62012-08-16 12:59:181568bool WebContentsImpl::Send(IPC::Message* message) {
1569 if (!GetRenderViewHost()) {
1570 delete message;
1571 return false;
1572 }
1573
1574 return GetRenderViewHost()->Send(message);
1575}
1576
[email protected]b172aee2012-04-10 17:05:261577bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501578 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251579 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231580 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251581 reload_type);
[email protected]876bc832010-09-07 16:29:541582}
[email protected]96d185d2009-04-24 03:28:541583
[email protected]ba45bfd2012-05-22 21:51:441584void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211585 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441586 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1587 RenderViewForInterstitialPageCreated(render_view_host));
1588}
1589
[email protected]b172aee2012-04-10 17:05:261590bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231591 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501592 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401593 // The renderer will reject IPC messages with URLs longer than
1594 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211595 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401596 return false;
1597
[email protected]9f76c1e2012-03-05 15:15:581598 RenderViewHostImpl* dest_render_view_host =
1599 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401600 if (!dest_render_view_host)
1601 return false; // Unable to create the desired render view host.
1602
[email protected]80a8fad2011-01-29 04:02:381603 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071604 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581605 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]3c788372013-01-10 08:34:281606 WebUIControllerFactory* factory =
1607 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271608 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501609 bool is_allowed_in_web_ui_renderer =
[email protected]3c788372013-01-10 08:34:281610 factory &&
1611 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1612 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211613 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231614 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271615 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211616 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231617 CHECK(0);
1618 }
[email protected]54ec6472010-04-09 19:39:581619
[email protected]7bb761892012-07-20 09:32:471620 // Notify observers that we will navigate in this RV.
1621 FOR_EACH_OBSERVER(WebContentsObserver,
1622 observers_,
1623 AboutToNavigateRenderView(dest_render_view_host));
1624
[email protected]96d185d2009-04-24 03:28:541625 // Used for page load time metrics.
1626 current_load_start_ = base::TimeTicks::Now();
1627
1628 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341629 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271630 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471631 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341632 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541633
[email protected]36fc0392011-12-25 03:59:511634 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541635 // HACK!! This code suppresses javascript: URLs from being added to
1636 // session history, which is what we want to do for javascript: URLs that
1637 // do not generate content. What we really need is a message from the
1638 // renderer telling us that a new page was not created. The same message
1639 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511640 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541641 return false;
1642 }
1643
[email protected]3c9e1872010-11-18 16:17:491644 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251645 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041646 observers_,
[email protected]36fc0392011-12-25 03:59:511647 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541648
[email protected]09b29342011-06-24 19:18:481649 if (delegate_)
1650 delegate_->DidNavigateToPendingEntry(this);
1651
[email protected]d5f942ba2008-09-26 19:30:341652 return true;
1653}
1654
[email protected]b172aee2012-04-10 17:05:261655void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331656 const SiteInstance* site_instance,
1657 int history_length,
1658 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411659 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1660 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191661 if (render_manager_.pending_render_view_host()) {
1662 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141663 return;
[email protected]9e1ad4b2011-08-14 16:49:191664 }
[email protected]9f76c1e2012-03-05 15:15:581665 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191666 if (!rvh) {
1667 NOTREACHED();
1668 return;
1669 }
[email protected]9f76c1e2012-03-05 15:15:581670 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191671 NOTREACHED();
1672 return;
1673 }
[email protected]6b618e62012-08-16 12:59:181674 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1675 history_length,
1676 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141677}
1678
[email protected]b172aee2012-04-10 17:05:261679void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271680 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541681 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1682 return;
1683 }
[email protected]9f76c1e2012-03-05 15:15:581684 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541685}
1686
[email protected]b172aee2012-04-10 17:05:261687bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271688 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541689}
1690
[email protected]b172aee2012-04-10 17:05:261691InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271692 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221693}
1694
[email protected]b172aee2012-04-10 17:05:261695bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161696 // WebKit creates Document object when MIME type is application/xhtml+xml,
1697 // so we also support this MIME type.
1698 return contents_mime_type_ == "text/html" ||
1699 contents_mime_type_ == "text/xml" ||
1700 contents_mime_type_ == "application/xhtml+xml" ||
1701 contents_mime_type_ == "text/plain" ||
1702 contents_mime_type_ == "text/css" ||
1703 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1704}
1705
[email protected]b172aee2012-04-10 17:05:261706void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591707 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161708 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551709 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211710 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141711 return;
[email protected]c7dd2f62011-07-18 15:57:591712 }
1713
1714 Stop();
1715
1716 // Create the save package and possibly prompt the user for the name to save
1717 // the page as. The user prompt is an asynchronous operation that runs on
1718 // another thread.
1719 save_package_ = new SavePackage(this);
1720 save_package_->GetSaveInfo();
1721}
1722
1723// Used in automated testing to bypass prompting the user for file names.
1724// Instead, the names and paths are hard coded rather than running them through
1725// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261726bool WebContentsImpl::SavePage(const FilePath& main_file,
1727 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211728 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591729 // Stop the page from navigating.
1730 Stop();
1731
1732 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211733 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591734}
1735
[email protected]b172aee2012-04-10 17:05:261736void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121737 const FilePath& file,
1738 const base::Callback<void(const FilePath&, int64)>& callback) {
1739 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1740}
1741
[email protected]b172aee2012-04-10 17:05:261742bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231743 NavigationEntryImpl* active_entry =
1744 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321745 return (active_entry != NULL &&
1746 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511747 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321748}
1749
[email protected]b172aee2012-04-10 17:05:261750const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271751 return contents_mime_type_;
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271755 return notify_disconnection_;
1756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311759 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181760 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161761}
1762
[email protected]b172aee2012-04-10 17:05:261763void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311764 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181765 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161766}
1767
[email protected]8ff00d72012-10-23 19:12:211768RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271769 return &renderer_preferences_;
1770}
1771
[email protected]b172aee2012-04-10 17:05:261772void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271773 new_tab_start_time_ = time;
1774}
1775
[email protected]b172aee2012-04-10 17:05:261776base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271777 return new_tab_start_time_;
1778}
1779
[email protected]e35ccd52012-05-23 16:22:471780void WebContentsImpl::Close() {
1781 Close(GetRenderViewHost());
1782}
1783
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151785 if (close_start_time_.is_null())
1786 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011787}
1788
[email protected]b172aee2012-04-10 17:05:261789bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191790#if defined(OS_CHROMEOS)
1791 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1792 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511793 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201794 return false;
1795 return true;
[email protected]46624bf2010-06-09 16:04:191796#else
1797 return true;
1798#endif
1799}
1800
[email protected]b172aee2012-04-10 17:05:261801void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521802 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581803 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511804 if (delegate_)
1805 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341806}
1807
[email protected]e35ccd52012-05-23 16:22:471808void WebContentsImpl::UserGestureDone() {
1809 OnUserGesture();
1810}
1811
[email protected]b172aee2012-04-10 17:05:261812void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271813 closed_by_user_gesture_ = value;
1814}
1815
[email protected]b172aee2012-04-10 17:05:261816bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271817 return closed_by_user_gesture_;
1818}
1819
[email protected]b172aee2012-04-10 17:05:261820double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051821 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561822 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251823 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171824 return 0;
[email protected]b75b8292010-10-01 07:28:251825
1826 double zoom_level;
1827 if (temporary_zoom_settings_) {
1828 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581829 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251830 } else {
[email protected]2ae88d12011-10-14 09:11:191831 GURL url;
[email protected]10f417c52011-12-28 21:04:231832 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191833 // Since zoom map is updated using rewritten URL, use rewritten URL
1834 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511835 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191836 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251837 }
[email protected]d0b8d092010-10-25 04:05:171838 return zoom_level;
1839}
[email protected]b75b8292010-10-01 07:28:251840
[email protected]b172aee2012-04-10 17:05:261841int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591842 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171843 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011844 // Calculate the zoom percent from the factor. Round up to the nearest whole
1845 // number.
[email protected]b75b8292010-10-01 07:28:251846 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011847 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251848 *enable_decrement = percent > minimum_zoom_percent_;
1849 *enable_increment = percent < maximum_zoom_percent_;
1850 return percent;
1851}
1852
[email protected]b172aee2012-04-10 17:05:261853void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501854 if (!delegate_)
1855 return;
1856
[email protected]10f417c52011-12-28 21:04:231857 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501858 if (!active_entry)
1859 return;
1860
[email protected]36fc0392011-12-25 03:59:511861 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121862}
1863
[email protected]b172aee2012-04-10 17:05:261864void WebContentsImpl::ViewFrameSource(const GURL& url,
1865 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271866 if (!delegate_)
1867 return;
1868
1869 delegate_->ViewSourceForFrame(this, url, content_state);
1870}
1871
[email protected]b172aee2012-04-10 17:05:261872int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271873 return minimum_zoom_percent_;
1874}
1875
[email protected]b172aee2012-04-10 17:05:261876int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271877 return maximum_zoom_percent_;
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231881 return preferred_size_;
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271885 return content_restrictions_;
1886}
1887
[email protected]b172aee2012-04-10 17:05:261888WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]3c788372013-01-10 08:34:281889 WebUIControllerFactory* factory =
1890 GetContentClient()->browser()->GetWebUIControllerFactory();
1891 if (!factory)
1892 return WebUI::kNoWebUI;
1893 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271894}
1895
[email protected]8ff00d72012-10-23 19:12:211896WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271897 // When there is a pending navigation entry, we want to use the pending WebUI
1898 // that goes along with it to control the basic flags. For example, we want to
1899 // show the pending URL in the URL bar, so we want the display_url flag to
1900 // be from the pending entry.
1901 //
1902 // The confusion comes because there are multiple possibilities for the
1903 // initial load in a tab as a side effect of the way the RenderViewHostManager
1904 // works.
1905 //
1906 // - For the very first tab the load looks "normal". The new tab Web UI is
1907 // the pending one, and we want it to apply here.
1908 //
1909 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1910 // get switched to the one previously associated with the new tab pages.
1911 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1912 // have a committed Web UI in this case.
1913 //
1914 // This condition handles all of these cases:
1915 //
1916 // - First load in first tab: no committed nav entry + pending nav entry +
1917 // pending dom ui:
1918 // -> Use pending Web UI if any.
1919 //
1920 // - First load in second tab: no committed nav entry + pending nav entry +
1921 // no pending Web UI:
1922 // -> Use the committed Web UI if any.
1923 //
1924 // - Second navigation in any tab: committed nav entry + pending nav entry:
1925 // -> Use pending Web UI if any.
1926 //
1927 // - Normal state with no load: committed nav entry + no pending nav entry:
1928 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251929 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271930 (controller_.GetLastCommittedEntry() ||
1931 render_manager_.pending_web_ui()))
1932 return render_manager_.pending_web_ui();
1933 return render_manager_.web_ui();
1934}
1935
[email protected]b172aee2012-04-10 17:05:261936bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271937 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581938 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271939}
1940
[email protected]b172aee2012-04-10 17:05:261941bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441942 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501943}
1944
[email protected]b172aee2012-04-10 17:05:261945void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321946 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181947 Send(new ViewMsg_DidChooseColorResponse(
1948 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201949}
1950
[email protected]b172aee2012-04-10 17:05:261951void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181952 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201953 if (delegate_)
1954 delegate_->DidEndColorChooser();
1955 color_chooser_ = NULL;
1956}
1957
[email protected]795c28972012-12-06 06:13:391958int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
1959 const FaviconDownloadCallback& callback) {
1960 RenderViewHost* host = GetRenderViewHost();
1961 int id = StartDownload(host, url, image_size);
1962 favicon_download_map_[id] = callback;
1963 return id;
1964}
1965
[email protected]b172aee2012-04-10 17:05:261966bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211967 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271968 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221969 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231970 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411971 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271972}
1973
[email protected]b172aee2012-04-10 17:05:261974void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271975 if (delegate_)
1976 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211977}
1978
[email protected]3a3b75a2012-06-01 08:38:361979void WebContentsImpl::OnRegisterIntentService(
1980 const webkit_glue::WebIntentServiceData& data,
1981 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431982 if (delegate_)
1983 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301984}
1985
[email protected]b172aee2012-04-10 17:05:261986void WebContentsImpl::OnWebIntentDispatch(
1987 const webkit_glue::WebIntentData& intent,
1988 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431989 if (!delegate_)
1990 return;
1991
[email protected]0d9989d2011-12-21 20:26:001992 WebIntentsDispatcherImpl* intents_dispatcher =
1993 new WebIntentsDispatcherImpl(this, intent, intent_id);
1994 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301995}
1996
[email protected]54047eb52012-05-08 21:45:571997void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211998 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571999 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132000 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572001 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:572002 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:212003 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]ead9009e2013-01-07 22:06:322004 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182005 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212006 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572007 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082008 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182009
[email protected]d974a0a2013-01-10 01:43:572010 if (is_main_frame)
2011 DidChangeLoadProgress(0);
2012
[email protected]0d60f0192011-04-14 12:40:102013 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252014 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132015 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2016 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322017 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542018
2019 if (is_main_frame) {
2020 // Notify observers about the provisional change in the main frame URL.
2021 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2022 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542023 render_view_host));
2024 }
2025}
2026
2027void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212028 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542029 int32 page_id,
[email protected]400992b2012-06-14 00:03:542030 const GURL& source_url,
2031 const GURL& target_url) {
2032 // TODO(creis): Remove this method and have the pre-rendering code listen to
2033 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2034 // instead. See http://crbug.com/78512.
2035 GURL validated_source_url(source_url);
2036 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212037 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542038 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082039 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2040 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542041 NavigationEntry* entry;
2042 if (page_id == -1) {
2043 entry = controller_.GetPendingEntry();
2044 } else {
2045 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2046 page_id);
2047 }
2048 if (!entry || entry->GetURL() != validated_source_url)
2049 return;
2050
2051 // Notify observers about the provisional change in the main frame URL.
2052 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2053 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542054 render_view_host));
[email protected]724159a2010-12-30 01:11:182055}
2056
[email protected]54047eb52012-05-08 21:45:572057void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212058 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582059 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2060 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2061 << ", error_code: " << params.error_code
2062 << ", error_description: " << params.error_description
2063 << ", is_main_frame: " << params.is_main_frame
2064 << ", showing_repost_interstitial: " <<
2065 params.showing_repost_interstitial
2066 << ", frame_id: " << params.frame_id;
2067 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212068 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572069 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082070 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182071
[email protected]d7b175e2011-10-11 15:31:582072 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182073 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2074 // This means that the interstitial won't be torn down properly, which is
2075 // bad. But if we have an interstitial, go back to another tab type, and
2076 // then load the same interstitial again, we could end up getting the first
2077 // interstitial's "failed" message (as a result of the cancel) when we're on
2078 // the second one.
2079 //
2080 // We can't tell this apart, so we think we're tearing down the current page
2081 // which will cause a crash later one. There is also some code in
2082 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2083 // out because of this problem.
2084 //
2085 // http://code.google.com/p/chromium/issues/detail?id=2855
2086 // Because this will not tear down the interstitial properly, if "back" is
2087 // back to another tab type, the interstitial will still be somewhat alive
2088 // in the previous tab type. If you navigate somewhere that activates the
2089 // tab with the interstitial again, you'll see a flash before the new load
2090 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272091 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182092 LOG(WARNING) << "Discarding message during interstitial.";
2093 return;
2094 }
2095
[email protected]a16690732012-07-13 19:22:172096 // Do not clear the pending entry if one exists, so that the user's typed
2097 // URL is not lost when a navigation fails or is aborted. We'll allow
2098 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182099
[email protected]54047eb52012-05-08 21:45:572100 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182101 }
2102
[email protected]d8c660432011-12-22 20:51:252103 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582104 observers_,
2105 DidFailProvisionalLoad(params.frame_id,
2106 params.is_main_frame,
2107 validated_url,
2108 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462109 params.error_description,
2110 render_view_host));
[email protected]724159a2010-12-30 01:11:182111}
2112
[email protected]b172aee2012-04-10 17:05:262113void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182114 const GURL& url,
[email protected]70435962011-08-02 20:13:282115 const std::string& security_info,
2116 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182117 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282118 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192119 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182120 cache.Increment();
2121
2122 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082123 int cert_id = 0;
2124 net::CertStatus cert_status = 0;
2125 int security_bits = -1;
2126 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212127 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2128 &security_bits, &connection_status);
2129 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002130 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2131 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182132
[email protected]8ff00d72012-10-23 19:12:212133 NotificationService::current()->Notify(
2134 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2135 Source<NavigationController>(&controller_),
2136 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182137}
2138
[email protected]b172aee2012-04-10 17:05:262139void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212140 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182141 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192142 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182143}
2144
[email protected]b172aee2012-04-10 17:05:262145void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022146 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232147 LOG(INFO) << security_origin << " ran insecure content from "
2148 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212149 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412150 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212151 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182152 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412153 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192154 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182158 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252159 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472160 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312164 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062165 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312166 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062167 GURL validated_url(url);
2168 RenderProcessHost* render_process_host = message_source_->GetProcess();
2169 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252170 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472171 DidFinishLoad(frame_id, validated_url, is_main_frame,
2172 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312173}
2174
[email protected]b172aee2012-04-10 17:05:262175void WebContentsImpl::OnDidFailLoadWithError(
2176 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062177 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262178 bool is_main_frame,
2179 int error_code,
2180 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062181 GURL validated_url(url);
2182 RenderProcessHost* render_process_host = message_source_->GetProcess();
2183 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252184 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312185 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472186 error_code, error_description,
2187 message_source_));
[email protected]724159a2010-12-30 01:11:182188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272191 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432192 if (delegate_)
2193 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172194}
2195
[email protected]b172aee2012-04-10 17:05:262196void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262197 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232198 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252199 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262200 if (!entry)
2201 return;
2202 // Note that we don't call NavigationController::GotToOffset() as we don't
2203 // want to create a pending navigation entry (it might end up lingering
2204 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252205 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212206 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512207 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212208 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472209 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572210
2211 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2212 // it in now that we know. This allows us to find the entry when it commits.
2213 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232214 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332215 entry->set_site_instance(
2216 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572217 }
[email protected]216813952011-05-19 22:21:262218 }
2219}
2220
[email protected]b172aee2012-04-10 17:05:262221void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2222 int maximum_percent,
2223 bool remember) {
[email protected]216813952011-05-19 22:21:262224 minimum_zoom_percent_ = minimum_percent;
2225 maximum_zoom_percent_ = maximum_percent;
2226 temporary_zoom_settings_ = !remember;
2227}
2228
[email protected]20b433a2012-05-15 21:23:462229void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212230 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552231 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262232 // Check if the URL to save matches the URL of the main frame. Since this
2233 // message originates from Pepper plugins, it may not be the case if the
2234 // plugin is an embedded element.
2235 GURL main_frame_url = GetURL();
2236 if (!main_frame_url.is_valid())
2237 return;
2238 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462239 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272240}
2241
[email protected]b172aee2012-04-10 17:05:262242void WebContentsImpl::OnEnumerateDirectory(int request_id,
2243 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432244 if (!delegate_)
2245 return;
2246
[email protected]b9535422012-02-09 01:47:592247 ChildProcessSecurityPolicyImpl* policy =
2248 ChildProcessSecurityPolicyImpl::GetInstance();
2249 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2250 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432254 if (delegate_)
2255 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202256}
2257
[email protected]b172aee2012-04-10 17:05:262258void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2259 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362260 const string16& title,
2261 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432262 if (!delegate_)
2263 return;
2264
[email protected]b9535422012-02-09 01:47:592265 ChildProcessSecurityPolicyImpl* policy =
2266 ChildProcessSecurityPolicyImpl::GetInstance();
2267 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2268 return;
[email protected]3a3b75a2012-06-01 08:38:362269 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnFindReply(int request_id,
2273 int number_of_matches,
2274 const gfx::Rect& selection_rect,
2275 int active_match_ordinal,
2276 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432277 if (delegate_) {
2278 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2279 active_match_ordinal, final_update);
2280 }
[email protected]b888919c2011-09-02 00:32:162281}
2282
[email protected]59363fc92012-09-05 03:46:312283#if defined(OS_ANDROID)
2284void WebContentsImpl::OnFindMatchRectsReply(
2285 int version,
2286 const std::vector<gfx::RectF>& rects,
2287 const gfx::RectF& active_rect) {
2288 if (delegate_)
2289 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2290}
[email protected]583418cc2013-01-17 14:01:102291
2292void WebContentsImpl::OnOpenDateTimeDialog(int type, const std::string& value) {
2293 date_time_chooser_->ShowDialog(
2294 GetContentNativeView(), GetRenderViewHost(), type, value);
2295}
2296
[email protected]59363fc92012-09-05 03:46:312297#endif
2298
[email protected]cf4d6e742013-01-10 14:06:422299void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path,
2300 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442301 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422302 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2306 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102307 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252308 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102309 AppCacheAccessed(manifest_url, blocked_by_policy));
2310}
2311
[email protected]b172aee2012-04-10 17:05:262312void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322313 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432314 color_chooser_ = delegate_ ?
2315 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202316}
2317
[email protected]b172aee2012-04-10 17:05:262318void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202319 if (color_chooser_ &&
2320 color_chooser_id == color_chooser_->identifier())
2321 color_chooser_->End();
2322}
2323
[email protected]b172aee2012-04-10 17:05:262324void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322325 SkColor color) {
[email protected]da8543762012-03-20 08:52:202326 if (color_chooser_ &&
2327 color_chooser_id == color_chooser_->identifier())
2328 color_chooser_->SetSelectedColor(color);
2329}
2330
[email protected]9f2a9d72012-04-16 16:02:222331void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2332 const FilePath& path,
2333 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552334 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2335
[email protected]3fc07c52012-04-20 00:27:442336 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2337 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292338}
2339
[email protected]d0759f492012-04-19 22:50:502340// This exists for render views that don't have a WebUI, but do have WebUI
2341// bindings enabled.
2342void WebContentsImpl::OnWebUISend(const GURL& source_url,
2343 const std::string& name,
2344 const base::ListValue& args) {
2345 if (delegate_)
2346 delegate_->WebUISend(this, source_url, name, args);
2347}
2348
[email protected]d8415ad92012-08-23 14:40:502349void WebContentsImpl::OnRequestPpapiBrokerPermission(
2350 int request_id,
2351 const GURL& url,
2352 const FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162353 if (!delegate_) {
2354 OnPpapiBrokerPermissionResult(request_id, false);
2355 return;
[email protected]d8415ad92012-08-23 14:40:502356 }
2357
[email protected]8c8fc292012-11-23 18:57:162358 if (!delegate_->RequestPpapiBrokerPermission(
2359 this, url, plugin_path,
2360 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2361 base::Unretained(this), request_id))) {
2362 NOTIMPLEMENTED();
2363 OnPpapiBrokerPermissionResult(request_id, false);
2364 }
[email protected]d8415ad92012-08-23 14:40:502365}
2366
2367void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2368 bool result) {
2369 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2370 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2371 request_id,
2372 result));
2373}
2374
[email protected]b479912c2013-01-23 00:07:082375void WebContentsImpl::OnBrowserPluginAllocateInstanceID(
2376 const IPC::Message& message, int request_id) {
[email protected]19be7a62012-10-01 23:03:372377 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082378 // specific messages for this WebContents. This means that any message from
2379 // a BrowserPlugin prior to AllocateInstanceID will be ignored.
[email protected]7a846df2012-09-20 19:17:392380 // For more info, see comment above classes BrowserPluginEmbedder and
2381 // BrowserPluginGuest.
[email protected]b479912c2013-01-23 00:07:082382 // The first BrowserPluginHostMsg_AllocateInstanceID message from this
2383 // WebContents' embedder render process is handled here. Once
2384 // BrowserPluginEmbedder is created, all subsequent BrowserPluginHostMsg_*
2385 // messages are handled in BrowserPluginEmbedder. Thus, this code will not be
2386 // executed if a BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392387 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392388 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212389 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]b479912c2013-01-23 00:07:082390 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372391}
2392
[email protected]795c28972012-12-06 06:13:392393void WebContentsImpl::OnDidDownloadFavicon(
2394 int id,
2395 const GURL& image_url,
[email protected]795c28972012-12-06 06:13:392396 int requested_size,
2397 const std::vector<SkBitmap>& bitmaps) {
2398 FaviconDownloadMap::iterator iter = favicon_download_map_.find(id);
2399 if (iter == favicon_download_map_.end()) {
2400 // Currently WebContents notifies us of ANY downloads so that it is
2401 // possible to get here.
2402 return;
2403 }
2404 if (!iter->second.is_null()) {
[email protected]8383aa962013-01-10 05:48:532405 iter->second.Run(id, image_url, requested_size, bitmaps);
[email protected]795c28972012-12-06 06:13:392406 }
2407 favicon_download_map_.erase(id);
2408}
2409
2410void WebContentsImpl::OnUpdateFaviconURL(
2411 int32 page_id,
2412 const std::vector<FaviconURL>& candidates) {
2413 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2414 DidUpdateFaviconURL(page_id, candidates));
2415}
2416
[email protected]8607c832013-01-18 14:11:572417void WebContentsImpl::OnFrameDetached(int64 frame_id) {
2418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2419 FrameDetached(message_source_, frame_id));
2420}
2421
[email protected]818915cd2012-11-20 13:14:112422void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
2423 ThreeDAPIType requester) {
2424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2425 DidBlock3DAPIs(url, requester));
2426}
2427
[email protected]96d185d2009-04-24 03:28:542428// Notifies the RenderWidgetHost instance about the fact that the page is
2429// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262430void WebContentsImpl::SetIsLoading(bool is_loading,
2431 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542432 if (is_loading == is_loading_)
2433 return;
2434
2435 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212436 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542437 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562438 upload_size_ = 0;
2439 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542440 }
2441
2442 render_manager_.SetIsLoading(is_loading);
2443
2444 is_loading_ = is_loading;
2445 waiting_for_response_ = is_loading;
2446
[email protected]6ebdc9b2010-09-27 16:55:572447 if (delegate_)
2448 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212449 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542450
[email protected]8ff00d72012-10-23 19:12:212451 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2452 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542453 if (details)
[email protected]8ff00d72012-10-23 19:12:212454 det = Details<LoadNotificationDetails>(details);
2455 NotificationService::current()->Notify(
2456 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542457}
2458
[email protected]b172aee2012-04-10 17:05:262459void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212460 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322461 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562462 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382463 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442464 // that opened the window, as long as both renderers have the same
2465 // privileges.
[email protected]1fd1a502011-03-30 16:55:562466 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562467 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582468 // web_ui might be NULL if the URL refers to a non-existent extension.
2469 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402470 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522471 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442472 }
2473 }
[email protected]1fd1a502011-03-30 16:55:562474 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442475 }
2476
[email protected]4e697b042011-07-08 06:44:562477 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322478 // Clear the status bubble. This is a workaround for a bug where WebKit
2479 // doesn't let us know that the cursor left an element during a
2480 // transition (this is also why the mouse cursor remains as a hand after
2481 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2482 // clear the bubble when a user navigates to a named anchor in the same
2483 // page.
[email protected]36fc0392011-12-25 03:59:512484 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322485 }
2486
[email protected]a6e82fc2010-02-24 22:28:142487 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472488 // Once the main frame is navigated, we're no longer considered to have
2489 // displayed insecure content.
2490 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172491 }
[email protected]ce5c4502009-05-06 16:46:112492
[email protected]3c9e1872010-11-18 16:17:492493 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252494 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042495 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322496}
2497
[email protected]b172aee2012-04-10 17:05:262498void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322499 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212500 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322501 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062502 // If we navigate off the page, reset JavaScript state. This does nothing
2503 // to prevent a malicious script from spamming messages, since the script
2504 // could just reload the page to stop blocking.
2505 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552506 dialog_creator_->ResetJavaScriptState(this);
2507 dialog_creator_ = NULL;
2508 }
[email protected]420ae012009-04-24 05:16:322509
[email protected]3c9e1872010-11-18 16:17:492510 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042512 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322513}
2514
[email protected]b172aee2012-04-10 17:05:262515void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462516 // If we are creating a RVH for a restored controller, then we need to make
2517 // sure the RenderView starts with a next_page_id_ larger than the number
2518 // of restored entries. This must be called before the RenderView starts
2519 // navigating (to avoid a race between the browser updating max_page_id and
2520 // the renderer updating next_page_id_). Because of this, we only call this
2521 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562522 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582523 if (max_restored_page_id >
2524 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2525 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2526 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322527}
2528
[email protected]b172aee2012-04-10 17:05:262529bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2530 const string16& title) {
[email protected]420ae012009-04-24 05:16:322531 // For file URLs without a title, use the pathname instead. In the case of a
2532 // synthesized title, we don't want the update to count toward the "one set
2533 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512534 string16 final_title;
[email protected]420ae012009-04-24 05:16:322535 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512536 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2537 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322538 explicit_set = false; // Don't count synthetic titles toward the set limit.
2539 } else {
[email protected]acafd272011-07-26 17:35:572540 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322541 explicit_set = true;
2542 }
2543
[email protected]987fc3a2011-05-26 14:18:092544 // If a page is created via window.open and never navigated,
2545 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552546 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092547 if (entry) {
[email protected]36fc0392011-12-25 03:59:512548 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092549 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322550
[email protected]36fc0392011-12-25 03:59:512551 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092552 } else {
2553 if (page_title_when_no_navigation_entry_ == final_title)
2554 return false; // Nothing changed, don't bother.
2555
2556 page_title_when_no_navigation_entry_ = final_title;
2557 }
[email protected]420ae012009-04-24 05:16:322558
[email protected]420ae012009-04-24 05:16:322559 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232560 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322561
[email protected]8ff00d72012-10-23 19:12:212562 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462563 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142564
[email protected]8ff00d72012-10-23 19:12:212565 NotificationService::current()->Notify(
2566 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2567 Source<WebContents>(this),
2568 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042569
[email protected]420ae012009-04-24 05:16:322570 return true;
2571}
2572
[email protected]35e0e0792012-11-30 02:35:482573void WebContentsImpl::NotifySwapped(RenderViewHost* old_render_view_host) {
[email protected]420ae012009-04-24 05:16:322574 // After sending out a swap notification, we need to send a disconnect
2575 // notification so that clients that pick up a pointer to |this| can NULL the
2576 // pointer. See Bug 1230284.
2577 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212578 NotificationService::current()->Notify(
2579 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2580 Source<WebContents>(this),
[email protected]35e0e0792012-11-30 02:35:482581 Details<RenderViewHost>(old_render_view_host));
[email protected]7a846df2012-09-20 19:17:392582
2583 // Ensure that the associated embedder gets cleared after a RenderViewHost
2584 // gets swapped, so we don't reuse the same embedder next time a
2585 // RenderViewHost is attached to this WebContents.
2586 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322587}
2588
[email protected]b172aee2012-04-10 17:05:262589void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322590 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212591 NotificationService::current()->Notify(
2592 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2593 Source<WebContents>(this),
2594 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322595}
2596
[email protected]b172aee2012-04-10 17:05:262597void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322598 if (!notify_disconnection_)
2599 return;
2600
2601 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212602 NotificationService::current()->Notify(
2603 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2604 Source<WebContents>(this),
2605 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322606}
2607
[email protected]5a3bdf52012-05-24 15:12:572608RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2609 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322610}
2611
[email protected]8d3347f2009-07-09 22:00:212612RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262613WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212614 return &render_manager_;
2615}
2616
[email protected]8ff00d72012-10-23 19:12:212617RendererPreferences WebContentsImpl::GetRendererPrefs(
2618 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462619 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512620}
2621
[email protected]b172aee2012-04-10 17:05:262622WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172623 return this;
2624}
2625
[email protected]b172aee2012-04-10 17:05:262626gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172627 if (delegate_)
2628 return delegate_->GetRootWindowResizerRect();
2629 return gfx::Rect();
2630}
2631
[email protected]7a846df2012-09-20 19:17:392632void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2633 if (browser_plugin_embedder_.get())
2634 browser_plugin_embedder_.reset();
2635}
2636
[email protected]b172aee2012-04-10 17:05:262637void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442638 // Don't send notifications if we are just creating a swapped-out RVH for
2639 // the opener chain. These won't be used for view-source or WebUI, so it's
2640 // ok to return early.
2641 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2642 return;
2643
[email protected]8ff00d72012-10-23 19:12:212644 NotificationService::current()->Notify(
2645 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2646 Source<WebContents>(this),
2647 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232648 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322649 if (!entry)
2650 return;
2651
2652 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352653 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562654 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582655 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322656
2657 if (entry->IsViewSourceMode()) {
2658 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182659 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582660 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322661 }
[email protected]0666aef2009-05-13 19:48:082662
[email protected]d487beefe2011-12-21 05:41:212663 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262664
2665 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252666 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322667}
2668
[email protected]b172aee2012-04-10 17:05:262669void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522670 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322671 // Don't notify the world, since this came from a renderer in the
2672 // background.
2673 return;
2674 }
2675
2676 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312677 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232678 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302679
2680 // Restore the focus to the tab (otherwise the focus will be on the top
2681 // window).
[email protected]484ae5912010-09-29 19:16:142682 if (was_crashed && !FocusLocationBarByDefault() &&
2683 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302684 Focus();
[email protected]484ae5912010-09-29 19:16:142685 }
[email protected]32ded2212011-11-10 18:51:432686
[email protected]d8c660432011-12-22 20:51:252687 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322688}
2689
[email protected]b172aee2012-04-10 17:05:262690void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2691 base::TerminationStatus status,
2692 int error_code) {
[email protected]151a63d2011-12-20 22:32:522693 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322694 // The pending page's RenderViewHost is gone.
2695 return;
2696 }
2697
2698 SetIsLoading(false, NULL);
2699 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232700 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312701 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322702
[email protected]d8c660432011-12-22 20:51:252703 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272704 observers_,
[email protected]be1f56ab2011-12-22 06:55:312705 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322706}
2707
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482709 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252710 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062711}
2712
[email protected]b172aee2012-04-10 17:05:262713void WebContentsImpl::DidNavigate(
2714 RenderViewHost* rvh,
2715 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e3d92a7f2013-01-10 02:35:052716 if (PageTransitionIsMainFrame(params.transition)) {
2717 // When overscroll navigation gesture is enabled, a screenshot of the page
2718 // in its current state is taken so that it can be used during the
2719 // nav-gesture. It is necessary to take the screenshot here, before calling
2720 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2721 // WebContents::GetRenderViewHost to return the new host, instead of the one
2722 // that may have just been swapped out.
2723 controller_.TakeScreenshot();
2724
[email protected]420ae012009-04-24 05:16:322725 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052726 }
[email protected]8030f012009-09-25 18:09:372727
[email protected]434f69f2012-02-06 21:56:522728 // Update the site of the SiteInstance if it doesn't have one yet, unless
2729 // this is for about:blank. In that case, the SiteInstance can still be
2730 // considered unused until a navigation to a real page.
2731 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2732 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332733 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522734 }
[email protected]420ae012009-04-24 05:16:322735
2736 // Need to update MIME type here because it's referred to in
2737 // UpdateNavigationCommands() called by RendererDidNavigate() to
2738 // determine whether or not to enable the encoding menu.
2739 // It's updated only for the main frame. For a subframe,
2740 // RenderView::UpdateURL does not set params.contents_mime_type.
2741 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2742 // TODO(jungshik): Add a test for the encoding menu to avoid
2743 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212744 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322745 contents_mime_type_ = params.contents_mime_type;
2746
[email protected]8ff00d72012-10-23 19:12:212747 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002748 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392749
[email protected]a9c0bfe2010-09-17 08:35:222750 // Send notification about committed provisional loads. This notification is
2751 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2752 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212753 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072754 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2755 // that is not recorded in the navigation history. For the purpose of
2756 // tracking navigation events, we treat this event as a sub frame navigation
2757 // event.
2758 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212759 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222760 // Whether or not a page transition was triggered by going backward or
2761 // forward in the history is only stored in the navigation controller's
2762 // entry list.
2763 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512764 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212765 PAGE_TRANSITION_FORWARD_BACK)) {
2766 transition_type = PageTransitionFromInt(
2767 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222768 }
[email protected]0d60f0192011-04-14 12:40:102769 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252770 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102771 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462772 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222773 }
2774
[email protected]76543b92009-08-31 17:27:452775 if (!did_navigate)
2776 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322777
2778 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2779 // for the appropriate notification (best) or you can add it to
2780 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2781 // necessary, please).
2782
2783 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002784 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322785 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512786 if (delegate_)
2787 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002788 }
[email protected]420ae012009-04-24 05:16:322789 DidNavigateAnyFramePostCommit(rvh, details, params);
2790}
2791
[email protected]b172aee2012-04-10 17:05:262792void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2793 int32 page_id,
2794 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152795 // Ensure that this state update comes from either the active RVH or one of
2796 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522797 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322798
2799 // We must be prepared to handle state updates for any page, these occur
2800 // when the user is scrolling and entering form data, as well as when we're
2801 // leaving a page, in which case our state may have already been moved to
2802 // the next page. The navigation controller will look up the appropriate
2803 // NavigationEntry and update it when it is notified via the delegate.
2804
2805 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582806 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322807 if (entry_index < 0)
2808 return;
[email protected]10f417c52011-12-28 21:04:232809 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322810
[email protected]36fc0392011-12-25 03:59:512811 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322812 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512813 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322814 controller_.NotifyEntryChanged(entry, entry_index);
2815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2818 int32 page_id,
2819 const string16& title,
2820 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322821 // If we have a title, that's a pretty good indication that we've started
2822 // getting useful data.
2823 SetNotWaitingForResponse();
2824
[email protected]73eb2602012-02-09 19:50:552825 // Try to find the navigation entry, which might not be the current one.
2826 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232827 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582828 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092829
[email protected]73eb2602012-02-09 19:50:552830 // We can handle title updates when we don't have an entry in
2831 // UpdateTitleForEntry, but only if the update is from the current RVH.
2832 if (!entry && rvh != GetRenderViewHost())
2833 return;
2834
[email protected]a49e10b2011-08-01 23:57:462835 // TODO(evan): make use of title_direction.
2836 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092837 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322838 return;
2839
2840 // Broadcast notifications when the UI should be updated.
2841 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212842 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2846 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312847 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322848}
2849
[email protected]b172aee2012-04-10 17:05:262850void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512851 if (delegate_)
2852 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322853}
2854
[email protected]b172aee2012-04-10 17:05:262855void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292856 // The UI may be in an event-tracking loop, such as between the
2857 // mouse-down and mouse-up in text selection or a button click.
2858 // Defer the close until after tracking is complete, so that we
2859 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292860 // TODO(shess): This could get more fine-grained. For instance,
2861 // closing a tab in another window while selecting text in the
2862 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212863 if (GetView()->IsEventTracking()) {
2864 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292865 return;
2866 }
2867
[email protected]420ae012009-04-24 05:16:322868 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522869 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512870 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522874 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512875 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572876}
2877
[email protected]b172aee2012-04-10 17:05:262878void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512879 if (delegate_ && delegate_->IsPopupOrPanel(this))
2880 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322881}
2882
[email protected]8ff00d72012-10-23 19:12:212883void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322884 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492885
[email protected]82114f52012-03-20 22:53:412886 if (delegate_ && content_restrictions_)
2887 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492888
2889 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292890 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2891 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322892}
2893
[email protected]8ff00d72012-10-23 19:12:212894void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322895 scoped_ptr<LoadNotificationDetails> details;
2896
[email protected]10f417c52011-12-28 21:04:232897 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322898 // An entry may not exist for a stop when loading an initial blank page or
2899 // if an iframe injected by script into a blank page finishes loading.
2900 if (entry) {
[email protected]420ae012009-04-24 05:16:322901 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2902
2903 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512904 entry->GetVirtualURL(),
2905 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322906 elapsed,
2907 &controller_,
2908 controller_.GetCurrentEntryIndex()));
2909 }
2910
[email protected]420ae012009-04-24 05:16:322911 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492912
2913 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292914 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2915 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322916}
2917
[email protected]b172aee2012-04-10 17:05:262918void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162919 controller_.DiscardNonCommittedEntries();
2920
2921 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212922 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162923}
2924
[email protected]b172aee2012-04-10 17:05:262925void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262926#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512927 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132928 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262929#endif
[email protected]1a3c3cb2010-12-16 21:03:402930}
2931
[email protected]7cc78902012-12-06 02:32:262932void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2933 // Clear our opener so that future cross-process navigations don't have an
2934 // opener assigned.
2935 opener_ = NULL;
2936
2937 // Notify all swapped out RenderViewHosts for this tab. This is important
2938 // in case we go back to them, or if another window in those processes tries
2939 // to access window.opener.
2940 render_manager_.DidDisownOpener(rvh);
2941}
2942
[email protected]0720b532012-08-28 19:23:372943void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2944 render_manager_.DidUpdateFrameTree(rvh);
2945}
2946
[email protected]87717d0e2012-04-26 02:58:432947void WebContentsImpl::DocumentAvailableInMainFrame(
2948 RenderViewHost* render_view_host) {
2949 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2950 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102951}
2952
[email protected]b172aee2012-04-10 17:05:262953void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082954 RenderViewHost* render_view_host,
2955 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212956 NotificationService::current()->Notify(
2957 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2958 Source<WebContents>(this),
2959 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082960}
2961
[email protected]196159d2012-05-04 17:26:542962void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2963 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212964 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262965 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:182966 int64 source_frame_id,
2967 bool is_cross_site_redirect) {
[email protected]196159d2012-05-04 17:26:542968 // If this came from a swapped out RenderViewHost, we only allow the request
2969 // if we are still in the same BrowsingInstance.
2970 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2971 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2972 return;
2973 }
2974
[email protected]4ad5d77d2011-12-03 02:00:482975 // Delegate to RequestTransferURL because this is just the generic
2976 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582977 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]e2caa032012-11-15 23:29:182978 GlobalRequestID(), is_cross_site_redirect);
[email protected]4ad5d77d2011-12-03 02:00:482979}
2980
[email protected]b172aee2012-04-10 17:05:262981void WebContentsImpl::RequestTransferURL(
2982 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212983 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262984 WindowOpenDisposition disposition,
2985 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:182986 const GlobalRequestID& old_request_id,
2987 bool is_cross_site_redirect) {
[email protected]e5d549d2011-12-28 01:29:202988 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212989 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582990 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352991 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322992 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2993 // generated suggestions).
2994 //
[email protected]e0112912011-02-02 22:54:352995 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162996 // want web sites to see a referrer of "chrome://blah" (and some
2997 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322998 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:212999 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:223000 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:483001 false /* is_renderer_initiated */);
3002 params.transferred_global_request_id = old_request_id;
3003 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:223004 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:323005 } else {
[email protected]6bf6a6b52012-02-03 15:41:433006 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:213007 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:483008 params.transferred_global_request_id = old_request_id;
[email protected]e2caa032012-11-15 23:29:183009 params.is_cross_site_redirect = is_cross_site_redirect;
[email protected]4ad5d77d2011-12-03 02:00:483010 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:583011 }
3012 if (new_contents) {
3013 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253014 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583015 DidOpenRequestedURL(new_contents,
3016 url,
3017 referrer,
3018 disposition,
3019 transition_type,
3020 source_frame_id));
[email protected]420ae012009-04-24 05:16:323021 }
3022}
3023
[email protected]e1c3a552012-05-04 20:51:323024void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3025 // Tell the active RenderViewHost to run unload handlers and close, as long
3026 // as the request came from a RenderViewHost in the same BrowsingInstance.
3027 // In most cases, we receive this from a swapped out RenderViewHost.
3028 // It is possible to receive it from one that has just been swapped in,
3029 // in which case we might as well deliver the message anyway.
3030 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3031 GetRenderViewHost()->ClosePage();
3032}
3033
[email protected]f546640b2012-05-15 00:03:493034void WebContentsImpl::RouteMessageEvent(
3035 RenderViewHost* rvh,
3036 const ViewMsg_PostMessage_Params& params) {
3037 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363038 // came from a RenderViewHost in the same BrowsingInstance or if this
3039 // WebContents is dedicated to a browser plugin guest.
3040 // Note: This check means that an embedder could theoretically receive a
3041 // postMessage from anyone (not just its own guests). However, this is
3042 // probably not a risk for apps since other pages won't have references
3043 // to App windows.
3044 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3045 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493046 return;
3047
3048 ViewMsg_PostMessage_Params new_params(params);
3049
[email protected]0720b532012-08-28 19:23:373050 // If the renderer has changed while the post message is being routed,
3051 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:193052 // TODO(nasko): Check for process ID and target frame id mismatch, once
3053 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:373054
[email protected]f546640b2012-05-15 00:03:493055 // If there is a source_routing_id, translate it to the routing ID for
3056 // the equivalent swapped out RVH in the target process. If we need
3057 // to create a swapped out RVH for the source tab, we create its opener
3058 // chain as well, since those will also be accessible to the target page.
3059 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3060 // Try to look up the WebContents for the source page.
3061 WebContentsImpl* source_contents = NULL;
3062 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3063 rvh->GetProcess()->GetID(), params.source_routing_id);
3064 if (source_rvh) {
3065 source_contents = static_cast<WebContentsImpl*>(
3066 source_rvh->GetDelegate()->GetAsWebContents());
3067 }
3068
3069 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363070 if (GetBrowserPluginGuest()) {
3071 // We create a swapped out RenderView for the embedder in the guest's
3072 // render process but we intentionally do not expose the embedder's
3073 // opener chain to it.
3074 new_params.source_routing_id =
3075 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3076 } else {
3077 new_params.source_routing_id =
3078 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3079 }
[email protected]f546640b2012-05-15 00:03:493080 } else {
3081 // We couldn't find it, so don't pass a source frame.
3082 new_params.source_routing_id = MSG_ROUTING_NONE;
3083 }
3084 }
3085
3086 // In most cases, we receive this from a swapped out RenderViewHost.
3087 // It is possible to receive it from one that has just been swapped in,
3088 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183089 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493090}
3091
[email protected]b172aee2012-04-10 17:05:263092void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343093 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413094 const string16& message,
3095 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323096 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213097 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323098 IPC::Message* reply_msg,
3099 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073100 // Suppress JavaScript dialogs when requested. Also suppress messages when
3101 // showing an interstitial as it's shown over the previous page and we don't
3102 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503103 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583104 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273105 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073106 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523107 delegate_->ShouldSuppressDialogs() ||
3108 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323109
3110 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213111 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433112 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553113 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523114 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433115 this,
3116 frame_url.GetOrigin(),
3117 accept_lang,
3118 javascript_message_type,
3119 message,
[email protected]51da7e32012-01-30 19:24:523120 default_prompt,
[email protected]b172aee2012-04-10 17:05:263121 base::Bind(&WebContentsImpl::OnDialogClosed,
3122 base::Unretained(this),
3123 rvh,
3124 reply_msg),
[email protected]51da7e32012-01-30 19:24:523125 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323126 }
[email protected]3ab9cb82011-06-03 18:02:073127
3128 if (suppress_this_message) {
3129 // If we are suppressing messages, just reply as if the user immediately
3130 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343131 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073132 }
3133
3134 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323135}
3136
[email protected]b172aee2012-04-10 17:05:263137void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3138 const string16& message,
3139 bool is_reload,
3140 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583141 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513142 if (delegate_)
3143 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073144
3145 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583146 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073147 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523148 delegate_->ShouldSuppressDialogs() ||
3149 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153150 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343151 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583152 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503153 return;
3154 }
[email protected]3ab9cb82011-06-03 18:02:073155
[email protected]7ab1e7d62009-10-14 23:32:013156 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553157 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523158 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323159 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263160 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523161 reply_msg));
[email protected]420ae012009-04-24 05:16:323162}
3163
[email protected]a796f202012-05-30 14:14:253164bool WebContentsImpl::AddMessageToConsole(int32 level,
3165 const string16& message,
3166 int32 line_no,
3167 const string16& source_id) {
3168 if (!delegate_)
3169 return false;
3170 return delegate_->AddMessageToConsole(this, level, message, line_no,
3171 source_id);
3172}
3173
[email protected]b172aee2012-04-10 17:05:263174WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333175 // We want to base the page config off of the real URL, rather than the
3176 // display URL.
3177 GURL url = controller_.GetActiveEntry()
3178 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3179 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323180}
3181
[email protected]0eba810b2012-10-18 03:19:363182int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213183 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363184 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3185}
3186
[email protected]b172aee2012-04-10 17:05:263187void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273188 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253189 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223190
[email protected]ea114722012-03-12 01:11:253191 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173192 if (rdh) // NULL in unittests.
3193 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253194}
3195
[email protected]b172aee2012-04-10 17:05:263196void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443197 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253198 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443199}
3200
[email protected]b172aee2012-04-10 17:05:263201void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3202 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153203 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523204 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153205 return;
3206
[email protected]9f76c1e2012-03-05 15:15:583207 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3208
[email protected]e5fc1632011-08-08 07:51:533209 // Ignore renderer unresponsive event if debugger is attached to the tab
3210 // since the event may be a result of the renderer sitting on a breakpoint.
3211 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363212 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533213 return;
3214
[email protected]420ae012009-04-24 05:16:323215 if (is_during_unload) {
3216 // Hang occurred while firing the beforeunload/unload handler.
3217 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583218 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323219
3220 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3221 return;
3222
3223 // If the tab hangs in the beforeunload/unload handler there's really
3224 // nothing we can do to recover. Pretend the unload listeners have
3225 // all fired and close the tab. If the hang is in the beforeunload handler
3226 // then the user will not have the option of cancelling the close.
3227 Close(rvh);
3228 return;
3229 }
3230
[email protected]9f76c1e2012-03-05 15:15:583231 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473232 return;
3233
[email protected]6934a702011-12-20 00:04:513234 if (delegate_)
3235 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323236}
3237
[email protected]b172aee2012-04-10 17:05:263238void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513239 if (delegate_)
3240 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323241}
3242
[email protected]b172aee2012-04-10 17:05:263243void WebContentsImpl::LoadStateChanged(
3244 const GURL& url,
3245 const net::LoadStateWithParam& load_state,
3246 uint64 upload_position,
3247 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323248 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563249 upload_position_ = upload_position;
3250 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503251 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213252 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303253 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213254 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323255 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463256 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213257 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463258 }
[email protected]420ae012009-04-24 05:16:323259}
3260
[email protected]b172aee2012-04-10 17:05:263261void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513262 if (delegate_)
3263 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253264}
3265
[email protected]b172aee2012-04-10 17:05:263266void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553267 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323268 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553269 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513270 if (delegate_)
3271 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323272}
3273
[email protected]b172aee2012-04-10 17:05:263274void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543275 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233276 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3277 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543278}
3279
[email protected]b172aee2012-04-10 17:05:263280void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103281 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263282 gfx::Size size = view_->GetContainerSize();
3283 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3284 // here during container initialization and normal window size will be set
3285 // later. In case of tab duplication this resizing to 0x0 prevents setting
3286 // normal size later so just ignore it.
3287 if (!size.IsEmpty())
3288 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323289}
3290
[email protected]35e0e0792012-11-30 02:35:483291void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) {
3292 NotifySwapped(rvh);
[email protected]3a3d47472010-07-15 21:03:543293}
3294
[email protected]14392a52012-05-02 20:28:443295int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3296 SiteInstance* instance) {
3297 if (!opener_)
3298 return MSG_ROUTING_NONE;
3299
3300 // Recursively create RenderViews for anything else in the opener chain.
3301 return opener_->CreateOpenerRenderViews(instance);
3302}
3303
3304int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3305 int opener_route_id = MSG_ROUTING_NONE;
3306
3307 // If this tab has an opener, ensure it has a RenderView in the given
3308 // SiteInstance as well.
3309 if (opener_)
3310 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3311
[email protected]0720b532012-08-28 19:23:373312 // If any of the renderers for this WebContents has the same SiteInstance,
3313 // use it.
3314 if (render_manager_.current_host()->GetSiteInstance() == instance)
3315 return render_manager_.current_host()->GetRoutingID();
3316
3317 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3318 instance);
3319 if (rvh)
3320 return rvh->GetRoutingID();
3321
[email protected]14392a52012-05-02 20:28:443322 // Create a swapped out RenderView in the given SiteInstance if none exists,
3323 // setting its opener to the given route_id. Return the new view's route_id.
3324 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3325}
3326
[email protected]b172aee2012-04-10 17:05:263327NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193328 return GetController();
[email protected]3a3d47472010-07-15 21:03:543329}
3330
[email protected]b172aee2012-04-10 17:05:263331WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563332 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323333}
3334
[email protected]10f417c52011-12-28 21:04:233335NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263336 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323337 return controller_.GetLastCommittedEntry();
3338}
3339
[email protected]b172aee2012-04-10 17:05:263340bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443341 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443342 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323343 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523344
[email protected]420ae012009-04-24 05:16:323345 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443346 if (rwh_view)
3347 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323348
[email protected]74ce1ad2011-12-16 21:51:463349 // Make sure we use the correct starting page_id in the new RenderView.
3350 UpdateMaxPageIDIfNecessary(render_view_host);
3351 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583352 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463353
[email protected]9f76c1e2012-03-05 15:15:583354 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493355 render_view_host)->CreateRenderView(string16(),
3356 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133357 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523358 return false;
[email protected]14392a52012-05-02 20:28:443359 }
[email protected]a4127722011-04-27 23:13:523360
[email protected]e60c0232011-11-11 19:56:353361#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503362 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3363 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443364 if (rwh_view) {
3365 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3366 render_widget_host->WasResized();
3367 }
[email protected]f8233cc2011-05-31 20:24:503368#endif
3369
[email protected]420ae012009-04-24 05:16:323370 return true;
3371}
3372
[email protected]b172aee2012-04-10 17:05:263373void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3374 IPC::Message* reply_msg,
3375 bool success,
3376 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543377 if (is_showing_before_unload_dialog_ && !success) {
3378 // If a beforeunload dialog is canceled, we need to stop the throbber from
3379 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293380 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353381 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543382
[email protected]3bbacc5b2012-04-17 17:46:153383 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553384 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543385 }
3386 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583387 static_cast<RenderViewHostImpl*>(
3388 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543389}
3390
[email protected]b172aee2012-04-10 17:05:263391void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213392 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123393 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103394}
[email protected]f45d2a72010-03-08 23:28:353395
[email protected]b172aee2012-04-10 17:05:263396void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213397 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263398 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573399 DownloadManager* dlm =
3400 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143401 if (!dlm)
3402 return;
3403 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263404 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143405 const NavigationEntry* entry = controller_.GetActiveEntry();
3406 if (entry)
3407 post_id = entry->GetPostID();
3408 }
[email protected]c5a5c0842012-05-04 20:05:143409 scoped_ptr<DownloadUrlParameters> params(
[email protected]49d812e2012-11-06 21:18:123410 DownloadUrlParameters::FromWebContents(this, url));
[email protected]f859eba2012-05-30 17:22:493411 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143412 params->set_post_id(post_id);
3413 params->set_prefer_cache(true);
3414 if (post_id >= 0)
3415 params->set_method("POST");
[email protected]49d812e2012-11-06 21:18:123416 params->set_prompt(true);
[email protected]c5a5c0842012-05-04 20:05:143417 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143418}
3419
[email protected]b172aee2012-04-10 17:05:263420void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213421 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443422 // Can be NULL during tests.
3423 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213424 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363425}
[email protected]9f76c1e2012-03-05 15:15:583426
[email protected]b172aee2012-04-10 17:05:263427RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583428 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3429}
[email protected]7900bfdb2012-05-24 19:31:243430
[email protected]8ff00d72012-10-23 19:12:213431BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393432 return browser_plugin_guest_.get();
3433}
3434
[email protected]8ff00d72012-10-23 19:12:213435BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393436 return browser_plugin_embedder_.get();
3437}
[email protected]8ff00d72012-10-23 19:12:213438
3439} // namespace content