blob: 098d7d99792716581251d97bf7ba60683c3e82af [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]87f3c082011-10-19 18:07:4450#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3651#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1752#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1453#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4654#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1555#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0056#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2757#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0058#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3759#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1460#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3261#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3462#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3863#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4264#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2565#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1066#include "content/public/browser/web_contents_view.h"
[email protected]3c788372013-01-10 08:34:2867#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2168#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4869#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1870#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5471#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0372#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1673#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2974#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5475#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3476#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3777#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5678#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1679#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0181#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5283#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2484#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3685#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3186#include "webkit/glue/webpreferences.h"
87
[email protected]583418cc2013-01-17 14:01:1088#if defined(OS_ANDROID)
89#include "content/browser/android/date_time_chooser_android.h"
90#endif
91
[email protected]f66df822012-05-18 16:52:1792#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5093#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4194#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5795#endif
[email protected]3e45ba92009-02-20 21:09:0096
[email protected]c71fe6402012-08-15 15:22:5597#if defined(USE_AURA) && defined(USE_X11)
[email protected]54944cde2012-12-09 09:24:5998#include "ui/aura/window.h"
[email protected]c71fe6402012-08-15 15:22:5599#include "ui/base/touch/touch_factory.h"
100#endif // defined (USE_AURA) && defined(USE_X11)
101
[email protected]420ae012009-04-24 05:16:32102// Cross-Site Navigations
103//
[email protected]b172aee2012-04-10 17:05:26104// If a WebContentsImpl is told to navigate to a different web site (as
105// determined by SiteInstance), it will replace its current RenderViewHost with
106// a new RenderViewHost dedicated to the new SiteInstance. This works as
107// follows:
[email protected]420ae012009-04-24 05:16:32108//
109// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46110// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32111// - The pending RVH is "suspended," so that no navigation messages are sent to
112// its renderer until the onbeforeunload JavaScript handler has a chance to
113// run in the current RVH.
114// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
115// that it has a pending cross-site request. ResourceDispatcherHost will
116// check for this when the response arrives.
117// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46118// cancel all the pending logic. Otherwise we allow the pending RVH to send
119// the navigation request to its renderer.
120// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
121// main resource load on the pending RVH. It checks CrossSiteRequestManager
122// to see that it is a cross-site request, and installs a
123// CrossSiteResourceHandler.
124// - When RDH receives a response, the BufferedResourceHandler determines
125// whether it is a download. If so, it sends a message to the new renderer
126// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26127// pending RVH remains until the next DidNavigate event for this
128// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32129// - After RDH receives a response and determines that it is safe and not a
130// download, it pauses the response to first run the old page's onunload
131// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26132// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32133// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15134// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32135// the ResourceDispatcherHost, who unpauses the response. Data is then sent
136// to the pending RVH.
137// - The pending renderer sends a FrameNavigate message that invokes the
138// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46139// pending RVH.
[email protected]992db4c2011-05-12 15:37:15140// - The previous renderer is kept swapped out in RenderViewHostManager in case
141// the user goes back. The process only stays live if another tab is using
142// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32143
[email protected]6717bf272012-05-11 23:31:25144using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44145
[email protected]8ff00d72012-10-23 19:12:21146namespace content {
[email protected]420ae012009-04-24 05:16:32147namespace {
148
149// Amount of time we wait between when a key event is received and the renderer
150// is queried for its state and pushed to the NavigationEntry.
151const int kQueryStateDelay = 5000;
152
[email protected]6ebdc9b2010-09-27 16:55:57153const int kSyncWaitDelay = 40;
154
[email protected]82114f52012-03-20 22:53:41155const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05156
[email protected]795c28972012-12-06 06:13:39157static int StartDownload(content::RenderViewHost* rvh,
158 const GURL& url,
159 int image_size) {
160 static int g_next_favicon_download_id = 0;
161 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
162 ++g_next_favicon_download_id,
163 url,
164 image_size));
165 return g_next_favicon_download_id;
166}
167
[email protected]2c5569662011-03-22 20:45:02168ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21169 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50170 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16171 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47172 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02173 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47174 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02175 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23176 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
177 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16179 break; // Fall through to rest of function.
180 }
[email protected]5e369672009-11-03 23:48:30181
[email protected]59246c572012-02-10 13:32:13182 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
183 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36184 if (entry.restore_type() ==
185 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13186 if (entry.GetHasPostData())
187 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13189 }
[email protected]5e369672009-11-03 23:48:30190
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30192}
193
[email protected]10f417c52011-12-28 21:04:23194void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47195 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21196 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50197 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16198 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51199 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54200 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55201 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
202 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36203 if (!entry.GetBaseURLForDataURL().is_empty()) {
204 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
205 params->history_url_for_data_url = entry.GetVirtualURL();
206 }
[email protected]36fc0392011-12-25 03:59:51207 params->referrer = entry.GetReferrer();
208 params->transition = entry.GetTransitionType();
209 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00210 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55211 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34212 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47213 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48214 params->transferred_request_child_id =
215 entry.transferred_global_request_id().child_id;
216 params->transferred_request_request_id =
217 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22218 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00219 // Avoid downloading when in view-source mode.
220 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44221 params->is_post = entry.GetHasPostData();
222 if(entry.GetBrowserInitiatedPostData()) {
223 params->browser_initiated_post_data.assign(
224 entry.GetBrowserInitiatedPostData()->front(),
225 entry.GetBrowserInitiatedPostData()->front() +
226 entry.GetBrowserInitiatedPostData()->size());
227
228 }
[email protected]6c6b02d2011-09-02 03:36:47229
[email protected]7c16976c2012-08-04 02:38:23230 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
231 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
232 // We may have been redirected when navigating to the current URL.
233 // Use the URL the user originally intended to visit, if it's valid and if a
234 // POST wasn't involved; the latter case avoids issues with sending data to
235 // the wrong page.
236 params->url = entry.GetOriginalRequestURL();
237 } else {
238 params->url = entry.GetURL();
239 }
240
[email protected]951a64832012-10-11 16:26:37241 params->can_load_local_resources = entry.GetCanLoadLocalResources();
242
[email protected]6c6b02d2011-09-02 03:36:47243 if (delegate)
244 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34245}
246
[email protected]f98f5092012-05-19 00:08:14247int GetSwitchValueAsInt(
248 const CommandLine& command_line,
249 const std::string& switch_string,
250 int min_value) {
251 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
252 int int_value;
253 if (base::StringToInt(string_value, &int_value))
254 return std::max(min_value, int_value);
255 else
256 return min_value;
257}
258
[email protected]420ae012009-04-24 05:16:32259} // namespace
260
[email protected]54944cde2012-12-09 09:24:59261WebContents* WebContents::Create(const WebContents::CreateParams& params) {
262 return WebContentsImpl::CreateWithOpener(params, NULL);
[email protected]d1198fd2012-08-13 22:50:19263}
264
265WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59266 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19267 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59268 WebContentsImpl* new_contents = new WebContentsImpl(
269 params.browser_context, NULL);
[email protected]d1198fd2012-08-13 22:50:19270
271 for (SessionStorageNamespaceMap::const_iterator it =
272 session_storage_namespace_map.begin();
273 it != session_storage_namespace_map.end();
274 ++it) {
275 new_contents->GetController().SetSessionStorageNamespace(it->first,
276 it->second);
277 }
278
[email protected]54944cde2012-12-09 09:24:59279 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19280 return new_contents;
[email protected]a81343d232011-12-27 07:39:20281}
[email protected]746d3052012-05-22 15:15:47282
[email protected]299d7f12012-05-23 05:31:15283WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47284 return rvh->GetDelegate()->GetAsWebContents();
285}
286
[email protected]b172aee2012-04-10 17:05:26287// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32288
[email protected]b172aee2012-04-10 17:05:26289WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21290 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19291 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42292 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19293 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57294 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44295 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05296 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34297 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23298 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
299 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34300 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21301 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56302 upload_size_(0),
303 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47304 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57305 capturing_contents_(false),
306 is_being_destroyed_(false),
307 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55308 dialog_creator_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01309 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56310 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38311 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21312 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
313 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00314 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43315 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20316 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35317}
initial.commit09911bf2008-07-26 23:55:29318
[email protected]b172aee2012-04-10 17:05:26319WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32320 is_being_destroyed_ = true;
321
[email protected]b24b68a2012-09-24 21:57:26322 for (std::set<RenderWidgetHostImpl*>::iterator iter =
323 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
324 (*iter)->DetachDelegate();
325 }
326 created_widgets_.clear();
327
[email protected]3ab9cb82011-06-03 18:02:07328 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55329 if (dialog_creator_)
330 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07331
[email protected]da8543762012-03-20 08:52:20332 if (color_chooser_)
333 color_chooser_->End();
334
[email protected]420ae012009-04-24 05:16:32335 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32336
[email protected]ca13a442012-04-17 14:00:12337 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21338 NotificationService::current()->Notify(
339 NOTIFICATION_WEB_CONTENTS_DESTROYED,
340 Source<WebContents>(this),
341 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32342
343 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07344#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32345 // If we still have a window handle, destroy it. GetNativeView can return
346 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42347 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52348 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58349 if (host && host->GetView())
350 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42351 }
[email protected]420ae012009-04-24 05:16:32352#endif
[email protected]7ab1e7d62009-10-14 23:32:01353
354 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15355 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55356 base::TimeTicks now = base::TimeTicks::Now();
357 base::TimeTicks unload_start_time = close_start_time_;
358 if (!before_unload_end_time_.is_null())
359 unload_start_time = before_unload_end_time_;
360 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
361 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01362 }
[email protected]b5a1d11c2011-02-17 03:09:42363
[email protected]2db9bd72012-04-13 20:20:56364 FOR_EACH_OBSERVER(WebContentsObserver,
365 observers_,
366 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08367
[email protected]6934a702011-12-20 00:04:51368 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42369}
370
[email protected]d1198fd2012-08-13 22:50:19371WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59372 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19373 WebContentsImpl* opener) {
[email protected]54944cde2012-12-09 09:24:59374 WebContentsImpl* new_contents = new WebContentsImpl(
375 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19376
[email protected]54944cde2012-12-09 09:24:59377 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19378 return new_contents;
379}
380
[email protected]dd8c8232012-11-03 00:49:36381WebContentsImpl* WebContentsImpl::CreateGuest(
382 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53383 SiteInstance* site_instance,
[email protected]3de10bb32013-01-08 21:57:33384 int routing_id,
385 WebContentsImpl* opener_web_contents,
[email protected]dd8c8232012-11-03 00:49:36386 int guest_instance_id,
387 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]b5a40842012-11-28 15:26:11388
[email protected]3de10bb32013-01-08 21:57:33389 WebContentsImpl* new_contents = new WebContentsImpl(browser_context,
390 opener_web_contents);
[email protected]7a846df2012-09-20 19:17:39391
392 // This makes |new_contents| act as a guest.
393 // For more info, see comment above class BrowserPluginGuest.
[email protected]b5a40842012-11-28 15:26:11394 new_contents->browser_plugin_guest_.reset(
395 BrowserPluginGuest::Create(
396 guest_instance_id,
397 new_contents,
398 params));
399
[email protected]3de10bb32013-01-08 21:57:33400 WebContents::CreateParams create_params(browser_context, site_instance);
401 create_params.routing_id = routing_id;
402 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11403
[email protected]7a846df2012-09-20 19:17:39404 return new_contents;
405}
406
[email protected]b172aee2012-04-10 17:05:26407WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
408 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54409 WebPreferences prefs;
410
411 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
412
413 prefs.developer_extras_enabled = true;
414 prefs.javascript_enabled =
415 !command_line.HasSwitch(switches::kDisableJavaScript);
416 prefs.web_security_enabled =
417 !command_line.HasSwitch(switches::kDisableWebSecurity);
418 prefs.plugins_enabled =
419 !command_line.HasSwitch(switches::kDisablePlugins);
420 prefs.java_enabled =
421 !command_line.HasSwitch(switches::kDisableJava);
422
423 prefs.uses_page_cache =
424 command_line.HasSwitch(switches::kEnableFastback);
425 prefs.remote_fonts_enabled =
426 !command_line.HasSwitch(switches::kDisableRemoteFonts);
427 prefs.xss_auditor_enabled =
428 !command_line.HasSwitch(switches::kDisableXSSAuditor);
429 prefs.application_cache_enabled =
430 !command_line.HasSwitch(switches::kDisableApplicationCache);
431
432 prefs.local_storage_enabled =
433 !command_line.HasSwitch(switches::kDisableLocalStorage);
434 prefs.databases_enabled =
435 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01436#if defined(OS_ANDROID)
437 prefs.webaudio_enabled =
438 command_line.HasSwitch(switches::kEnableWebAudio);
439#else
[email protected]64d69de42012-02-06 00:19:54440 prefs.webaudio_enabled =
441 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01442#endif
[email protected]64d69de42012-02-06 00:19:54443
444 prefs.experimental_webgl_enabled =
445 GpuProcessHost::gpu_enabled() &&
446 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07447#if defined(OS_ANDROID)
448 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
449#else
[email protected]64d69de42012-02-06 00:19:54450 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07451#endif
[email protected]64d69de42012-02-06 00:19:54452
[email protected]5a073092012-06-08 00:42:51453 prefs.flash_3d_enabled =
454 GpuProcessHost::gpu_enabled() &&
455 !command_line.HasSwitch(switches::kDisableFlash3d);
456 prefs.flash_stage3d_enabled =
457 GpuProcessHost::gpu_enabled() &&
458 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19459
[email protected]64d69de42012-02-06 00:19:54460 prefs.gl_multisampling_enabled =
461 !command_line.HasSwitch(switches::kDisableGLMultisampling);
462 prefs.privileged_webgl_extensions_enabled =
463 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
464 prefs.site_specific_quirks_enabled =
465 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
466 prefs.allow_file_access_from_file_urls =
467 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
468 prefs.show_composited_layer_borders =
469 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
470 prefs.show_composited_layer_tree =
471 command_line.HasSwitch(switches::kShowCompositedLayerTree);
472 prefs.show_fps_counter =
473 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08474 prefs.accelerated_compositing_for_overflow_scroll_enabled =
[email protected]1315fdf2012-12-12 19:45:16475 command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll);
476 prefs.accelerated_compositing_for_scrollable_frames_enabled =
477 command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames);
[email protected]ab3dd632013-01-09 23:19:08478 prefs.composited_scrolling_for_frames_enabled =
479 command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames);
[email protected]8611a852012-05-23 22:11:19480 prefs.show_paint_rects =
481 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52482 prefs.render_vsync_enabled =
483 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54484 prefs.accelerated_compositing_enabled =
485 GpuProcessHost::gpu_enabled() &&
486 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54487 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23488 command_line.HasSwitch(switches::kForceCompositingMode) &&
489 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54490 prefs.fixed_position_compositing_enabled =
491 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
492 prefs.accelerated_2d_canvas_enabled =
493 GpuProcessHost::gpu_enabled() &&
494 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58495 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27496 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]a7f899e2013-01-09 12:15:44497 prefs.antialiased_2d_canvas_disabled =
498 command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
[email protected]64d69de42012-02-06 00:19:54499 prefs.accelerated_painting_enabled =
500 GpuProcessHost::gpu_enabled() &&
501 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
502 prefs.accelerated_filters_enabled =
503 GpuProcessHost::gpu_enabled() &&
504 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
[email protected]9bdcfd642012-11-14 21:24:26505 prefs.accelerated_compositing_for_3d_transforms_enabled =
506 prefs.accelerated_compositing_for_animation_enabled =
[email protected]64d69de42012-02-06 00:19:54507 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]9bdcfd642012-11-14 21:24:26508 prefs.accelerated_compositing_for_plugins_enabled =
[email protected]64d69de42012-02-06 00:19:54509 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
[email protected]9bdcfd642012-11-14 21:24:26510 prefs.accelerated_compositing_for_video_enabled =
[email protected]64d69de42012-02-06 00:19:54511 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54512 prefs.fullscreen_enabled =
513 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43514 prefs.css_sticky_position_enabled =
515 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29516 prefs.css_shaders_enabled =
517 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01518 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03519 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]8eb51382012-11-20 00:42:33520 prefs.css_grid_layout_enabled =
521 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]d7932532012-11-21 21:10:31522
523 bool touch_device_present = false;
[email protected]c71fe6402012-08-15 15:22:55524#if defined(USE_AURA) && defined(USE_X11)
[email protected]d7932532012-11-21 21:10:31525 touch_device_present =
[email protected]c71fe6402012-08-15 15:22:55526 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
527#endif
[email protected]25ee94f2012-09-11 19:16:16528#if defined(OS_WIN)
[email protected]d7932532012-11-21 21:10:31529 touch_device_present = ui::IsTouchDevicePresent();
[email protected]25ee94f2012-09-11 19:16:16530#endif
[email protected]d849b122012-07-18 07:35:26531#if defined(OS_ANDROID)
[email protected]d7932532012-11-21 21:10:31532 touch_device_present = true;
533#endif
534 const std::string touch_enabled_switch =
535 command_line.HasSwitch(switches::kTouchEvents) ?
536 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
537 switches::kTouchEventsAuto;
538
539 if (touch_enabled_switch.empty() ||
540 touch_enabled_switch == switches::kTouchEventsEnabled) {
541 prefs.touch_enabled = true;
542 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
543 prefs.touch_enabled = touch_device_present;
544 } else if (touch_enabled_switch != switches::kTouchEventsDisabled) {
545 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
546 }
547
548 prefs.device_supports_touch = prefs.touch_enabled && touch_device_present;
549#if defined(OS_ANDROID)
[email protected]d849b122012-07-18 07:35:26550 prefs.device_supports_mouse = false;
551#endif
[email protected]64d69de42012-02-06 00:19:54552
[email protected]b9c96ff2012-11-26 22:24:40553 prefs.touch_adjustment_enabled =
554 !command_line.HasSwitch(switches::kDisableTouchAdjustment);
555
[email protected]64d69de42012-02-06 00:19:54556#if defined(OS_MACOSX)
557 bool default_enable_scroll_animator = true;
558#else
559 // On CrOS, the launcher always passes in the --enable flag.
560 bool default_enable_scroll_animator = false;
561#endif
562 prefs.enable_scroll_animator = default_enable_scroll_animator;
563 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
564 prefs.enable_scroll_animator = true;
565 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
566 prefs.enable_scroll_animator = false;
567
568 prefs.visual_word_movement_enabled =
569 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54570
571 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32572 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54573 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39574 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21575 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54576 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21577 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54578 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21579 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19580 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21581 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19582 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21583 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54584 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21585 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54586 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21587 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]9bdcfd642012-11-14 21:24:26588 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
589 prefs.accelerated_compositing_for_animation_enabled = false;
[email protected]c521d7462012-10-03 22:28:20590 }
[email protected]8ff00d72012-10-23 19:12:21591 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]9bdcfd642012-11-14 21:24:26592 prefs.accelerated_compositing_for_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54593
594 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45595 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32596 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]9bdcfd642012-11-14 21:24:26597 prefs.accelerated_compositing_for_video_enabled = false;
598 prefs.accelerated_compositing_for_animation_enabled = false;
599 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
600 prefs.accelerated_compositing_for_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54601 }
602 }
603
[email protected]b9535422012-02-09 01:47:59604 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58605 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54606 prefs.loads_images_automatically = true;
607 prefs.javascript_enabled = true;
608 }
609
610 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
611
[email protected]2ee33532013-01-17 12:27:03612 // Force accelerated compositing and 2d canvas off for chrome: and about:
613 // pages (unless it's specifically allowed).
614 if ((url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]64d69de42012-02-06 00:19:54615 (url.SchemeIs(chrome::kAboutScheme) &&
616 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25617 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54618 prefs.accelerated_compositing_enabled = false;
619 prefs.accelerated_2d_canvas_enabled = false;
620 }
[email protected]43d9d782012-03-01 15:40:09621
[email protected]2ee33532013-01-17 12:27:03622 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
623 prefs.show_fps_counter = false;
624
[email protected]f98f5092012-05-19 00:08:14625 if (command_line.HasSwitch(switches::kDefaultTileWidth))
626 prefs.default_tile_width =
627 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
628 if (command_line.HasSwitch(switches::kDefaultTileHeight))
629 prefs.default_tile_height =
630 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
631 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
632 prefs.max_untiled_layer_width =
633 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
634 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
635 prefs.max_untiled_layer_height =
636 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
637
[email protected]ffabb1e2012-10-12 19:51:17638 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
639 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19640 // Only apply when using DIP coordinate system as this setting interferes
641 // with fixed layout mode.
[email protected]9bdcfd642012-11-14 21:24:26642 // TODO(danakj): Fixed layout mode is going away, so turn this on always.
[email protected]2486dce2012-05-23 17:18:19643 prefs.apply_default_device_scale_factor_in_compositor = true;
644 }
645
[email protected]9bdcfd642012-11-14 21:24:26646 prefs.apply_page_scale_factor_in_compositor =
[email protected]16ad47f82012-12-05 21:06:06647 command_line.HasSwitch(switches::kEnablePinch);
[email protected]f49dece2013-01-12 19:04:28648
649 if (command_line.HasSwitch(switches::kEnableCssTransformPinch)) {
650 prefs.apply_default_device_scale_factor_in_compositor = false;
651 prefs.apply_page_scale_factor_in_compositor = false;
652 }
653
[email protected]9bdcfd642012-11-14 21:24:26654 prefs.per_tile_painting_enabled =
655 command_line.HasSwitch(cc::switches::kEnablePerTilePainting);
[email protected]cf6cb622012-11-16 02:00:19656 prefs.accelerated_animation_enabled =
[email protected]9bdcfd642012-11-14 21:24:26657 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
658
[email protected]de023762012-07-26 17:10:17659 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
660 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10661
[email protected]e755a382012-09-13 17:16:35662 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
663 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12664
[email protected]6b4dcb072012-06-18 22:26:51665 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
666
[email protected]5c90d03d2013-01-10 17:16:02667 prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport);
668
[email protected]76f7d4882012-10-26 21:09:22669 prefs.deferred_image_decoding_enabled =
670 command_line.HasSwitch(switches::kEnableDeferredImageDecoding);
671
[email protected]8ff00d72012-10-23 19:12:21672 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54673
[email protected]97456602012-10-03 18:44:25674 // Disable compositing in guests until we have compositing path implemented
675 // for guests.
[email protected]747c30652012-12-18 20:35:53676 bool guest_compositing_enabled = command_line.HasSwitch(
677 switches::kEnableBrowserPluginCompositing);
678 if (rvh->GetProcess()->IsGuest() && !guest_compositing_enabled) {
[email protected]97456602012-10-03 18:44:25679 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06680 prefs.accelerated_compositing_enabled = false;
681 }
[email protected]97456602012-10-03 18:44:25682
[email protected]64d69de42012-02-06 00:19:54683 return prefs;
684}
685
[email protected]b172aee2012-04-10 17:05:26686RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28687 return &render_manager_;
688}
689
[email protected]7bb761892012-07-20 09:32:47690bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
691 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56692 if (GetWebUI() &&
693 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17694 return true;
[email protected]d2353452012-01-19 19:53:56695 }
[email protected]f82d57b52011-04-27 19:13:17696
[email protected]d8c660432011-12-22 20:51:25697 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
698 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10699 while ((observer = it.GetNext()) != NULL)
700 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53701 return true;
[email protected]403415a2011-01-10 18:57:53702
[email protected]7bb761892012-07-20 09:32:47703 // Message handlers should be aware of which RenderViewHost sent the
704 // message, which is temporarily stored in message_source_.
705 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18706 bool handled = true;
707 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26708 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58709 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
710 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24711 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
712 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18713 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
714 OnDidLoadResourceFromMemoryCache)
715 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
716 OnDidDisplayInsecureContent)
717 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
718 OnDidRunInsecureContent)
719 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
720 OnDocumentLoadedInFrame)
721 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26722 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
723 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17724 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
725 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25726 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26727 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59728 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21729 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20730 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
731 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
732 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16733 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45734 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10735 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20736 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
737 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
738 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
739 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29740 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50741 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50742 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
743 OnRequestPpapiBrokerPermission)
[email protected]19be7a62012-10-01 23:03:37744 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
745 OnBrowserPluginCreateGuest)
[email protected]795c28972012-12-06 06:13:39746 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
747 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10748#if defined(OS_ANDROID)
749 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
750 OnFindMatchRectsReply)
751 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
752 OnOpenDateTimeDialog)
753#endif
[email protected]724159a2010-12-30 01:11:18754 IPC_MESSAGE_UNHANDLED(handled = false)
755 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47756 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18757
758 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21759 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18760 GetRenderProcessHost()->ReceivedBadMessage();
761 }
762
763 return handled;
764}
765
[email protected]b172aee2012-04-10 17:05:26766void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18767 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21768 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43769 if (delegate_)
770 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18771}
772
[email protected]d1198fd2012-08-13 22:50:19773NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56774 return controller_;
775}
776
[email protected]d1198fd2012-08-13 22:50:19777const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56778 return controller_;
779}
780
[email protected]8ff00d72012-10-23 19:12:21781BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55782 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30783}
784
[email protected]b172aee2012-04-10 17:05:26785const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31786 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23787 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51788 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31789}
790
[email protected]8ff00d72012-10-23 19:12:21791WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31792 return delegate_;
793}
794
[email protected]8ff00d72012-10-23 19:12:21795void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31796 // TODO(cbentzel): remove this debugging code?
797 if (delegate == delegate_)
798 return;
799 if (delegate_)
800 delegate_->Detach(this);
801 delegate_ = delegate;
802 if (delegate_)
803 delegate_->Attach(this);
804}
805
[email protected]8ff00d72012-10-23 19:12:21806RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41807 RenderViewHostImpl* host = render_manager_.current_host();
808 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16809}
810
[email protected]b172aee2012-04-10 17:05:26811RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31812 return render_manager_.current_host();
813}
814
[email protected]a04c9d02012-11-14 21:04:34815void WebContentsImpl::GetRenderViewHostAtPosition(
816 int x,
817 int y,
818 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
819 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
820 if (embedder)
821 embedder->GetRenderViewHostAtPosition(x, y, callback);
822 else
823 callback.Run(GetRenderViewHost(), x, y);
824}
825
[email protected]6b618e62012-08-16 12:59:18826int WebContentsImpl::GetRoutingID() const {
827 if (!GetRenderViewHost())
828 return MSG_ROUTING_NONE;
829
830 return GetRenderViewHost()->GetRoutingID();
831}
832
[email protected]b172aee2012-04-10 17:05:26833RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31834 return render_manager_.GetRenderWidgetHostView();
835}
836
[email protected]8ff00d72012-10-23 19:12:21837WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return view_.get();
839}
840
[email protected]8ff00d72012-10-23 19:12:21841WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]3c788372013-01-10 08:34:28842 WebUIControllerFactory* factory =
843 GetContentClient()->browser()->GetWebUIControllerFactory();
844 if (!factory)
845 return NULL;
[email protected]d2353452012-01-19 19:53:56846 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]3c788372013-01-10 08:34:28847 WebUIController* controller =
848 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22849 if (controller) {
850 web_ui->SetController(controller);
851 return web_ui;
852 }
853
854 delete web_ui;
855 return NULL;
856}
857
[email protected]8ff00d72012-10-23 19:12:21858WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return render_manager_.web_ui() ? render_manager_.web_ui()
860 : render_manager_.pending_web_ui();
861}
862
[email protected]8ff00d72012-10-23 19:12:21863WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31864 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34865}
866
[email protected]86ef6a392012-05-11 22:03:11867void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22868 if (GetUserAgentOverride() == override)
869 return;
870
871 renderer_preferences_.user_agent_override = override;
872
873 // Send the new override string to the renderer.
874 RenderViewHost* host = GetRenderViewHost();
875 if (host)
876 host->SyncRendererPrefs();
877
878 // Reload the page if a load is currently in progress to avoid having
879 // different parts of the page loaded using different user agents.
880 NavigationEntry* entry = controller_.GetActiveEntry();
881 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
882 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53883
884 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
885 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11886}
887
888const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22889 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11890}
891
[email protected]b172aee2012-04-10 17:05:26892const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55893 // Transient entries take precedence. They are used for interstitial pages
894 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23895 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08896 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21897 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30898 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23899 if (entry) {
[email protected]b5cca982011-05-26 04:42:08900 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23901 }
[email protected]7ade2732011-02-10 00:13:58902 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
903 render_manager_.pending_web_ui() : render_manager_.web_ui();
904 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54905 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55906 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54907 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35908 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22909 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54910 if (!title.empty())
911 return title;
912 }
913 }
914
915 // We use the title for the last committed entry rather than a pending
916 // navigation entry. For example, when the user types in a URL, we want to
917 // keep the old page's title until the new load has committed and we get a new
918 // title.
[email protected]96d185d2009-04-24 03:28:54919 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23920 if (entry) {
[email protected]b5cca982011-05-26 04:42:08921 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23922 }
[email protected]987fc3a2011-05-26 14:18:09923
924 // |page_title_when_no_navigation_entry_| is finally used
925 // if no title cannot be retrieved.
926 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54927}
928
[email protected]b172aee2012-04-10 17:05:26929int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46930 return GetMaxPageIDForSiteInstance(GetSiteInstance());
931}
932
[email protected]b172aee2012-04-10 17:05:26933int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
934 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33935 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
936 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46937
[email protected]b6583592012-01-25 19:52:33938 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34939}
940
[email protected]b172aee2012-04-10 17:05:26941void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46942 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
943}
944
[email protected]b172aee2012-04-10 17:05:26945void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33946 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46947 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33948 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34949}
950
[email protected]b172aee2012-04-10 17:05:26951void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
952 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57953}
954
[email protected]b172aee2012-04-10 17:05:26955SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58956 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54957}
958
[email protected]b172aee2012-04-10 17:05:26959SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38960 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
961 render_manager_.pending_render_view_host() :
962 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58963 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38964}
965
[email protected]b172aee2012-04-10 17:05:26966bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31967 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49968}
969
[email protected]b172aee2012-04-10 17:05:26970bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31971 return waiting_for_response_;
972}
973
[email protected]b172aee2012-04-10 17:05:26974const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31975 return load_state_;
976}
977
[email protected]b172aee2012-04-10 17:05:26978const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31979 return load_state_host_;
980}
981
[email protected]b172aee2012-04-10 17:05:26982uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31983 return upload_size_;
984}
985
[email protected]b172aee2012-04-10 17:05:26986uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31987 return upload_position_;
988}
989
[email protected]b172aee2012-04-10 17:05:26990const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31991 return encoding_;
992}
993
[email protected]b172aee2012-04-10 17:05:26994bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31995 return displayed_insecure_content_;
996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31999 capturing_contents_ = cap;
1000}
1001
[email protected]b172aee2012-04-10 17:05:261002bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311003 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1004 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1005 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491006}
1007
[email protected]b172aee2012-04-10 17:05:261008void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1009 int error_code) {
[email protected]443b80e2010-12-14 00:42:231010 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341011 return;
1012
[email protected]443b80e2010-12-14 00:42:231013 crashed_status_ = status;
1014 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211015 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341016}
1017
[email protected]b172aee2012-04-10 17:05:261018base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311019 return crashed_status_;
1020}
1021
[email protected]b172aee2012-04-10 17:05:261022bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311023 return is_being_destroyed_;
1024}
1025
[email protected]b172aee2012-04-10 17:05:261026void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341027 if (delegate_)
1028 delegate_->NavigationStateChanged(this, changed_flags);
1029}
1030
[email protected]3e324142012-06-25 18:26:331031base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1032 return last_selected_time_;
1033}
1034
[email protected]9e2e4632012-07-27 16:38:411035void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541036 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041037 RenderWidgetHostViewPort* rwhv =
1038 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161039 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411040 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431041#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161042 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431043#endif
1044 }
[email protected]96d185d2009-04-24 03:28:541045
[email protected]5ac20162010-11-24 23:33:111046 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381047
[email protected]9e2e4632012-07-27 16:38:411048 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591049
1050 // The resize rect might have changed while this was inactive -- send the new
1051 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581052 RenderViewHostImpl* rvh =
1053 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591054 if (rvh) {
1055 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1056 }
[email protected]96d185d2009-04-24 03:28:541057
[email protected]3e324142012-06-25 18:26:331058 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211059 NotificationService::current()->Notify(
1060 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1061 Source<WebContents>(this),
1062 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311063}
1064
[email protected]b172aee2012-04-10 17:05:261065void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311066 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521067 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1068 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261069 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521070 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331071 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521072 // calls us).
[email protected]c30585c2012-02-16 15:02:041073 RenderWidgetHostViewPort* rwhv =
1074 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161075 if (rwhv)
1076 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541077 }
1078
[email protected]375fa1b2012-05-22 22:05:371079 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211080 NotificationService::current()->Notify(
1081 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1082 Source<WebContents>(this),
1083 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371084}
1085
[email protected]b172aee2012-04-10 17:05:261086bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311087 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271088 return WillNotifyDisconnection() &&
1089 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581090 !static_cast<RenderViewHostImpl*>(
1091 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311092}
1093
[email protected]b172aee2012-04-10 17:05:261094void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271095 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251096 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271097}
1098
[email protected]b172aee2012-04-10 17:05:261099WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441100 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451101 // We pass our own opener so that the cloned page can access it if it was
1102 // before.
[email protected]54944cde2012-12-09 09:24:591103 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451104 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591105 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191106 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221107 FOR_EACH_OBSERVER(WebContentsObserver,
1108 observers_,
1109 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271110 return tc;
1111}
1112
[email protected]b172aee2012-04-10 17:05:261113gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271114 return view_->GetContentNativeView();
1115}
1116
[email protected]b172aee2012-04-10 17:05:261117gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271118 return view_->GetNativeView();
1119}
1120
[email protected]b172aee2012-04-10 17:05:261121void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271122 view_->GetContainerBounds(out);
1123}
1124
[email protected]b172aee2012-04-10 17:05:261125void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271126 view_->Focus();
1127}
1128
[email protected]14392a52012-05-02 20:28:441129void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211130 const NotificationSource& source,
1131 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441132 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211133 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1134 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441135 break;
[email protected]8ff00d72012-10-23 19:12:211136 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1137 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501138 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1139 i != pending_widget_views_.end(); ++i) {
1140 if (host->GetView() == i->second) {
1141 pending_widget_views_.erase(i);
1142 break;
1143 }
1144 }
1145 break;
1146 }
[email protected]14392a52012-05-02 20:28:441147 default:
1148 NOTREACHED();
1149 }
1150}
1151
[email protected]54944cde2012-12-09 09:24:591152void WebContentsImpl::Init(const WebContents::CreateParams& params) {
1153 render_manager_.Init(
1154 params.browser_context, params.site_instance, params.routing_id);
[email protected]d1198fd2012-08-13 22:50:191155
[email protected]8ff00d72012-10-23 19:12:211156 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191157 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1158 if (view_.get()) {
1159 CHECK(render_view_host_delegate_view_);
1160 } else {
[email protected]b5a40842012-11-28 15:26:111161 if (browser_plugin_guest_.get() &&
1162 CommandLine::ForCurrentProcess()->HasSwitch(
1163 switches::kEnableBrowserPluginCompositing)) {
1164 WebContentsViewGuest* rv = new WebContentsViewGuest(
1165 this,
1166 browser_plugin_guest_.get());
1167 render_view_host_delegate_view_ = rv;
1168 view_.reset(rv);
1169 } else {
1170 WebContentsViewDelegate* delegate =
1171 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1172 view_.reset(CreateWebContentsView(
1173 this, delegate, &render_view_host_delegate_view_));
1174 }
[email protected]d1198fd2012-08-13 22:50:191175 CHECK(render_view_host_delegate_view_);
1176 }
1177 CHECK(view_.get());
1178
[email protected]ed245db2012-12-18 08:00:451179 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591180 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191181
1182 // Listen for whether our opener gets destroyed.
1183 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211184 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1185 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191186 }
1187
1188 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211189 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1190 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191191#if defined(ENABLE_JAVA_BRIDGE)
1192 java_bridge_dispatcher_host_manager_.reset(
1193 new JavaBridgeDispatcherHostManager(this));
1194#endif
[email protected]583418cc2013-01-17 14:01:101195
1196#if defined(OS_ANDROID)
1197 date_time_chooser_.reset(new DateTimeChooserAndroid());
1198#endif
[email protected]d1198fd2012-08-13 22:50:191199}
1200
[email protected]14392a52012-05-02 20:28:441201void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1202 // Clear the opener if it has been closed.
1203 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211204 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1205 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441206 opener_ = NULL;
1207 }
1208}
1209
[email protected]b172aee2012-04-10 17:05:261210void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311211 observers_.AddObserver(observer);
1212}
1213
[email protected]b172aee2012-04-10 17:05:261214void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311215 observers_.RemoveObserver(observer);
1216}
1217
[email protected]b172aee2012-04-10 17:05:261218void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341219 if (delegate_)
1220 delegate_->ActivateContents(this);
1221}
1222
[email protected]b172aee2012-04-10 17:05:261223void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121224 if (delegate_)
1225 delegate_->DeactivateContents(this);
1226}
1227
[email protected]b172aee2012-04-10 17:05:261228void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481229 if (delegate_)
1230 delegate_->LostCapture();
1231}
1232
[email protected]b24b68a2012-09-24 21:57:261233void WebContentsImpl::RenderWidgetDeleted(
1234 RenderWidgetHostImpl* render_widget_host) {
1235 if (is_being_destroyed_) {
1236 // |created_widgets_| might have been destroyed.
1237 return;
1238 }
1239
1240 std::set<RenderWidgetHostImpl*>::iterator iter =
1241 created_widgets_.find(render_widget_host);
1242 if (iter != created_widgets_.end())
1243 created_widgets_.erase(iter);
1244}
1245
[email protected]b172aee2012-04-10 17:05:261246bool WebContentsImpl::PreHandleKeyboardEvent(
1247 const NativeWebKeyboardEvent& event,
1248 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481249 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131250 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481251}
1252
[email protected]b172aee2012-04-10 17:05:261253void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481254 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131255 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481256}
1257
[email protected]b172aee2012-04-10 17:05:261258void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431259 if (delegate_)
1260 delegate_->HandleMouseDown();
1261}
1262
[email protected]b172aee2012-04-10 17:05:261263void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481264 if (delegate_)
1265 delegate_->HandleMouseUp();
1266}
1267
[email protected]590a634e2012-07-19 16:38:231268void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481269 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231270 delegate_->HandlePointerActivate();
1271}
1272
1273void WebContentsImpl::HandleGestureBegin() {
1274 if (delegate_)
1275 delegate_->HandleGestureBegin();
1276}
1277
1278void WebContentsImpl::HandleGestureEnd() {
1279 if (delegate_)
1280 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481281}
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471284 if (delegate_)
1285 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1286}
1287
[email protected]b172aee2012-04-10 17:05:261288bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381289 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121290}
1291
[email protected]a9c81f02012-06-01 00:15:441292void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1293 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371294 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441295 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371296 } else {
1297 GotResponseToLockMouseRequest(false);
1298 }
1299}
1300
[email protected]b172aee2012-04-10 17:05:261301void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371302 if (delegate_)
1303 delegate_->LostMouseLock();
1304}
1305
[email protected]bafe6cd2012-05-23 23:09:501306void WebContentsImpl::CreateNewWindow(
1307 int route_id,
[email protected]97714c82012-06-06 10:15:131308 const ViewHostMsg_CreateWindow_Params& params,
1309 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501310 if (delegate_ && !delegate_->ShouldCreateWebContents(
1311 this, route_id, params.window_container_type, params.frame_name,
1312 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091313 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501314 return;
1315 }
1316
1317 // We usually create the new window in the same BrowsingInstance (group of
1318 // script-related windows), by passing in the current SiteInstance. However,
1319 // if the opener is being suppressed, we create a new SiteInstance in its own
1320 // BrowsingInstance.
1321 scoped_refptr<SiteInstance> site_instance =
1322 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571323 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501324 GetSiteInstance();
1325
1326 // Create the new web contents. This will automatically create the new
1327 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191328 WebContentsImpl* new_contents =
1329 new WebContentsImpl(GetBrowserContext(),
1330 params.opener_suppressed ? NULL : this);
1331
1332 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341333 //
1334 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191335 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211336 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571337 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591338 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211339 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341340 BrowserContext::GetStoragePartition(GetBrowserContext(),
1341 site_instance);
[email protected]d1198fd2012-08-13 22:50:191342 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341343 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191344 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1345 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1346 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1347 new_contents->GetController().SetSessionStorageNamespace(
1348 partition_id,
1349 session_storage_namespace);
[email protected]54944cde2012-12-09 09:24:591350 CreateParams create_params(GetBrowserContext(), site_instance);
1351 create_params.routing_id = route_id;
[email protected]ed245db2012-12-18 08:00:451352 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591353 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191354
[email protected]bafe6cd2012-05-23 23:09:501355 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1356
1357 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211358 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501359
1360 // TODO(brettw): It seems bogus that we have to call this function on the
1361 // newly created object and give it one of its own member variables.
1362 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1363
1364 // Save the created window associated with the route so we can show it
1365 // later.
1366 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1367 pending_contents_[route_id] = new_contents;
1368 }
1369
1370 if (delegate_) {
1371 delegate_->WebContentsCreated(
1372 this, params.opener_frame_id, params.target_url, new_contents);
1373 }
1374
1375 if (params.opener_suppressed) {
1376 // When the opener is suppressed, the original renderer cannot access the
1377 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001378 bool was_blocked = false;
1379 if (delegate_) {
1380 gfx::Rect initial_pos;
1381 delegate_->AddNewContents(
1382 this, new_contents, params.disposition, initial_pos,
1383 params.user_gesture, &was_blocked);
1384 }
1385 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211386 OpenURLParams open_params(params.target_url,
1387 Referrer(),
1388 CURRENT_TAB,
1389 PAGE_TRANSITION_LINK,
1390 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001391 new_contents->OpenURL(open_params);
1392 }
[email protected]bafe6cd2012-05-23 23:09:501393 }
1394}
1395
1396void WebContentsImpl::CreateNewWidget(int route_id,
1397 WebKit::WebPopupType popup_type) {
1398 CreateNewWidget(route_id, false, popup_type);
1399}
1400
1401void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1402 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1403}
1404
1405void WebContentsImpl::CreateNewWidget(int route_id,
1406 bool is_fullscreen,
1407 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211408 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501409 RenderWidgetHostImpl* widget_host =
1410 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261411 created_widgets_.insert(widget_host);
1412
[email protected]83918ec2013-01-10 15:37:191413 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1414 view_->CreateViewForPopupWidget(widget_host));
1415 if (!widget_view)
1416 return;
[email protected]bafe6cd2012-05-23 23:09:501417 if (!is_fullscreen) {
1418 // Popups should not get activated.
1419 widget_view->SetPopupType(popup_type);
1420 }
1421 // Save the created widget associated with the route so we can show it later.
1422 pending_widget_views_[route_id] = widget_view;
1423
1424#if defined(OS_MACOSX)
1425 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1426 // to allow it to survive the trip without being hosted.
1427 base::mac::NSObjectRetain(widget_view->GetNativeView());
1428#endif
1429}
1430
1431void WebContentsImpl::ShowCreatedWindow(int route_id,
1432 WindowOpenDisposition disposition,
1433 const gfx::Rect& initial_pos,
1434 bool user_gesture) {
1435 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001436 if (contents) {
1437 WebContentsDelegate* delegate = GetDelegate();
1438 if (delegate) {
1439 delegate->AddNewContents(
1440 this, contents, disposition, initial_pos, user_gesture, NULL);
1441 }
1442 }
[email protected]bafe6cd2012-05-23 23:09:501443}
1444
1445void WebContentsImpl::ShowCreatedWidget(int route_id,
1446 const gfx::Rect& initial_pos) {
1447 ShowCreatedWidget(route_id, false, initial_pos);
1448}
1449
1450void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1451 ShowCreatedWidget(route_id, true, gfx::Rect());
1452}
1453
1454void WebContentsImpl::ShowCreatedWidget(int route_id,
1455 bool is_fullscreen,
1456 const gfx::Rect& initial_pos) {
1457 if (delegate_)
1458 delegate_->RenderWidgetShowing();
1459
1460 RenderWidgetHostViewPort* widget_host_view =
1461 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1462 if (!widget_host_view)
1463 return;
1464 if (is_fullscreen) {
1465 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1466 } else {
1467 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1468 }
[email protected]89054502012-06-03 10:29:241469
1470 RenderWidgetHostImpl* render_widget_host_impl =
1471 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1472 render_widget_host_impl->Init();
1473 // Only allow privileged mouse lock for fullscreen render widget, which is
1474 // used to implement Pepper Flash fullscreen.
1475 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501476
1477#if defined(OS_MACOSX)
1478 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1479 // properly embedded (or purposefully ignored) we can release the retain we
1480 // took in CreateNewWidget().
1481 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1482#endif
1483}
1484
1485WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1486 PendingContents::iterator iter = pending_contents_.find(route_id);
1487
1488 // Certain systems can block the creation of new windows. If we didn't succeed
1489 // in creating one, just return NULL.
1490 if (iter == pending_contents_.end()) {
1491 return NULL;
1492 }
1493
1494 WebContentsImpl* new_contents = iter->second;
1495 pending_contents_.erase(route_id);
1496
1497 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1498 !new_contents->GetRenderViewHost()->GetView())
1499 return NULL;
1500
1501 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1502 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1503 return new_contents;
1504}
1505
1506RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1507 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1508 if (iter == pending_widget_views_.end()) {
1509 DCHECK(false);
1510 return NULL;
1511 }
1512
1513 RenderWidgetHostView* widget_host_view = iter->second;
1514 pending_widget_views_.erase(route_id);
1515
1516 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1517 if (!widget_host->GetProcess()->HasConnection()) {
1518 // The view has gone away or the renderer crashed. Nothing to do.
1519 return NULL;
1520 }
1521
1522 return widget_host_view;
1523}
1524
1525void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211526 const ContextMenuParams& params,
1527 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501528 // Allow WebContentsDelegates to handle the context menu operation first.
1529 if (delegate_ && delegate_->HandleContextMenu(params))
1530 return;
1531
[email protected]ba16e3a2012-09-07 04:14:521532 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501533}
1534
[email protected]f13b4202012-06-12 23:53:231535void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091536 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211537 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231538 if (delegate_)
1539 delegate_->RequestMediaAccessPermission(this, request, callback);
1540 else
[email protected]8ff00d72012-10-23 19:12:211541 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231542}
1543
[email protected]b172aee2012-04-10 17:05:261544void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231545 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331546 if (delegate_)
1547 delegate_->UpdatePreferredSize(this, pref_size);
1548}
1549
[email protected]b172aee2012-04-10 17:05:261550void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341551 if (delegate_)
1552 delegate_->ResizeDueToAutoResize(this, new_size);
1553}
1554
[email protected]b172aee2012-04-10 17:05:261555WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201556 if (!delegate_)
1557 return NULL;
[email protected]00c37fc2011-08-02 00:22:501558
[email protected]e5d549d2011-12-28 01:29:201559 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201560 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341561}
1562
[email protected]6b618e62012-08-16 12:59:181563bool WebContentsImpl::Send(IPC::Message* message) {
1564 if (!GetRenderViewHost()) {
1565 delete message;
1566 return false;
1567 }
1568
1569 return GetRenderViewHost()->Send(message);
1570}
1571
[email protected]b172aee2012-04-10 17:05:261572bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501573 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251574 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231575 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251576 reload_type);
[email protected]876bc832010-09-07 16:29:541577}
[email protected]96d185d2009-04-24 03:28:541578
[email protected]ba45bfd2012-05-22 21:51:441579void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211580 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1582 RenderViewForInterstitialPageCreated(render_view_host));
1583}
1584
[email protected]b172aee2012-04-10 17:05:261585bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231586 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501587 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401588 // The renderer will reject IPC messages with URLs longer than
1589 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211590 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401591 return false;
1592
[email protected]9f76c1e2012-03-05 15:15:581593 RenderViewHostImpl* dest_render_view_host =
1594 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401595 if (!dest_render_view_host)
1596 return false; // Unable to create the desired render view host.
1597
[email protected]80a8fad2011-01-29 04:02:381598 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071599 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581600 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]3c788372013-01-10 08:34:281601 WebUIControllerFactory* factory =
1602 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271603 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501604 bool is_allowed_in_web_ui_renderer =
[email protected]3c788372013-01-10 08:34:281605 factory &&
1606 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1607 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211608 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231609 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271610 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211611 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231612 CHECK(0);
1613 }
[email protected]54ec6472010-04-09 19:39:581614
[email protected]7bb761892012-07-20 09:32:471615 // Notify observers that we will navigate in this RV.
1616 FOR_EACH_OBSERVER(WebContentsObserver,
1617 observers_,
1618 AboutToNavigateRenderView(dest_render_view_host));
1619
[email protected]96d185d2009-04-24 03:28:541620 // Used for page load time metrics.
1621 current_load_start_ = base::TimeTicks::Now();
1622
1623 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341624 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271625 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471626 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341627 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541628
[email protected]36fc0392011-12-25 03:59:511629 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541630 // HACK!! This code suppresses javascript: URLs from being added to
1631 // session history, which is what we want to do for javascript: URLs that
1632 // do not generate content. What we really need is a message from the
1633 // renderer telling us that a new page was not created. The same message
1634 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511635 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541636 return false;
1637 }
1638
[email protected]3c9e1872010-11-18 16:17:491639 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251640 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041641 observers_,
[email protected]36fc0392011-12-25 03:59:511642 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541643
[email protected]09b29342011-06-24 19:18:481644 if (delegate_)
1645 delegate_->DidNavigateToPendingEntry(this);
1646
[email protected]d5f942ba2008-09-26 19:30:341647 return true;
1648}
1649
[email protected]b172aee2012-04-10 17:05:261650void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331651 const SiteInstance* site_instance,
1652 int history_length,
1653 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411654 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1655 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191656 if (render_manager_.pending_render_view_host()) {
1657 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141658 return;
[email protected]9e1ad4b2011-08-14 16:49:191659 }
[email protected]9f76c1e2012-03-05 15:15:581660 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191661 if (!rvh) {
1662 NOTREACHED();
1663 return;
1664 }
[email protected]9f76c1e2012-03-05 15:15:581665 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191666 NOTREACHED();
1667 return;
1668 }
[email protected]6b618e62012-08-16 12:59:181669 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1670 history_length,
1671 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141672}
1673
[email protected]b172aee2012-04-10 17:05:261674void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271675 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541676 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1677 return;
1678 }
[email protected]9f76c1e2012-03-05 15:15:581679 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541680}
1681
[email protected]b172aee2012-04-10 17:05:261682bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271683 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541684}
1685
[email protected]b172aee2012-04-10 17:05:261686InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271687 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221688}
1689
[email protected]b172aee2012-04-10 17:05:261690bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161691 // WebKit creates Document object when MIME type is application/xhtml+xml,
1692 // so we also support this MIME type.
1693 return contents_mime_type_ == "text/html" ||
1694 contents_mime_type_ == "text/xml" ||
1695 contents_mime_type_ == "application/xhtml+xml" ||
1696 contents_mime_type_ == "text/plain" ||
1697 contents_mime_type_ == "text/css" ||
1698 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1699}
1700
[email protected]b172aee2012-04-10 17:05:261701void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591702 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161703 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551704 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211705 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141706 return;
[email protected]c7dd2f62011-07-18 15:57:591707 }
1708
1709 Stop();
1710
1711 // Create the save package and possibly prompt the user for the name to save
1712 // the page as. The user prompt is an asynchronous operation that runs on
1713 // another thread.
1714 save_package_ = new SavePackage(this);
1715 save_package_->GetSaveInfo();
1716}
1717
1718// Used in automated testing to bypass prompting the user for file names.
1719// Instead, the names and paths are hard coded rather than running them through
1720// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261721bool WebContentsImpl::SavePage(const FilePath& main_file,
1722 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211723 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591724 // Stop the page from navigating.
1725 Stop();
1726
1727 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211728 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591729}
1730
[email protected]b172aee2012-04-10 17:05:261731void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121732 const FilePath& file,
1733 const base::Callback<void(const FilePath&, int64)>& callback) {
1734 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1735}
1736
[email protected]b172aee2012-04-10 17:05:261737bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231738 NavigationEntryImpl* active_entry =
1739 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321740 return (active_entry != NULL &&
1741 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511742 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321743}
1744
[email protected]b172aee2012-04-10 17:05:261745const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271746 return contents_mime_type_;
1747}
1748
[email protected]b172aee2012-04-10 17:05:261749bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271750 return notify_disconnection_;
1751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311754 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181755 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311759 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181760 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161761}
1762
[email protected]8ff00d72012-10-23 19:12:211763RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271764 return &renderer_preferences_;
1765}
1766
[email protected]b172aee2012-04-10 17:05:261767void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271768 new_tab_start_time_ = time;
1769}
1770
[email protected]b172aee2012-04-10 17:05:261771base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271772 return new_tab_start_time_;
1773}
1774
[email protected]e35ccd52012-05-23 16:22:471775void WebContentsImpl::Close() {
1776 Close(GetRenderViewHost());
1777}
1778
[email protected]b172aee2012-04-10 17:05:261779void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151780 if (close_start_time_.is_null())
1781 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011782}
1783
[email protected]b172aee2012-04-10 17:05:261784bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191785#if defined(OS_CHROMEOS)
1786 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1787 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511788 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201789 return false;
1790 return true;
[email protected]46624bf2010-06-09 16:04:191791#else
1792 return true;
1793#endif
1794}
1795
[email protected]b172aee2012-04-10 17:05:261796void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521797 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581798 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511799 if (delegate_)
1800 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341801}
1802
[email protected]e35ccd52012-05-23 16:22:471803void WebContentsImpl::UserGestureDone() {
1804 OnUserGesture();
1805}
1806
[email protected]b172aee2012-04-10 17:05:261807void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271808 closed_by_user_gesture_ = value;
1809}
1810
[email protected]b172aee2012-04-10 17:05:261811bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271812 return closed_by_user_gesture_;
1813}
1814
[email protected]b172aee2012-04-10 17:05:261815double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051816 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561817 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251818 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171819 return 0;
[email protected]b75b8292010-10-01 07:28:251820
1821 double zoom_level;
1822 if (temporary_zoom_settings_) {
1823 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581824 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251825 } else {
[email protected]2ae88d12011-10-14 09:11:191826 GURL url;
[email protected]10f417c52011-12-28 21:04:231827 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191828 // Since zoom map is updated using rewritten URL, use rewritten URL
1829 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511830 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191831 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251832 }
[email protected]d0b8d092010-10-25 04:05:171833 return zoom_level;
1834}
[email protected]b75b8292010-10-01 07:28:251835
[email protected]b172aee2012-04-10 17:05:261836int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591837 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171838 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011839 // Calculate the zoom percent from the factor. Round up to the nearest whole
1840 // number.
[email protected]b75b8292010-10-01 07:28:251841 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011842 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251843 *enable_decrement = percent > minimum_zoom_percent_;
1844 *enable_increment = percent < maximum_zoom_percent_;
1845 return percent;
1846}
1847
[email protected]b172aee2012-04-10 17:05:261848void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501849 if (!delegate_)
1850 return;
1851
[email protected]10f417c52011-12-28 21:04:231852 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501853 if (!active_entry)
1854 return;
1855
[email protected]36fc0392011-12-25 03:59:511856 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121857}
1858
[email protected]b172aee2012-04-10 17:05:261859void WebContentsImpl::ViewFrameSource(const GURL& url,
1860 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271861 if (!delegate_)
1862 return;
1863
1864 delegate_->ViewSourceForFrame(this, url, content_state);
1865}
1866
[email protected]b172aee2012-04-10 17:05:261867int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271868 return minimum_zoom_percent_;
1869}
1870
[email protected]b172aee2012-04-10 17:05:261871int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271872 return maximum_zoom_percent_;
1873}
1874
[email protected]b172aee2012-04-10 17:05:261875gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231876 return preferred_size_;
1877}
1878
[email protected]b172aee2012-04-10 17:05:261879int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271880 return content_restrictions_;
1881}
1882
[email protected]b172aee2012-04-10 17:05:261883WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]3c788372013-01-10 08:34:281884 WebUIControllerFactory* factory =
1885 GetContentClient()->browser()->GetWebUIControllerFactory();
1886 if (!factory)
1887 return WebUI::kNoWebUI;
1888 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271889}
1890
[email protected]8ff00d72012-10-23 19:12:211891WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271892 // When there is a pending navigation entry, we want to use the pending WebUI
1893 // that goes along with it to control the basic flags. For example, we want to
1894 // show the pending URL in the URL bar, so we want the display_url flag to
1895 // be from the pending entry.
1896 //
1897 // The confusion comes because there are multiple possibilities for the
1898 // initial load in a tab as a side effect of the way the RenderViewHostManager
1899 // works.
1900 //
1901 // - For the very first tab the load looks "normal". The new tab Web UI is
1902 // the pending one, and we want it to apply here.
1903 //
1904 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1905 // get switched to the one previously associated with the new tab pages.
1906 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1907 // have a committed Web UI in this case.
1908 //
1909 // This condition handles all of these cases:
1910 //
1911 // - First load in first tab: no committed nav entry + pending nav entry +
1912 // pending dom ui:
1913 // -> Use pending Web UI if any.
1914 //
1915 // - First load in second tab: no committed nav entry + pending nav entry +
1916 // no pending Web UI:
1917 // -> Use the committed Web UI if any.
1918 //
1919 // - Second navigation in any tab: committed nav entry + pending nav entry:
1920 // -> Use pending Web UI if any.
1921 //
1922 // - Normal state with no load: committed nav entry + no pending nav entry:
1923 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251924 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271925 (controller_.GetLastCommittedEntry() ||
1926 render_manager_.pending_web_ui()))
1927 return render_manager_.pending_web_ui();
1928 return render_manager_.web_ui();
1929}
1930
[email protected]b172aee2012-04-10 17:05:261931bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271932 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581933 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271934}
1935
[email protected]b172aee2012-04-10 17:05:261936bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441937 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501938}
1939
[email protected]b172aee2012-04-10 17:05:261940void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321941 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181942 Send(new ViewMsg_DidChooseColorResponse(
1943 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201944}
1945
[email protected]b172aee2012-04-10 17:05:261946void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181947 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201948 if (delegate_)
1949 delegate_->DidEndColorChooser();
1950 color_chooser_ = NULL;
1951}
1952
[email protected]795c28972012-12-06 06:13:391953int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
1954 const FaviconDownloadCallback& callback) {
1955 RenderViewHost* host = GetRenderViewHost();
1956 int id = StartDownload(host, url, image_size);
1957 favicon_download_map_[id] = callback;
1958 return id;
1959}
1960
[email protected]b172aee2012-04-10 17:05:261961bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211962 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271963 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221964 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231965 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411966 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271967}
1968
[email protected]b172aee2012-04-10 17:05:261969void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271970 if (delegate_)
1971 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211972}
1973
[email protected]3a3b75a2012-06-01 08:38:361974void WebContentsImpl::OnRegisterIntentService(
1975 const webkit_glue::WebIntentServiceData& data,
1976 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431977 if (delegate_)
1978 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301979}
1980
[email protected]b172aee2012-04-10 17:05:261981void WebContentsImpl::OnWebIntentDispatch(
1982 const webkit_glue::WebIntentData& intent,
1983 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431984 if (!delegate_)
1985 return;
1986
[email protected]0d9989d2011-12-21 20:26:001987 WebIntentsDispatcherImpl* intents_dispatcher =
1988 new WebIntentsDispatcherImpl(this, intent, intent_id);
1989 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301990}
1991
[email protected]54047eb52012-05-08 21:45:571992void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211993 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571994 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131995 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571996 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:571997 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211998 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]ead9009e2013-01-07 22:06:321999 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182000 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212001 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572002 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082003 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182004
[email protected]d974a0a2013-01-10 01:43:572005 if (is_main_frame)
2006 DidChangeLoadProgress(0);
2007
[email protected]0d60f0192011-04-14 12:40:102008 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132010 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2011 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322012 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542013
2014 if (is_main_frame) {
2015 // Notify observers about the provisional change in the main frame URL.
2016 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2017 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542018 render_view_host));
2019 }
2020}
2021
2022void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212023 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542024 int32 page_id,
[email protected]400992b2012-06-14 00:03:542025 const GURL& source_url,
2026 const GURL& target_url) {
2027 // TODO(creis): Remove this method and have the pre-rendering code listen to
2028 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2029 // instead. See http://crbug.com/78512.
2030 GURL validated_source_url(source_url);
2031 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212032 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542033 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082034 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2035 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542036 NavigationEntry* entry;
2037 if (page_id == -1) {
2038 entry = controller_.GetPendingEntry();
2039 } else {
2040 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2041 page_id);
2042 }
2043 if (!entry || entry->GetURL() != validated_source_url)
2044 return;
2045
2046 // Notify observers about the provisional change in the main frame URL.
2047 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2048 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542049 render_view_host));
[email protected]724159a2010-12-30 01:11:182050}
2051
[email protected]54047eb52012-05-08 21:45:572052void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212053 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582054 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2055 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2056 << ", error_code: " << params.error_code
2057 << ", error_description: " << params.error_description
2058 << ", is_main_frame: " << params.is_main_frame
2059 << ", showing_repost_interstitial: " <<
2060 params.showing_repost_interstitial
2061 << ", frame_id: " << params.frame_id;
2062 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212063 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572064 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082065 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182066
[email protected]d7b175e2011-10-11 15:31:582067 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182068 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2069 // This means that the interstitial won't be torn down properly, which is
2070 // bad. But if we have an interstitial, go back to another tab type, and
2071 // then load the same interstitial again, we could end up getting the first
2072 // interstitial's "failed" message (as a result of the cancel) when we're on
2073 // the second one.
2074 //
2075 // We can't tell this apart, so we think we're tearing down the current page
2076 // which will cause a crash later one. There is also some code in
2077 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2078 // out because of this problem.
2079 //
2080 // http://code.google.com/p/chromium/issues/detail?id=2855
2081 // Because this will not tear down the interstitial properly, if "back" is
2082 // back to another tab type, the interstitial will still be somewhat alive
2083 // in the previous tab type. If you navigate somewhere that activates the
2084 // tab with the interstitial again, you'll see a flash before the new load
2085 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272086 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182087 LOG(WARNING) << "Discarding message during interstitial.";
2088 return;
2089 }
2090
[email protected]a16690732012-07-13 19:22:172091 // Do not clear the pending entry if one exists, so that the user's typed
2092 // URL is not lost when a navigation fails or is aborted. We'll allow
2093 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182094
[email protected]54047eb52012-05-08 21:45:572095 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182096 }
2097
[email protected]d8c660432011-12-22 20:51:252098 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582099 observers_,
2100 DidFailProvisionalLoad(params.frame_id,
2101 params.is_main_frame,
2102 validated_url,
2103 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462104 params.error_description,
2105 render_view_host));
[email protected]724159a2010-12-30 01:11:182106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182109 const GURL& url,
[email protected]70435962011-08-02 20:13:282110 const std::string& security_info,
2111 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182112 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282113 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192114 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182115 cache.Increment();
2116
2117 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082118 int cert_id = 0;
2119 net::CertStatus cert_status = 0;
2120 int security_bits = -1;
2121 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212122 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2123 &security_bits, &connection_status);
2124 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002125 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2126 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182127
[email protected]8ff00d72012-10-23 19:12:212128 NotificationService::current()->Notify(
2129 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2130 Source<NavigationController>(&controller_),
2131 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182132}
2133
[email protected]b172aee2012-04-10 17:05:262134void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212135 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182136 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192137 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022141 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232142 LOG(INFO) << security_origin << " ran insecure content from "
2143 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212144 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412145 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212146 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182147 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412148 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192149 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182150}
2151
[email protected]b172aee2012-04-10 17:05:262152void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182153 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252154 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472155 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182156}
2157
[email protected]b172aee2012-04-10 17:05:262158void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312159 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062160 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312161 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062162 GURL validated_url(url);
2163 RenderProcessHost* render_process_host = message_source_->GetProcess();
2164 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472166 DidFinishLoad(frame_id, validated_url, is_main_frame,
2167 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312168}
2169
[email protected]b172aee2012-04-10 17:05:262170void WebContentsImpl::OnDidFailLoadWithError(
2171 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062172 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262173 bool is_main_frame,
2174 int error_code,
2175 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062176 GURL validated_url(url);
2177 RenderProcessHost* render_process_host = message_source_->GetProcess();
2178 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252179 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312180 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472181 error_code, error_description,
2182 message_source_));
[email protected]724159a2010-12-30 01:11:182183}
2184
[email protected]b172aee2012-04-10 17:05:262185void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272186 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432187 if (delegate_)
2188 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172189}
2190
[email protected]b172aee2012-04-10 17:05:262191void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262192 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232193 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252194 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262195 if (!entry)
2196 return;
2197 // Note that we don't call NavigationController::GotToOffset() as we don't
2198 // want to create a pending navigation entry (it might end up lingering
2199 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252200 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212201 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512202 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212203 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472204 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572205
2206 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2207 // it in now that we know. This allows us to find the entry when it commits.
2208 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232209 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332210 entry->set_site_instance(
2211 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572212 }
[email protected]216813952011-05-19 22:21:262213 }
2214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2217 int maximum_percent,
2218 bool remember) {
[email protected]216813952011-05-19 22:21:262219 minimum_zoom_percent_ = minimum_percent;
2220 maximum_zoom_percent_ = maximum_percent;
2221 temporary_zoom_settings_ = !remember;
2222}
2223
[email protected]20b433a2012-05-15 21:23:462224void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212225 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552226 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262227 // Check if the URL to save matches the URL of the main frame. Since this
2228 // message originates from Pepper plugins, it may not be the case if the
2229 // plugin is an embedded element.
2230 GURL main_frame_url = GetURL();
2231 if (!main_frame_url.is_valid())
2232 return;
2233 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462234 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272235}
2236
[email protected]b172aee2012-04-10 17:05:262237void WebContentsImpl::OnEnumerateDirectory(int request_id,
2238 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432239 if (!delegate_)
2240 return;
2241
[email protected]b9535422012-02-09 01:47:592242 ChildProcessSecurityPolicyImpl* policy =
2243 ChildProcessSecurityPolicyImpl::GetInstance();
2244 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2245 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212246}
2247
[email protected]b172aee2012-04-10 17:05:262248void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432249 if (delegate_)
2250 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2254 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362255 const string16& title,
2256 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432257 if (!delegate_)
2258 return;
2259
[email protected]b9535422012-02-09 01:47:592260 ChildProcessSecurityPolicyImpl* policy =
2261 ChildProcessSecurityPolicyImpl::GetInstance();
2262 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2263 return;
[email protected]3a3b75a2012-06-01 08:38:362264 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202265}
2266
[email protected]b172aee2012-04-10 17:05:262267void WebContentsImpl::OnFindReply(int request_id,
2268 int number_of_matches,
2269 const gfx::Rect& selection_rect,
2270 int active_match_ordinal,
2271 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432272 if (delegate_) {
2273 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2274 active_match_ordinal, final_update);
2275 }
[email protected]b888919c2011-09-02 00:32:162276}
2277
[email protected]59363fc92012-09-05 03:46:312278#if defined(OS_ANDROID)
2279void WebContentsImpl::OnFindMatchRectsReply(
2280 int version,
2281 const std::vector<gfx::RectF>& rects,
2282 const gfx::RectF& active_rect) {
2283 if (delegate_)
2284 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2285}
[email protected]583418cc2013-01-17 14:01:102286
2287void WebContentsImpl::OnOpenDateTimeDialog(int type, const std::string& value) {
2288 date_time_chooser_->ShowDialog(
2289 GetContentNativeView(), GetRenderViewHost(), type, value);
2290}
2291
[email protected]59363fc92012-09-05 03:46:312292#endif
2293
[email protected]cf4d6e742013-01-10 14:06:422294void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path,
2295 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442296 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422297 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452298}
2299
[email protected]b172aee2012-04-10 17:05:262300void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2301 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102302 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252303 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102304 AppCacheAccessed(manifest_url, blocked_by_policy));
2305}
2306
[email protected]b172aee2012-04-10 17:05:262307void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322308 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432309 color_chooser_ = delegate_ ?
2310 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202314 if (color_chooser_ &&
2315 color_chooser_id == color_chooser_->identifier())
2316 color_chooser_->End();
2317}
2318
[email protected]b172aee2012-04-10 17:05:262319void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322320 SkColor color) {
[email protected]da8543762012-03-20 08:52:202321 if (color_chooser_ &&
2322 color_chooser_id == color_chooser_->identifier())
2323 color_chooser_->SetSelectedColor(color);
2324}
2325
[email protected]9f2a9d72012-04-16 16:02:222326void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2327 const FilePath& path,
2328 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552329 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2330
[email protected]3fc07c52012-04-20 00:27:442331 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2332 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292333}
2334
[email protected]d0759f492012-04-19 22:50:502335// This exists for render views that don't have a WebUI, but do have WebUI
2336// bindings enabled.
2337void WebContentsImpl::OnWebUISend(const GURL& source_url,
2338 const std::string& name,
2339 const base::ListValue& args) {
2340 if (delegate_)
2341 delegate_->WebUISend(this, source_url, name, args);
2342}
2343
[email protected]d8415ad92012-08-23 14:40:502344void WebContentsImpl::OnRequestPpapiBrokerPermission(
2345 int request_id,
2346 const GURL& url,
2347 const FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162348 if (!delegate_) {
2349 OnPpapiBrokerPermissionResult(request_id, false);
2350 return;
[email protected]d8415ad92012-08-23 14:40:502351 }
2352
[email protected]8c8fc292012-11-23 18:57:162353 if (!delegate_->RequestPpapiBrokerPermission(
2354 this, url, plugin_path,
2355 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2356 base::Unretained(this), request_id))) {
2357 NOTIMPLEMENTED();
2358 OnPpapiBrokerPermissionResult(request_id, false);
2359 }
[email protected]d8415ad92012-08-23 14:40:502360}
2361
2362void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2363 bool result) {
2364 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2365 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2366 request_id,
2367 result));
2368}
2369
[email protected]19be7a62012-10-01 23:03:372370void WebContentsImpl::OnBrowserPluginCreateGuest(
[email protected]92a01cc2012-09-29 14:13:592371 int instance_id,
[email protected]dd8c8232012-11-03 00:49:362372 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]19be7a62012-10-01 23:03:372373 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
2374 // specific messages for this WebContents (through its
2375 // BrowserPluginEmbedderHelper). This means that any message from browser
2376 // plugin renderer prior to CreateGuest will be ignored.
[email protected]7a846df2012-09-20 19:17:392377 // For more info, see comment above classes BrowserPluginEmbedder and
2378 // BrowserPluginGuest.
[email protected]b6bcd8c2012-10-03 06:03:582379 // The first BrowserPluginHostMsg_CreateGuest message from this WebContents'
2380 // embedder render process is handled here. Once BrowserPluginEmbedder is
2381 // created, all subsequent BrowserPluginHostMsg_CreateGuest messages are
2382 // intercepted by the BrowserPluginEmbedderHelper and handled by the
2383 // BrowserPluginEmbedder. Thus, this code will not be executed if a
2384 // BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392385 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392386 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212387 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]3997b1b22012-12-20 01:02:542388 BrowserPluginHostMsg_CreateGuest create_guest_msg(
2389 GetRenderViewHost()->GetRoutingID(), instance_id, params);
2390 browser_plugin_embedder_->OnMessageReceived(create_guest_msg);
[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]818915cd2012-11-20 13:14:112417void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
2418 ThreeDAPIType requester) {
2419 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2420 DidBlock3DAPIs(url, requester));
2421}
2422
[email protected]96d185d2009-04-24 03:28:542423// Notifies the RenderWidgetHost instance about the fact that the page is
2424// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262425void WebContentsImpl::SetIsLoading(bool is_loading,
2426 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542427 if (is_loading == is_loading_)
2428 return;
2429
2430 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212431 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542432 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562433 upload_size_ = 0;
2434 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542435 }
2436
2437 render_manager_.SetIsLoading(is_loading);
2438
2439 is_loading_ = is_loading;
2440 waiting_for_response_ = is_loading;
2441
[email protected]6ebdc9b2010-09-27 16:55:572442 if (delegate_)
2443 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212444 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542445
[email protected]8ff00d72012-10-23 19:12:212446 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2447 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542448 if (details)
[email protected]8ff00d72012-10-23 19:12:212449 det = Details<LoadNotificationDetails>(details);
2450 NotificationService::current()->Notify(
2451 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542452}
2453
[email protected]b172aee2012-04-10 17:05:262454void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212455 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322456 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562457 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382458 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442459 // that opened the window, as long as both renderers have the same
2460 // privileges.
[email protected]1fd1a502011-03-30 16:55:562461 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562462 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582463 // web_ui might be NULL if the URL refers to a non-existent extension.
2464 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402465 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522466 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442467 }
2468 }
[email protected]1fd1a502011-03-30 16:55:562469 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442470 }
2471
[email protected]4e697b042011-07-08 06:44:562472 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322473 // Clear the status bubble. This is a workaround for a bug where WebKit
2474 // doesn't let us know that the cursor left an element during a
2475 // transition (this is also why the mouse cursor remains as a hand after
2476 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2477 // clear the bubble when a user navigates to a named anchor in the same
2478 // page.
[email protected]36fc0392011-12-25 03:59:512479 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322480 }
2481
[email protected]a6e82fc2010-02-24 22:28:142482 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472483 // Once the main frame is navigated, we're no longer considered to have
2484 // displayed insecure content.
2485 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172486 }
[email protected]ce5c4502009-05-06 16:46:112487
[email protected]3c9e1872010-11-18 16:17:492488 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042490 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322491}
2492
[email protected]b172aee2012-04-10 17:05:262493void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322494 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212495 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322496 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062497 // If we navigate off the page, reset JavaScript state. This does nothing
2498 // to prevent a malicious script from spamming messages, since the script
2499 // could just reload the page to stop blocking.
2500 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552501 dialog_creator_->ResetJavaScriptState(this);
2502 dialog_creator_ = NULL;
2503 }
[email protected]420ae012009-04-24 05:16:322504
[email protected]3c9e1872010-11-18 16:17:492505 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252506 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042507 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322508}
2509
[email protected]b172aee2012-04-10 17:05:262510void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462511 // If we are creating a RVH for a restored controller, then we need to make
2512 // sure the RenderView starts with a next_page_id_ larger than the number
2513 // of restored entries. This must be called before the RenderView starts
2514 // navigating (to avoid a race between the browser updating max_page_id and
2515 // the renderer updating next_page_id_). Because of this, we only call this
2516 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562517 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582518 if (max_restored_page_id >
2519 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2520 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2521 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322522}
2523
[email protected]b172aee2012-04-10 17:05:262524bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2525 const string16& title) {
[email protected]420ae012009-04-24 05:16:322526 // For file URLs without a title, use the pathname instead. In the case of a
2527 // synthesized title, we don't want the update to count toward the "one set
2528 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512529 string16 final_title;
[email protected]420ae012009-04-24 05:16:322530 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512531 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2532 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322533 explicit_set = false; // Don't count synthetic titles toward the set limit.
2534 } else {
[email protected]acafd272011-07-26 17:35:572535 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322536 explicit_set = true;
2537 }
2538
[email protected]987fc3a2011-05-26 14:18:092539 // If a page is created via window.open and never navigated,
2540 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552541 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092542 if (entry) {
[email protected]36fc0392011-12-25 03:59:512543 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092544 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322545
[email protected]36fc0392011-12-25 03:59:512546 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092547 } else {
2548 if (page_title_when_no_navigation_entry_ == final_title)
2549 return false; // Nothing changed, don't bother.
2550
2551 page_title_when_no_navigation_entry_ = final_title;
2552 }
[email protected]420ae012009-04-24 05:16:322553
[email protected]420ae012009-04-24 05:16:322554 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232555 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322556
[email protected]8ff00d72012-10-23 19:12:212557 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462558 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142559
[email protected]8ff00d72012-10-23 19:12:212560 NotificationService::current()->Notify(
2561 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2562 Source<WebContents>(this),
2563 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042564
[email protected]420ae012009-04-24 05:16:322565 return true;
2566}
2567
[email protected]35e0e0792012-11-30 02:35:482568void WebContentsImpl::NotifySwapped(RenderViewHost* old_render_view_host) {
[email protected]420ae012009-04-24 05:16:322569 // After sending out a swap notification, we need to send a disconnect
2570 // notification so that clients that pick up a pointer to |this| can NULL the
2571 // pointer. See Bug 1230284.
2572 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212573 NotificationService::current()->Notify(
2574 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2575 Source<WebContents>(this),
[email protected]35e0e0792012-11-30 02:35:482576 Details<RenderViewHost>(old_render_view_host));
[email protected]7a846df2012-09-20 19:17:392577
2578 // Ensure that the associated embedder gets cleared after a RenderViewHost
2579 // gets swapped, so we don't reuse the same embedder next time a
2580 // RenderViewHost is attached to this WebContents.
2581 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322582}
2583
[email protected]b172aee2012-04-10 17:05:262584void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322585 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212586 NotificationService::current()->Notify(
2587 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2588 Source<WebContents>(this),
2589 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322590}
2591
[email protected]b172aee2012-04-10 17:05:262592void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322593 if (!notify_disconnection_)
2594 return;
2595
2596 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212597 NotificationService::current()->Notify(
2598 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2599 Source<WebContents>(this),
2600 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322601}
2602
[email protected]5a3bdf52012-05-24 15:12:572603RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2604 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322605}
2606
[email protected]8d3347f2009-07-09 22:00:212607RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262608WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212609 return &render_manager_;
2610}
2611
[email protected]8ff00d72012-10-23 19:12:212612RendererPreferences WebContentsImpl::GetRendererPrefs(
2613 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462614 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512615}
2616
[email protected]b172aee2012-04-10 17:05:262617WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172618 return this;
2619}
2620
[email protected]b172aee2012-04-10 17:05:262621gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172622 if (delegate_)
2623 return delegate_->GetRootWindowResizerRect();
2624 return gfx::Rect();
2625}
2626
[email protected]7a846df2012-09-20 19:17:392627void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2628 if (browser_plugin_embedder_.get())
2629 browser_plugin_embedder_.reset();
2630}
2631
[email protected]b172aee2012-04-10 17:05:262632void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442633 // Don't send notifications if we are just creating a swapped-out RVH for
2634 // the opener chain. These won't be used for view-source or WebUI, so it's
2635 // ok to return early.
2636 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2637 return;
2638
[email protected]8ff00d72012-10-23 19:12:212639 NotificationService::current()->Notify(
2640 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2641 Source<WebContents>(this),
2642 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232643 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322644 if (!entry)
2645 return;
2646
2647 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352648 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562649 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582650 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322651
2652 if (entry->IsViewSourceMode()) {
2653 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182654 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582655 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322656 }
[email protected]0666aef2009-05-13 19:48:082657
[email protected]d487beefe2011-12-21 05:41:212658 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262659
2660 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252661 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322662}
2663
[email protected]b172aee2012-04-10 17:05:262664void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522665 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322666 // Don't notify the world, since this came from a renderer in the
2667 // background.
2668 return;
2669 }
2670
2671 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312672 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232673 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302674
2675 // Restore the focus to the tab (otherwise the focus will be on the top
2676 // window).
[email protected]484ae5912010-09-29 19:16:142677 if (was_crashed && !FocusLocationBarByDefault() &&
2678 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302679 Focus();
[email protected]484ae5912010-09-29 19:16:142680 }
[email protected]32ded2212011-11-10 18:51:432681
[email protected]d8c660432011-12-22 20:51:252682 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322683}
2684
[email protected]b172aee2012-04-10 17:05:262685void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2686 base::TerminationStatus status,
2687 int error_code) {
[email protected]151a63d2011-12-20 22:32:522688 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322689 // The pending page's RenderViewHost is gone.
2690 return;
2691 }
2692
2693 SetIsLoading(false, NULL);
2694 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232695 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312696 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322697
[email protected]d8c660432011-12-22 20:51:252698 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272699 observers_,
[email protected]be1f56ab2011-12-22 06:55:312700 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322701}
2702
[email protected]b172aee2012-04-10 17:05:262703void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482704 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252705 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062706}
2707
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::DidNavigate(
2709 RenderViewHost* rvh,
2710 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e3d92a7f2013-01-10 02:35:052711 if (PageTransitionIsMainFrame(params.transition)) {
2712 // When overscroll navigation gesture is enabled, a screenshot of the page
2713 // in its current state is taken so that it can be used during the
2714 // nav-gesture. It is necessary to take the screenshot here, before calling
2715 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2716 // WebContents::GetRenderViewHost to return the new host, instead of the one
2717 // that may have just been swapped out.
2718 controller_.TakeScreenshot();
2719
[email protected]420ae012009-04-24 05:16:322720 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052721 }
[email protected]8030f012009-09-25 18:09:372722
[email protected]434f69f2012-02-06 21:56:522723 // Update the site of the SiteInstance if it doesn't have one yet, unless
2724 // this is for about:blank. In that case, the SiteInstance can still be
2725 // considered unused until a navigation to a real page.
2726 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2727 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332728 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522729 }
[email protected]420ae012009-04-24 05:16:322730
2731 // Need to update MIME type here because it's referred to in
2732 // UpdateNavigationCommands() called by RendererDidNavigate() to
2733 // determine whether or not to enable the encoding menu.
2734 // It's updated only for the main frame. For a subframe,
2735 // RenderView::UpdateURL does not set params.contents_mime_type.
2736 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2737 // TODO(jungshik): Add a test for the encoding menu to avoid
2738 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212739 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322740 contents_mime_type_ = params.contents_mime_type;
2741
[email protected]8ff00d72012-10-23 19:12:212742 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002743 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392744
[email protected]a9c0bfe2010-09-17 08:35:222745 // Send notification about committed provisional loads. This notification is
2746 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2747 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212748 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072749 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2750 // that is not recorded in the navigation history. For the purpose of
2751 // tracking navigation events, we treat this event as a sub frame navigation
2752 // event.
2753 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212754 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222755 // Whether or not a page transition was triggered by going backward or
2756 // forward in the history is only stored in the navigation controller's
2757 // entry list.
2758 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512759 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212760 PAGE_TRANSITION_FORWARD_BACK)) {
2761 transition_type = PageTransitionFromInt(
2762 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222763 }
[email protected]0d60f0192011-04-14 12:40:102764 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252765 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102766 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462767 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222768 }
2769
[email protected]76543b92009-08-31 17:27:452770 if (!did_navigate)
2771 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322772
2773 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2774 // for the appropriate notification (best) or you can add it to
2775 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2776 // necessary, please).
2777
2778 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002779 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322780 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512781 if (delegate_)
2782 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002783 }
[email protected]420ae012009-04-24 05:16:322784 DidNavigateAnyFramePostCommit(rvh, details, params);
2785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2788 int32 page_id,
2789 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152790 // Ensure that this state update comes from either the active RVH or one of
2791 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522792 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322793
2794 // We must be prepared to handle state updates for any page, these occur
2795 // when the user is scrolling and entering form data, as well as when we're
2796 // leaving a page, in which case our state may have already been moved to
2797 // the next page. The navigation controller will look up the appropriate
2798 // NavigationEntry and update it when it is notified via the delegate.
2799
2800 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582801 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322802 if (entry_index < 0)
2803 return;
[email protected]10f417c52011-12-28 21:04:232804 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322805
[email protected]36fc0392011-12-25 03:59:512806 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322807 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512808 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322809 controller_.NotifyEntryChanged(entry, entry_index);
2810}
2811
[email protected]b172aee2012-04-10 17:05:262812void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2813 int32 page_id,
2814 const string16& title,
2815 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322816 // If we have a title, that's a pretty good indication that we've started
2817 // getting useful data.
2818 SetNotWaitingForResponse();
2819
[email protected]73eb2602012-02-09 19:50:552820 // Try to find the navigation entry, which might not be the current one.
2821 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232822 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582823 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092824
[email protected]73eb2602012-02-09 19:50:552825 // We can handle title updates when we don't have an entry in
2826 // UpdateTitleForEntry, but only if the update is from the current RVH.
2827 if (!entry && rvh != GetRenderViewHost())
2828 return;
2829
[email protected]a49e10b2011-08-01 23:57:462830 // TODO(evan): make use of title_direction.
2831 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092832 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322833 return;
2834
2835 // Broadcast notifications when the UI should be updated.
2836 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212837 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322838}
2839
[email protected]b172aee2012-04-10 17:05:262840void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2841 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312842 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512846 if (delegate_)
2847 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322848}
2849
[email protected]b172aee2012-04-10 17:05:262850void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292851 // The UI may be in an event-tracking loop, such as between the
2852 // mouse-down and mouse-up in text selection or a button click.
2853 // Defer the close until after tracking is complete, so that we
2854 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292855 // TODO(shess): This could get more fine-grained. For instance,
2856 // closing a tab in another window while selecting text in the
2857 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212858 if (GetView()->IsEventTracking()) {
2859 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292860 return;
2861 }
2862
[email protected]420ae012009-04-24 05:16:322863 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522864 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512865 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322866}
2867
[email protected]b172aee2012-04-10 17:05:262868void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522869 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512870 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512874 if (delegate_ && delegate_->IsPopupOrPanel(this))
2875 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322876}
2877
[email protected]8ff00d72012-10-23 19:12:212878void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322879 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492880
[email protected]82114f52012-03-20 22:53:412881 if (delegate_ && content_restrictions_)
2882 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492883
2884 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2886 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322887}
2888
[email protected]8ff00d72012-10-23 19:12:212889void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322890 scoped_ptr<LoadNotificationDetails> details;
2891
[email protected]10f417c52011-12-28 21:04:232892 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322893 // An entry may not exist for a stop when loading an initial blank page or
2894 // if an iframe injected by script into a blank page finishes loading.
2895 if (entry) {
[email protected]420ae012009-04-24 05:16:322896 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2897
2898 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512899 entry->GetVirtualURL(),
2900 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322901 elapsed,
2902 &controller_,
2903 controller_.GetCurrentEntryIndex()));
2904 }
2905
[email protected]420ae012009-04-24 05:16:322906 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492907
2908 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292909 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2910 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]b172aee2012-04-10 17:05:262913void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162914 controller_.DiscardNonCommittedEntries();
2915
2916 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212917 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162918}
2919
[email protected]b172aee2012-04-10 17:05:262920void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262921#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512922 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132923 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262924#endif
[email protected]1a3c3cb2010-12-16 21:03:402925}
2926
[email protected]7cc78902012-12-06 02:32:262927void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2928 // Clear our opener so that future cross-process navigations don't have an
2929 // opener assigned.
2930 opener_ = NULL;
2931
2932 // Notify all swapped out RenderViewHosts for this tab. This is important
2933 // in case we go back to them, or if another window in those processes tries
2934 // to access window.opener.
2935 render_manager_.DidDisownOpener(rvh);
2936}
2937
[email protected]0720b532012-08-28 19:23:372938void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2939 render_manager_.DidUpdateFrameTree(rvh);
2940}
2941
[email protected]87717d0e2012-04-26 02:58:432942void WebContentsImpl::DocumentAvailableInMainFrame(
2943 RenderViewHost* render_view_host) {
2944 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2945 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102946}
2947
[email protected]b172aee2012-04-10 17:05:262948void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082949 RenderViewHost* render_view_host,
2950 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212951 NotificationService::current()->Notify(
2952 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2953 Source<WebContents>(this),
2954 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082955}
2956
[email protected]196159d2012-05-04 17:26:542957void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2958 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212959 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262960 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:182961 int64 source_frame_id,
2962 bool is_cross_site_redirect) {
[email protected]196159d2012-05-04 17:26:542963 // If this came from a swapped out RenderViewHost, we only allow the request
2964 // if we are still in the same BrowsingInstance.
2965 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2966 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2967 return;
2968 }
2969
[email protected]4ad5d77d2011-12-03 02:00:482970 // Delegate to RequestTransferURL because this is just the generic
2971 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582972 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]e2caa032012-11-15 23:29:182973 GlobalRequestID(), is_cross_site_redirect);
[email protected]4ad5d77d2011-12-03 02:00:482974}
2975
[email protected]b172aee2012-04-10 17:05:262976void WebContentsImpl::RequestTransferURL(
2977 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212978 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262979 WindowOpenDisposition disposition,
2980 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:182981 const GlobalRequestID& old_request_id,
2982 bool is_cross_site_redirect) {
[email protected]e5d549d2011-12-28 01:29:202983 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212984 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582985 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352986 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322987 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2988 // generated suggestions).
2989 //
[email protected]e0112912011-02-02 22:54:352990 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162991 // want web sites to see a referrer of "chrome://blah" (and some
2992 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322993 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:212994 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222995 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482996 false /* is_renderer_initiated */);
2997 params.transferred_global_request_id = old_request_id;
2998 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222999 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:323000 } else {
[email protected]6bf6a6b52012-02-03 15:41:433001 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:213002 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:483003 params.transferred_global_request_id = old_request_id;
[email protected]e2caa032012-11-15 23:29:183004 params.is_cross_site_redirect = is_cross_site_redirect;
[email protected]4ad5d77d2011-12-03 02:00:483005 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:583006 }
3007 if (new_contents) {
3008 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583010 DidOpenRequestedURL(new_contents,
3011 url,
3012 referrer,
3013 disposition,
3014 transition_type,
3015 source_frame_id));
[email protected]420ae012009-04-24 05:16:323016 }
3017}
3018
[email protected]e1c3a552012-05-04 20:51:323019void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3020 // Tell the active RenderViewHost to run unload handlers and close, as long
3021 // as the request came from a RenderViewHost in the same BrowsingInstance.
3022 // In most cases, we receive this from a swapped out RenderViewHost.
3023 // It is possible to receive it from one that has just been swapped in,
3024 // in which case we might as well deliver the message anyway.
3025 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3026 GetRenderViewHost()->ClosePage();
3027}
3028
[email protected]f546640b2012-05-15 00:03:493029void WebContentsImpl::RouteMessageEvent(
3030 RenderViewHost* rvh,
3031 const ViewMsg_PostMessage_Params& params) {
3032 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363033 // came from a RenderViewHost in the same BrowsingInstance or if this
3034 // WebContents is dedicated to a browser plugin guest.
3035 // Note: This check means that an embedder could theoretically receive a
3036 // postMessage from anyone (not just its own guests). However, this is
3037 // probably not a risk for apps since other pages won't have references
3038 // to App windows.
3039 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3040 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493041 return;
3042
3043 ViewMsg_PostMessage_Params new_params(params);
3044
[email protected]0720b532012-08-28 19:23:373045 // If the renderer has changed while the post message is being routed,
3046 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:193047 // TODO(nasko): Check for process ID and target frame id mismatch, once
3048 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:373049
[email protected]f546640b2012-05-15 00:03:493050 // If there is a source_routing_id, translate it to the routing ID for
3051 // the equivalent swapped out RVH in the target process. If we need
3052 // to create a swapped out RVH for the source tab, we create its opener
3053 // chain as well, since those will also be accessible to the target page.
3054 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3055 // Try to look up the WebContents for the source page.
3056 WebContentsImpl* source_contents = NULL;
3057 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3058 rvh->GetProcess()->GetID(), params.source_routing_id);
3059 if (source_rvh) {
3060 source_contents = static_cast<WebContentsImpl*>(
3061 source_rvh->GetDelegate()->GetAsWebContents());
3062 }
3063
3064 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363065 if (GetBrowserPluginGuest()) {
3066 // We create a swapped out RenderView for the embedder in the guest's
3067 // render process but we intentionally do not expose the embedder's
3068 // opener chain to it.
3069 new_params.source_routing_id =
3070 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3071 } else {
3072 new_params.source_routing_id =
3073 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3074 }
[email protected]f546640b2012-05-15 00:03:493075 } else {
3076 // We couldn't find it, so don't pass a source frame.
3077 new_params.source_routing_id = MSG_ROUTING_NONE;
3078 }
3079 }
3080
3081 // In most cases, we receive this from a swapped out RenderViewHost.
3082 // It is possible to receive it from one that has just been swapped in,
3083 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183084 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493085}
3086
[email protected]b172aee2012-04-10 17:05:263087void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343088 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413089 const string16& message,
3090 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323091 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213092 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323093 IPC::Message* reply_msg,
3094 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073095 // Suppress JavaScript dialogs when requested. Also suppress messages when
3096 // showing an interstitial as it's shown over the previous page and we don't
3097 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503098 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583099 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273100 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073101 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523102 delegate_->ShouldSuppressDialogs() ||
3103 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323104
3105 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213106 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433107 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553108 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523109 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433110 this,
3111 frame_url.GetOrigin(),
3112 accept_lang,
3113 javascript_message_type,
3114 message,
[email protected]51da7e32012-01-30 19:24:523115 default_prompt,
[email protected]b172aee2012-04-10 17:05:263116 base::Bind(&WebContentsImpl::OnDialogClosed,
3117 base::Unretained(this),
3118 rvh,
3119 reply_msg),
[email protected]51da7e32012-01-30 19:24:523120 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323121 }
[email protected]3ab9cb82011-06-03 18:02:073122
3123 if (suppress_this_message) {
3124 // If we are suppressing messages, just reply as if the user immediately
3125 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343126 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073127 }
3128
3129 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323130}
3131
[email protected]b172aee2012-04-10 17:05:263132void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3133 const string16& message,
3134 bool is_reload,
3135 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583136 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513137 if (delegate_)
3138 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073139
3140 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583141 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073142 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523143 delegate_->ShouldSuppressDialogs() ||
3144 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153145 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343146 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583147 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503148 return;
3149 }
[email protected]3ab9cb82011-06-03 18:02:073150
[email protected]7ab1e7d62009-10-14 23:32:013151 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553152 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523153 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323154 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263155 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523156 reply_msg));
[email protected]420ae012009-04-24 05:16:323157}
3158
[email protected]a796f202012-05-30 14:14:253159bool WebContentsImpl::AddMessageToConsole(int32 level,
3160 const string16& message,
3161 int32 line_no,
3162 const string16& source_id) {
3163 if (!delegate_)
3164 return false;
3165 return delegate_->AddMessageToConsole(this, level, message, line_no,
3166 source_id);
3167}
3168
[email protected]b172aee2012-04-10 17:05:263169WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333170 // We want to base the page config off of the real URL, rather than the
3171 // display URL.
3172 GURL url = controller_.GetActiveEntry()
3173 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3174 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323175}
3176
[email protected]0eba810b2012-10-18 03:19:363177int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213178 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363179 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3180}
3181
[email protected]b172aee2012-04-10 17:05:263182void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273183 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253184 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223185
[email protected]ea114722012-03-12 01:11:253186 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173187 if (rdh) // NULL in unittests.
3188 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253189}
3190
[email protected]b172aee2012-04-10 17:05:263191void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443192 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253193 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443194}
3195
[email protected]b172aee2012-04-10 17:05:263196void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3197 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153198 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523199 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153200 return;
3201
[email protected]9f76c1e2012-03-05 15:15:583202 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3203
[email protected]e5fc1632011-08-08 07:51:533204 // Ignore renderer unresponsive event if debugger is attached to the tab
3205 // since the event may be a result of the renderer sitting on a breakpoint.
3206 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363207 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533208 return;
3209
[email protected]420ae012009-04-24 05:16:323210 if (is_during_unload) {
3211 // Hang occurred while firing the beforeunload/unload handler.
3212 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583213 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323214
3215 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3216 return;
3217
3218 // If the tab hangs in the beforeunload/unload handler there's really
3219 // nothing we can do to recover. Pretend the unload listeners have
3220 // all fired and close the tab. If the hang is in the beforeunload handler
3221 // then the user will not have the option of cancelling the close.
3222 Close(rvh);
3223 return;
3224 }
3225
[email protected]9f76c1e2012-03-05 15:15:583226 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473227 return;
3228
[email protected]6934a702011-12-20 00:04:513229 if (delegate_)
3230 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323231}
3232
[email protected]b172aee2012-04-10 17:05:263233void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513234 if (delegate_)
3235 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323236}
3237
[email protected]b172aee2012-04-10 17:05:263238void WebContentsImpl::LoadStateChanged(
3239 const GURL& url,
3240 const net::LoadStateWithParam& load_state,
3241 uint64 upload_position,
3242 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323243 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563244 upload_position_ = upload_position;
3245 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503246 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213247 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303248 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213249 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323250 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463251 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213252 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463253 }
[email protected]420ae012009-04-24 05:16:323254}
3255
[email protected]b172aee2012-04-10 17:05:263256void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513257 if (delegate_)
3258 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253259}
3260
[email protected]b172aee2012-04-10 17:05:263261void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553262 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323263 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553264 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513265 if (delegate_)
3266 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323267}
3268
[email protected]b172aee2012-04-10 17:05:263269void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543270 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233271 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3272 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543273}
3274
[email protected]b172aee2012-04-10 17:05:263275void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103276 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263277 gfx::Size size = view_->GetContainerSize();
3278 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3279 // here during container initialization and normal window size will be set
3280 // later. In case of tab duplication this resizing to 0x0 prevents setting
3281 // normal size later so just ignore it.
3282 if (!size.IsEmpty())
3283 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323284}
3285
[email protected]35e0e0792012-11-30 02:35:483286void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) {
3287 NotifySwapped(rvh);
[email protected]3a3d47472010-07-15 21:03:543288}
3289
[email protected]14392a52012-05-02 20:28:443290int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3291 SiteInstance* instance) {
3292 if (!opener_)
3293 return MSG_ROUTING_NONE;
3294
3295 // Recursively create RenderViews for anything else in the opener chain.
3296 return opener_->CreateOpenerRenderViews(instance);
3297}
3298
3299int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3300 int opener_route_id = MSG_ROUTING_NONE;
3301
3302 // If this tab has an opener, ensure it has a RenderView in the given
3303 // SiteInstance as well.
3304 if (opener_)
3305 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3306
[email protected]0720b532012-08-28 19:23:373307 // If any of the renderers for this WebContents has the same SiteInstance,
3308 // use it.
3309 if (render_manager_.current_host()->GetSiteInstance() == instance)
3310 return render_manager_.current_host()->GetRoutingID();
3311
3312 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3313 instance);
3314 if (rvh)
3315 return rvh->GetRoutingID();
3316
[email protected]14392a52012-05-02 20:28:443317 // Create a swapped out RenderView in the given SiteInstance if none exists,
3318 // setting its opener to the given route_id. Return the new view's route_id.
3319 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3320}
3321
[email protected]b172aee2012-04-10 17:05:263322NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193323 return GetController();
[email protected]3a3d47472010-07-15 21:03:543324}
3325
[email protected]b172aee2012-04-10 17:05:263326WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563327 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323328}
3329
[email protected]10f417c52011-12-28 21:04:233330NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263331 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323332 return controller_.GetLastCommittedEntry();
3333}
3334
[email protected]b172aee2012-04-10 17:05:263335bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443336 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443337 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323338 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523339
[email protected]420ae012009-04-24 05:16:323340 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443341 if (rwh_view)
3342 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323343
[email protected]74ce1ad2011-12-16 21:51:463344 // Make sure we use the correct starting page_id in the new RenderView.
3345 UpdateMaxPageIDIfNecessary(render_view_host);
3346 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583347 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463348
[email protected]9f76c1e2012-03-05 15:15:583349 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493350 render_view_host)->CreateRenderView(string16(),
3351 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133352 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523353 return false;
[email protected]14392a52012-05-02 20:28:443354 }
[email protected]a4127722011-04-27 23:13:523355
[email protected]e60c0232011-11-11 19:56:353356#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503357 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3358 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443359 if (rwh_view) {
3360 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3361 render_widget_host->WasResized();
3362 }
[email protected]f8233cc2011-05-31 20:24:503363#endif
3364
[email protected]420ae012009-04-24 05:16:323365 return true;
3366}
3367
[email protected]b172aee2012-04-10 17:05:263368void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3369 IPC::Message* reply_msg,
3370 bool success,
3371 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543372 if (is_showing_before_unload_dialog_ && !success) {
3373 // If a beforeunload dialog is canceled, we need to stop the throbber from
3374 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293375 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353376 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543377
[email protected]3bbacc5b2012-04-17 17:46:153378 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553379 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543380 }
3381 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583382 static_cast<RenderViewHostImpl*>(
3383 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543384}
3385
[email protected]b172aee2012-04-10 17:05:263386void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213387 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123388 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103389}
[email protected]f45d2a72010-03-08 23:28:353390
[email protected]b172aee2012-04-10 17:05:263391void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213392 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263393 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573394 DownloadManager* dlm =
3395 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143396 if (!dlm)
3397 return;
3398 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263399 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143400 const NavigationEntry* entry = controller_.GetActiveEntry();
3401 if (entry)
3402 post_id = entry->GetPostID();
3403 }
[email protected]c5a5c0842012-05-04 20:05:143404 scoped_ptr<DownloadUrlParameters> params(
[email protected]49d812e2012-11-06 21:18:123405 DownloadUrlParameters::FromWebContents(this, url));
[email protected]f859eba2012-05-30 17:22:493406 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143407 params->set_post_id(post_id);
3408 params->set_prefer_cache(true);
3409 if (post_id >= 0)
3410 params->set_method("POST");
[email protected]49d812e2012-11-06 21:18:123411 params->set_prompt(true);
[email protected]c5a5c0842012-05-04 20:05:143412 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143413}
3414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213416 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443417 // Can be NULL during tests.
3418 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213419 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363420}
[email protected]9f76c1e2012-03-05 15:15:583421
[email protected]b172aee2012-04-10 17:05:263422RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583423 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3424}
[email protected]7900bfdb2012-05-24 19:31:243425
[email protected]8ff00d72012-10-23 19:12:213426BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393427 return browser_plugin_guest_.get();
3428}
3429
[email protected]8ff00d72012-10-23 19:12:213430BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393431 return browser_plugin_embedder_.get();
3432}
[email protected]8ff00d72012-10-23 19:12:213433
3434} // namespace content