blob: 1bd9332c4c7839c4cde489ae6c9b6855fda8f06a [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]cc510d7e2012-08-08 04:40:1018#include "content/browser/browser_plugin/old/old_browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5919#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4420#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1921#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0422#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4623#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1224#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1625#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3226#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5427#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0528#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0029#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3030#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3231#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5032#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2533#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3334#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3735#include "content/browser/web_contents/interstitial_page_impl.h"
36#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5741#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5842#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1143#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2044#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4445#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4446#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1747#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1448#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4649#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1550#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0051#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2752#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0053#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3754#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1455#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3256#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3457#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3858#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4259#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2560#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1061#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5062#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2163#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4864#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1865#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5466#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0367#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1668#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2969#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5470#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3471#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3772#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5673#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1674#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4175#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0176#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4177#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5278#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2479#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3680#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3181#include "webkit/glue/webpreferences.h"
82
[email protected]f66df822012-05-18 16:52:1783#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5084#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4185#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5786#endif
[email protected]3e45ba92009-02-20 21:09:0087
[email protected]c71fe6402012-08-15 15:22:5588#if defined(USE_AURA) && defined(USE_X11)
89#include "ui/base/touch/touch_factory.h"
90#endif // defined (USE_AURA) && defined(USE_X11)
91
[email protected]420ae012009-04-24 05:16:3292// Cross-Site Navigations
93//
[email protected]b172aee2012-04-10 17:05:2694// If a WebContentsImpl is told to navigate to a different web site (as
95// determined by SiteInstance), it will replace its current RenderViewHost with
96// a new RenderViewHost dedicated to the new SiteInstance. This works as
97// follows:
[email protected]420ae012009-04-24 05:16:3298//
99// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46100// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32101// - The pending RVH is "suspended," so that no navigation messages are sent to
102// its renderer until the onbeforeunload JavaScript handler has a chance to
103// run in the current RVH.
104// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
105// that it has a pending cross-site request. ResourceDispatcherHost will
106// check for this when the response arrives.
107// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46108// cancel all the pending logic. Otherwise we allow the pending RVH to send
109// the navigation request to its renderer.
110// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
111// main resource load on the pending RVH. It checks CrossSiteRequestManager
112// to see that it is a cross-site request, and installs a
113// CrossSiteResourceHandler.
114// - When RDH receives a response, the BufferedResourceHandler determines
115// whether it is a download. If so, it sends a message to the new renderer
116// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26117// pending RVH remains until the next DidNavigate event for this
118// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32119// - After RDH receives a response and determines that it is safe and not a
120// download, it pauses the response to first run the old page's onunload
121// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26122// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32123// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15124// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32125// the ResourceDispatcherHost, who unpauses the response. Data is then sent
126// to the pending RVH.
127// - The pending renderer sends a FrameNavigate message that invokes the
128// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46129// pending RVH.
[email protected]992db4c2011-05-12 15:37:15130// - The previous renderer is kept swapped out in RenderViewHostManager in case
131// the user goes back. The process only stays live if another tab is using
132// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32133
[email protected]b441a8492012-06-06 14:55:57134using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44135using content::DevToolsAgentHost;
136using content::DevToolsAgentHostRegistry;
137using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17138using content::DownloadItem;
139using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14140using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20141using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56142using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13143using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27144using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54145using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50146using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23147using content::NavigationEntry;
148using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20149using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11150using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57151using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57152using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27153using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11154using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50155using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58156using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04157using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25158using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14159using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43160using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33161using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38162using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09163using content::WebContents;
[email protected]eda238a12012-09-07 23:44:00164using content::WebContentsDelegate;
[email protected]d8c660432011-12-22 20:51:25165using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56166using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22167using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50168using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25169using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44170
[email protected]420ae012009-04-24 05:16:32171namespace {
172
173// Amount of time we wait between when a key event is received and the renderer
174// is queried for its state and pushed to the NavigationEntry.
175const int kQueryStateDelay = 5000;
176
[email protected]6ebdc9b2010-09-27 16:55:57177const int kSyncWaitDelay = 40;
178
[email protected]82114f52012-03-20 22:53:41179const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05180
[email protected]420ae012009-04-24 05:16:32181#if defined(OS_WIN)
182
183BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
184 // Note: erase is required to properly paint some widgets borders. This can
185 // be seen with textfields.
186 InvalidateRect(hwnd, NULL, TRUE);
187 return TRUE;
188}
189#endif
190
[email protected]2c5569662011-03-22 20:45:02191ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23192 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50193 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16194 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47195 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47197 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23199 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
200 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47201 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16202 break; // Fall through to rest of function.
203 }
[email protected]5e369672009-11-03 23:48:30204
[email protected]59246c572012-02-10 13:32:13205 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
206 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23207 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13208 browser_context->DidLastSessionExitCleanly()) {
209 if (entry.GetHasPostData())
210 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02211 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13212 }
[email protected]5e369672009-11-03 23:48:30213
[email protected]2c5569662011-03-22 20:45:02214 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30215}
216
[email protected]10f417c52011-12-28 21:04:23217void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47218 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42219 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50220 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24221 const std::string& embedder_channel_name,
222 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16223 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51224 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54225 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55226 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
227 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36228 if (!entry.GetBaseURLForDataURL().is_empty()) {
229 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
230 params->history_url_for_data_url = entry.GetVirtualURL();
231 }
[email protected]36fc0392011-12-25 03:59:51232 params->referrer = entry.GetReferrer();
233 params->transition = entry.GetTransitionType();
234 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00235 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55236 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34237 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47238 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48239 params->transferred_request_child_id =
240 entry.transferred_global_request_id().child_id;
241 params->transferred_request_request_id =
242 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22243 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00244 // Avoid downloading when in view-source mode.
245 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24246 params->embedder_channel_name = embedder_channel_name;
247 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44248 params->is_post = entry.GetHasPostData();
249 if(entry.GetBrowserInitiatedPostData()) {
250 params->browser_initiated_post_data.assign(
251 entry.GetBrowserInitiatedPostData()->front(),
252 entry.GetBrowserInitiatedPostData()->front() +
253 entry.GetBrowserInitiatedPostData()->size());
254
255 }
[email protected]6c6b02d2011-09-02 03:36:47256
[email protected]7c16976c2012-08-04 02:38:23257 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
258 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
259 // We may have been redirected when navigating to the current URL.
260 // Use the URL the user originally intended to visit, if it's valid and if a
261 // POST wasn't involved; the latter case avoids issues with sending data to
262 // the wrong page.
263 params->url = entry.GetOriginalRequestURL();
264 } else {
265 params->url = entry.GetURL();
266 }
267
[email protected]6c6b02d2011-09-02 03:36:47268 if (delegate)
269 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34270}
271
[email protected]f98f5092012-05-19 00:08:14272int GetSwitchValueAsInt(
273 const CommandLine& command_line,
274 const std::string& switch_string,
275 int min_value) {
276 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
277 int int_value;
278 if (base::StringToInt(string_value, &int_value))
279 return std::max(min_value, int_value);
280 else
281 return min_value;
282}
283
[email protected]420ae012009-04-24 05:16:32284} // namespace
285
[email protected]a81343d232011-12-27 07:39:20286namespace content {
287
288WebContents* WebContents::Create(
289 BrowserContext* browser_context,
290 SiteInstance* site_instance,
291 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19292 const WebContents* base_web_contents) {
293 return WebContentsImpl::Create(
294 browser_context, site_instance, routing_id,
295 static_cast<const WebContentsImpl*>(base_web_contents));
296}
297
298WebContents* WebContents::CreateWithSessionStorage(
299 BrowserContext* browser_context,
300 SiteInstance* site_instance,
301 int routing_id,
[email protected]b172aee2012-04-10 17:05:26302 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19303 const SessionStorageNamespaceMap& session_storage_namespace_map) {
304 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
305
306 for (SessionStorageNamespaceMap::const_iterator it =
307 session_storage_namespace_map.begin();
308 it != session_storage_namespace_map.end();
309 ++it) {
310 new_contents->GetController().SetSessionStorageNamespace(it->first,
311 it->second);
312 }
313
314 new_contents->Init(browser_context, site_instance, routing_id,
315 static_cast<const WebContentsImpl*>(base_web_contents));
316 return new_contents;
[email protected]a81343d232011-12-27 07:39:20317}
[email protected]746d3052012-05-22 15:15:47318
[email protected]299d7f12012-05-23 05:31:15319WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47320 return rvh->GetDelegate()->GetAsWebContents();
321}
322
[email protected]a81343d232011-12-27 07:39:20323}
[email protected]f4f50ef2011-01-21 19:01:19324
[email protected]b172aee2012-04-10 17:05:26325// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32326
[email protected]b172aee2012-04-10 17:05:26327WebContentsImpl::WebContentsImpl(
328 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19329 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42330 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19331 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57332 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44333 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05334 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34335 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23336 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
337 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34338 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21339 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56340 upload_size_(0),
341 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47342 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57343 capturing_contents_(false),
344 is_being_destroyed_(false),
345 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55346 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57347#if defined(OS_WIN)
348 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
349#endif
[email protected]7ab1e7d62009-10-14 23:32:01350 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56351 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38352 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25353 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01354 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25355 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01356 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00357 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43358 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20359 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35360}
initial.commit09911bf2008-07-26 23:55:29361
[email protected]b172aee2012-04-10 17:05:26362WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32363 is_being_destroyed_ = true;
364
[email protected]3ab9cb82011-06-03 18:02:07365 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55366 if (dialog_creator_)
367 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07368
[email protected]da8543762012-03-20 08:52:20369 if (color_chooser_)
370 color_chooser_->End();
371
[email protected]420ae012009-04-24 05:16:32372 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32373
[email protected]ca13a442012-04-17 14:00:12374 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07375 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09376 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
377 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07378 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32379
380 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07381#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32382 // If we still have a window handle, destroy it. GetNativeView can return
383 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42384 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52385 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58386 if (host && host->GetView())
387 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42388 }
[email protected]420ae012009-04-24 05:16:32389#endif
[email protected]7ab1e7d62009-10-14 23:32:01390
391 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15392 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01393 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15394 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01395 }
[email protected]b5a1d11c2011-02-17 03:09:42396
[email protected]2db9bd72012-04-13 20:20:56397 FOR_EACH_OBSERVER(WebContentsObserver,
398 observers_,
399 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08400
[email protected]6934a702011-12-20 00:04:51401 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42402}
403
[email protected]d1198fd2012-08-13 22:50:19404WebContentsImpl* WebContentsImpl::Create(
405 BrowserContext* browser_context,
406 SiteInstance* site_instance,
407 int routing_id,
408 const WebContentsImpl* base_web_contents) {
409 return CreateWithOpener(browser_context, site_instance, routing_id,
410 base_web_contents, NULL);
411}
412
413WebContentsImpl* WebContentsImpl::CreateWithOpener(
414 BrowserContext* browser_context,
415 SiteInstance* site_instance,
416 int routing_id,
417 const WebContentsImpl* base_web_contents,
418 WebContentsImpl* opener) {
419 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
420
421 new_contents->Init(browser_context, site_instance, routing_id,
422 static_cast<const WebContentsImpl*>(base_web_contents));
423 return new_contents;
424}
425
[email protected]b172aee2012-04-10 17:05:26426WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
427 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54428 WebPreferences prefs;
429
430 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
431
432 prefs.developer_extras_enabled = true;
433 prefs.javascript_enabled =
434 !command_line.HasSwitch(switches::kDisableJavaScript);
435 prefs.web_security_enabled =
436 !command_line.HasSwitch(switches::kDisableWebSecurity);
437 prefs.plugins_enabled =
438 !command_line.HasSwitch(switches::kDisablePlugins);
439 prefs.java_enabled =
440 !command_line.HasSwitch(switches::kDisableJava);
441
442 prefs.uses_page_cache =
443 command_line.HasSwitch(switches::kEnableFastback);
444 prefs.remote_fonts_enabled =
445 !command_line.HasSwitch(switches::kDisableRemoteFonts);
446 prefs.xss_auditor_enabled =
447 !command_line.HasSwitch(switches::kDisableXSSAuditor);
448 prefs.application_cache_enabled =
449 !command_line.HasSwitch(switches::kDisableApplicationCache);
450
451 prefs.local_storage_enabled =
452 !command_line.HasSwitch(switches::kDisableLocalStorage);
453 prefs.databases_enabled =
454 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01455#if defined(OS_ANDROID)
456 prefs.webaudio_enabled =
457 command_line.HasSwitch(switches::kEnableWebAudio);
458#else
[email protected]64d69de42012-02-06 00:19:54459 prefs.webaudio_enabled =
460 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01461#endif
[email protected]64d69de42012-02-06 00:19:54462
463 prefs.experimental_webgl_enabled =
464 GpuProcessHost::gpu_enabled() &&
465 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07466#if defined(OS_ANDROID)
467 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
468#else
[email protected]64d69de42012-02-06 00:19:54469 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07470#endif
[email protected]64d69de42012-02-06 00:19:54471
[email protected]5a073092012-06-08 00:42:51472 prefs.flash_3d_enabled =
473 GpuProcessHost::gpu_enabled() &&
474 !command_line.HasSwitch(switches::kDisableFlash3d);
475 prefs.flash_stage3d_enabled =
476 GpuProcessHost::gpu_enabled() &&
477 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19478
[email protected]64d69de42012-02-06 00:19:54479 prefs.gl_multisampling_enabled =
480 !command_line.HasSwitch(switches::kDisableGLMultisampling);
481 prefs.privileged_webgl_extensions_enabled =
482 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
483 prefs.site_specific_quirks_enabled =
484 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
485 prefs.allow_file_access_from_file_urls =
486 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
487 prefs.show_composited_layer_borders =
488 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
489 prefs.show_composited_layer_tree =
490 command_line.HasSwitch(switches::kShowCompositedLayerTree);
491 prefs.show_fps_counter =
492 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19493 prefs.show_paint_rects =
494 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52495 prefs.render_vsync_enabled =
496 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54497 prefs.accelerated_compositing_enabled =
498 GpuProcessHost::gpu_enabled() &&
499 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54500 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23501 command_line.HasSwitch(switches::kForceCompositingMode) &&
502 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54503 prefs.fixed_position_compositing_enabled =
504 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
505 prefs.accelerated_2d_canvas_enabled =
506 GpuProcessHost::gpu_enabled() &&
507 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58508 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27509 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54510 prefs.accelerated_painting_enabled =
511 GpuProcessHost::gpu_enabled() &&
512 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
513 prefs.accelerated_filters_enabled =
514 GpuProcessHost::gpu_enabled() &&
515 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
516 prefs.accelerated_layers_enabled =
517 prefs.accelerated_animation_enabled =
518 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54519 prefs.accelerated_plugins_enabled =
520 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
521 prefs.accelerated_video_enabled =
522 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54523 prefs.fullscreen_enabled =
524 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16525 prefs.css_regions_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03526 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29527 prefs.css_shaders_enabled =
528 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01529 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03530 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]c71fe6402012-08-15 15:22:55531#if defined(USE_AURA) && defined(USE_X11)
532 prefs.device_supports_touch |=
533 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
534#endif
[email protected]25ee94f2012-09-11 19:16:16535#if defined(OS_WIN)
536 prefs.device_supports_touch = ui::IsTouchDevicePresent();
537#endif
[email protected]d849b122012-07-18 07:35:26538#if defined(OS_ANDROID)
539 prefs.device_supports_mouse = false;
540#endif
[email protected]64d69de42012-02-06 00:19:54541
542#if defined(OS_MACOSX)
543 bool default_enable_scroll_animator = true;
544#else
545 // On CrOS, the launcher always passes in the --enable flag.
546 bool default_enable_scroll_animator = false;
547#endif
548 prefs.enable_scroll_animator = default_enable_scroll_animator;
549 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
550 prefs.enable_scroll_animator = true;
551 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
552 prefs.enable_scroll_animator = false;
553
554 prefs.visual_word_movement_enabled =
555 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54556
557 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32558 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54559 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39560 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]d56ecf922012-02-15 16:03:11561 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54562 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11563 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54564 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19565 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
566 prefs.flash_3d_enabled = false;
567 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
568 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11569 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54570 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11571 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54572 prefs.gl_multisampling_enabled = false;
573
574 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45575 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32576 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54577 prefs.accelerated_video_enabled = false;
578 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45579 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09580 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54581 }
582 }
583
[email protected]b9535422012-02-09 01:47:59584 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58585 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54586 prefs.loads_images_automatically = true;
587 prefs.javascript_enabled = true;
588 }
589
590 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
591
592 // Force accelerated compositing and 2d canvas off for chrome:, about: and
593 // chrome-devtools: pages (unless it's specifically allowed).
594 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54595 url.SchemeIs(chrome::kChromeUIScheme) ||
596 (url.SchemeIs(chrome::kAboutScheme) &&
597 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25598 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54599 prefs.accelerated_compositing_enabled = false;
600 prefs.accelerated_2d_canvas_enabled = false;
601 }
[email protected]43d9d782012-03-01 15:40:09602
[email protected]f98f5092012-05-19 00:08:14603 if (command_line.HasSwitch(switches::kDefaultTileWidth))
604 prefs.default_tile_width =
605 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
606 if (command_line.HasSwitch(switches::kDefaultTileHeight))
607 prefs.default_tile_height =
608 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
609 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
610 prefs.max_untiled_layer_width =
611 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
612 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
613 prefs.max_untiled_layer_height =
614 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
615
[email protected]2486dce2012-05-23 17:18:19616 if (gfx::Screen::IsDIPEnabled()) {
617 // Only apply when using DIP coordinate system as this setting interferes
618 // with fixed layout mode.
619 prefs.apply_default_device_scale_factor_in_compositor = true;
620 }
621
[email protected]de023762012-07-26 17:10:17622 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
623 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10624
[email protected]e755a382012-09-13 17:16:35625 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
626 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12627
[email protected]6b4dcb072012-06-18 22:26:51628 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
629
[email protected]2e21fe292012-03-02 22:52:32630 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54631
632 return prefs;
633}
634
[email protected]b172aee2012-04-10 17:05:26635RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28636 return &render_manager_;
637}
638
[email protected]7bb761892012-07-20 09:32:47639bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
640 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56641 if (GetWebUI() &&
642 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17643 return true;
[email protected]d2353452012-01-19 19:53:56644 }
[email protected]f82d57b52011-04-27 19:13:17645
[email protected]d8c660432011-12-22 20:51:25646 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
647 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10648 while ((observer = it.GetNext()) != NULL)
649 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53650 return true;
[email protected]403415a2011-01-10 18:57:53651
[email protected]7bb761892012-07-20 09:32:47652 // Message handlers should be aware of which RenderViewHost sent the
653 // message, which is temporarily stored in message_source_.
654 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18655 bool handled = true;
656 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26657 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58658 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
659 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24660 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
661 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18662 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
663 OnDidLoadResourceFromMemoryCache)
664 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
665 OnDidDisplayInsecureContent)
666 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
667 OnDidRunInsecureContent)
668 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
669 OnDocumentLoadedInFrame)
670 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26671 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
672 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17673 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
674 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25675 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26676 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59677 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21678 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20679 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
681 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16682 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]59363fc92012-09-05 03:46:31683#if defined(OS_ANDROID)
684 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
685 OnFindMatchRectsReply)
686#endif
[email protected]d952a052011-09-06 18:42:45687 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10688 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20689 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
691 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
692 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29693 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50694 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50695 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
696 OnRequestPpapiBrokerPermission)
[email protected]724159a2010-12-30 01:11:18697 IPC_MESSAGE_UNHANDLED(handled = false)
698 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47699 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18700
701 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38702 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18703 GetRenderProcessHost()->ReceivedBadMessage();
704 }
705
706 return handled;
707}
708
[email protected]b172aee2012-04-10 17:05:26709void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18710 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23711 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43712 if (delegate_)
713 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18714}
715
[email protected]d1198fd2012-08-13 22:50:19716NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56717 return controller_;
718}
719
[email protected]d1198fd2012-08-13 22:50:19720const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56721 return controller_;
722}
723
[email protected]b172aee2012-04-10 17:05:26724content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55725 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30726}
727
[email protected]b172aee2012-04-10 17:05:26728const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31729 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23730 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51731 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31732}
733
[email protected]b172aee2012-04-10 17:05:26734content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31735 return delegate_;
736}
737
[email protected]b172aee2012-04-10 17:05:26738void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31739 // TODO(cbentzel): remove this debugging code?
740 if (delegate == delegate_)
741 return;
742 if (delegate_)
743 delegate_->Detach(this);
744 delegate_ = delegate;
745 if (delegate_)
746 delegate_->Attach(this);
747}
748
[email protected]b172aee2012-04-10 17:05:26749content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41750 RenderViewHostImpl* host = render_manager_.current_host();
751 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16752}
753
[email protected]b172aee2012-04-10 17:05:26754RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31755 return render_manager_.current_host();
756}
757
[email protected]6b618e62012-08-16 12:59:18758int WebContentsImpl::GetRoutingID() const {
759 if (!GetRenderViewHost())
760 return MSG_ROUTING_NONE;
761
762 return GetRenderViewHost()->GetRoutingID();
763}
764
[email protected]b172aee2012-04-10 17:05:26765RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31766 return render_manager_.GetRenderWidgetHostView();
767}
768
[email protected]b172aee2012-04-10 17:05:26769content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31770 return view_.get();
771}
772
[email protected]b172aee2012-04-10 17:05:26773content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50774 WebUIControllerFactory* factory =
775 content::GetContentClient()->browser()->GetWebUIControllerFactory();
776 if (!factory)
777 return NULL;
[email protected]d2353452012-01-19 19:53:56778 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22779 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50780 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22781 if (controller) {
782 web_ui->SetController(controller);
783 return web_ui;
784 }
785
786 delete web_ui;
787 return NULL;
788}
789
[email protected]b172aee2012-04-10 17:05:26790content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31791 return render_manager_.web_ui() ? render_manager_.web_ui()
792 : render_manager_.pending_web_ui();
793}
794
[email protected]b172aee2012-04-10 17:05:26795content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31796 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34797}
798
[email protected]86ef6a392012-05-11 22:03:11799void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22800 if (GetUserAgentOverride() == override)
801 return;
802
803 renderer_preferences_.user_agent_override = override;
804
805 // Send the new override string to the renderer.
806 RenderViewHost* host = GetRenderViewHost();
807 if (host)
808 host->SyncRendererPrefs();
809
810 // Reload the page if a load is currently in progress to avoid having
811 // different parts of the page loaded using different user agents.
812 NavigationEntry* entry = controller_.GetActiveEntry();
813 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
814 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53815
816 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
817 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11818}
819
820const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22821 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11822}
823
[email protected]b172aee2012-04-10 17:05:26824const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55825 // Transient entries take precedence. They are used for interstitial pages
826 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23827 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08828 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20829 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30830 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23831 if (entry) {
[email protected]b5cca982011-05-26 04:42:08832 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23833 }
[email protected]7ade2732011-02-10 00:13:58834 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
835 render_manager_.pending_web_ui() : render_manager_.web_ui();
836 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54837 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55838 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54839 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35840 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22841 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54842 if (!title.empty())
843 return title;
844 }
845 }
846
847 // We use the title for the last committed entry rather than a pending
848 // navigation entry. For example, when the user types in a URL, we want to
849 // keep the old page's title until the new load has committed and we get a new
850 // title.
[email protected]96d185d2009-04-24 03:28:54851 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23852 if (entry) {
[email protected]b5cca982011-05-26 04:42:08853 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23854 }
[email protected]987fc3a2011-05-26 14:18:09855
856 // |page_title_when_no_navigation_entry_| is finally used
857 // if no title cannot be retrieved.
858 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54859}
860
[email protected]b172aee2012-04-10 17:05:26861int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46862 return GetMaxPageIDForSiteInstance(GetSiteInstance());
863}
864
[email protected]b172aee2012-04-10 17:05:26865int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
866 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33867 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
868 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46869
[email protected]b6583592012-01-25 19:52:33870 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34871}
872
[email protected]b172aee2012-04-10 17:05:26873void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46874 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
875}
876
[email protected]b172aee2012-04-10 17:05:26877void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33878 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46879 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33880 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34881}
882
[email protected]b172aee2012-04-10 17:05:26883void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
884 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57885}
886
[email protected]b172aee2012-04-10 17:05:26887SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58888 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54889}
890
[email protected]b172aee2012-04-10 17:05:26891SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38892 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
893 render_manager_.pending_render_view_host() :
894 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58895 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38896}
897
[email protected]b172aee2012-04-10 17:05:26898bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31899 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49900}
901
[email protected]b172aee2012-04-10 17:05:26902bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31903 return waiting_for_response_;
904}
905
[email protected]b172aee2012-04-10 17:05:26906const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31907 return load_state_;
908}
909
[email protected]b172aee2012-04-10 17:05:26910const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31911 return load_state_host_;
912}
913
[email protected]b172aee2012-04-10 17:05:26914uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31915 return upload_size_;
916}
917
[email protected]b172aee2012-04-10 17:05:26918uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31919 return upload_position_;
920}
921
[email protected]b172aee2012-04-10 17:05:26922const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31923 return encoding_;
924}
925
[email protected]b172aee2012-04-10 17:05:26926bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return displayed_insecure_content_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31931 capturing_contents_ = cap;
932}
933
[email protected]b172aee2012-04-10 17:05:26934bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31935 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
936 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
937 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49938}
939
[email protected]b172aee2012-04-10 17:05:26940void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
941 int error_code) {
[email protected]443b80e2010-12-14 00:42:23942 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34943 return;
944
[email protected]443b80e2010-12-14 00:42:23945 crashed_status_ = status;
946 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46947 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34948}
949
[email protected]b172aee2012-04-10 17:05:26950base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31951 return crashed_status_;
952}
953
[email protected]b172aee2012-04-10 17:05:26954bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31955 return is_being_destroyed_;
956}
957
[email protected]b172aee2012-04-10 17:05:26958void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34959 if (delegate_)
960 delegate_->NavigationStateChanged(this, changed_flags);
961}
962
[email protected]3e324142012-06-25 18:26:33963base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
964 return last_selected_time_;
965}
966
[email protected]9e2e4632012-07-27 16:38:41967void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54968 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04969 RenderWidgetHostViewPort* rwhv =
970 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16971 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41972 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43973#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16974 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43975#endif
976 }
[email protected]96d185d2009-04-24 03:28:54977
[email protected]5ac20162010-11-24 23:33:11978 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38979
[email protected]9e2e4632012-07-27 16:38:41980 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59981
982 // The resize rect might have changed while this was inactive -- send the new
983 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58984 RenderViewHostImpl* rvh =
985 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59986 if (rvh) {
987 rvh->ResizeRectChanged(GetRootWindowResizerRect());
988 }
[email protected]96d185d2009-04-24 03:28:54989
[email protected]3e324142012-06-25 18:26:33990 bool is_visible = true;
991 content::NotificationService::current()->Notify(
992 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
993 content::Source<WebContents>(this),
994 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31995}
996
[email protected]b172aee2012-04-10 17:05:26997void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31998 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52999 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1000 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261001 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521002 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331003 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521004 // calls us).
[email protected]c30585c2012-02-16 15:02:041005 RenderWidgetHostViewPort* rwhv =
1006 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161007 if (rwhv)
1008 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541009 }
1010
[email protected]375fa1b2012-05-22 22:05:371011 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071012 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371013 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091014 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371015 content::Details<bool>(&is_visible));
1016}
1017
[email protected]b172aee2012-04-10 17:05:261018bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311019 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271020 return WillNotifyDisconnection() &&
1021 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581022 !static_cast<RenderViewHostImpl*>(
1023 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311024}
1025
[email protected]b172aee2012-04-10 17:05:261026void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271027 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251028 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271029}
1030
[email protected]b172aee2012-04-10 17:05:261031WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441032 // We use our current SiteInstance since the cloned entry will use it anyway.
1033 // We pass |this| for the |base_web_contents| to size the view correctly, and
1034 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191035 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1036 GetSiteInstance(), MSG_ROUTING_NONE,
1037 this, opener_);
1038 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221039 FOR_EACH_OBSERVER(WebContentsObserver,
1040 observers_,
1041 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271042 return tc;
1043}
1044
[email protected]b172aee2012-04-10 17:05:261045gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271046 return view_->GetContentNativeView();
1047}
1048
[email protected]b172aee2012-04-10 17:05:261049gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271050 return view_->GetNativeView();
1051}
1052
[email protected]b172aee2012-04-10 17:05:261053void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271054 view_->GetContainerBounds(out);
1055}
1056
[email protected]b172aee2012-04-10 17:05:261057void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271058 view_->Focus();
1059}
1060
[email protected]14392a52012-05-02 20:28:441061void WebContentsImpl::Observe(int type,
1062 const content::NotificationSource& source,
1063 const content::NotificationDetails& details) {
1064 switch (type) {
1065 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1066 OnWebContentsDestroyed(
1067 content::Source<content::WebContents>(source).ptr());
1068 break;
[email protected]bafe6cd2012-05-23 23:09:501069 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1070 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1071 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1072 i != pending_widget_views_.end(); ++i) {
1073 if (host->GetView() == i->second) {
1074 pending_widget_views_.erase(i);
1075 break;
1076 }
1077 }
1078 break;
1079 }
[email protected]14392a52012-05-02 20:28:441080 default:
1081 NOTREACHED();
1082 }
1083}
1084
[email protected]d1198fd2012-08-13 22:50:191085void WebContentsImpl::Init(BrowserContext* browser_context,
1086 SiteInstance* site_instance,
1087 int routing_id,
1088 const WebContents* base_web_contents) {
1089 render_manager_.Init(browser_context, site_instance, routing_id);
1090
1091 view_.reset(content::GetContentClient()->browser()->
1092 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1093 if (view_.get()) {
1094 CHECK(render_view_host_delegate_view_);
1095 } else {
1096 content::WebContentsViewDelegate* delegate =
1097 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1098 this);
1099 view_.reset(CreateWebContentsView(
1100 this, delegate, &render_view_host_delegate_view_));
1101 CHECK(render_view_host_delegate_view_);
1102 }
1103 CHECK(view_.get());
1104
1105 // We have the initial size of the view be based on the size of the view of
1106 // the passed in WebContents.
1107 view_->CreateView(base_web_contents ?
1108 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1109
1110 // Listen for whether our opener gets destroyed.
1111 if (opener_) {
1112 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1113 content::Source<WebContents>(opener_));
1114 }
1115
1116 registrar_.Add(this,
1117 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1118 content::NotificationService::AllBrowserContextsAndSources());
1119#if defined(ENABLE_JAVA_BRIDGE)
1120 java_bridge_dispatcher_host_manager_.reset(
1121 new JavaBridgeDispatcherHostManager(this));
1122#endif
1123
1124 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1125}
1126
[email protected]14392a52012-05-02 20:28:441127void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1128 // Clear the opener if it has been closed.
1129 if (web_contents == opener_) {
1130 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1131 content::Source<WebContents>(opener_));
1132 opener_ = NULL;
1133 }
1134}
1135
[email protected]b172aee2012-04-10 17:05:261136void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311137 observers_.AddObserver(observer);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311141 observers_.RemoveObserver(observer);
1142}
1143
[email protected]b172aee2012-04-10 17:05:261144void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341145 if (delegate_)
1146 delegate_->ActivateContents(this);
1147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121150 if (delegate_)
1151 delegate_->DeactivateContents(this);
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481155 if (delegate_)
1156 delegate_->LostCapture();
1157}
1158
[email protected]b172aee2012-04-10 17:05:261159bool WebContentsImpl::PreHandleKeyboardEvent(
1160 const NativeWebKeyboardEvent& event,
1161 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481162 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131163 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481164}
1165
[email protected]b172aee2012-04-10 17:05:261166void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481167 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131168 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431172 if (delegate_)
1173 delegate_->HandleMouseDown();
1174}
1175
[email protected]b172aee2012-04-10 17:05:261176void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481177 if (delegate_)
1178 delegate_->HandleMouseUp();
1179}
1180
[email protected]590a634e2012-07-19 16:38:231181void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481182 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231183 delegate_->HandlePointerActivate();
1184}
1185
1186void WebContentsImpl::HandleGestureBegin() {
1187 if (delegate_)
1188 delegate_->HandleGestureBegin();
1189}
1190
1191void WebContentsImpl::HandleGestureEnd() {
1192 if (delegate_)
1193 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481194}
1195
[email protected]b172aee2012-04-10 17:05:261196void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471197 if (delegate_)
1198 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1199}
1200
[email protected]b172aee2012-04-10 17:05:261201bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381202 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121203}
1204
[email protected]a9c81f02012-06-01 00:15:441205void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1206 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371207 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441208 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371209 } else {
1210 GotResponseToLockMouseRequest(false);
1211 }
1212}
1213
[email protected]b172aee2012-04-10 17:05:261214void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371215 if (delegate_)
1216 delegate_->LostMouseLock();
1217}
1218
[email protected]bafe6cd2012-05-23 23:09:501219void WebContentsImpl::CreateNewWindow(
1220 int route_id,
[email protected]97714c82012-06-06 10:15:131221 const ViewHostMsg_CreateWindow_Params& params,
1222 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501223 if (delegate_ && !delegate_->ShouldCreateWebContents(
1224 this, route_id, params.window_container_type, params.frame_name,
1225 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091226 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501227 return;
1228 }
1229
1230 // We usually create the new window in the same BrowsingInstance (group of
1231 // script-related windows), by passing in the current SiteInstance. However,
1232 // if the opener is being suppressed, we create a new SiteInstance in its own
1233 // BrowsingInstance.
1234 scoped_refptr<SiteInstance> site_instance =
1235 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571236 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501237 GetSiteInstance();
1238
1239 // Create the new web contents. This will automatically create the new
1240 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191241 WebContentsImpl* new_contents =
1242 new WebContentsImpl(GetBrowserContext(),
1243 params.opener_suppressed ? NULL : this);
1244
1245 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341246 //
1247 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191248 const std::string& partition_id =
1249 content::GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571250 GetStoragePartitionIdForSite(GetBrowserContext(),
1251 site_instance->GetSite());
[email protected]4c3a23582012-08-18 08:54:341252 content::StoragePartition* partition =
1253 BrowserContext::GetStoragePartition(GetBrowserContext(),
1254 site_instance);
[email protected]d1198fd2012-08-13 22:50:191255 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341256 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191257 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1258 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1259 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1260 new_contents->GetController().SetSessionStorageNamespace(
1261 partition_id,
1262 session_storage_namespace);
1263 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1264
[email protected]bafe6cd2012-05-23 23:09:501265 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1266
1267 if (!params.opener_suppressed) {
1268 content::WebContentsView* new_view = new_contents->GetView();
1269
1270 // TODO(brettw): It seems bogus that we have to call this function on the
1271 // newly created object and give it one of its own member variables.
1272 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1273
1274 // Save the created window associated with the route so we can show it
1275 // later.
1276 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1277 pending_contents_[route_id] = new_contents;
1278 }
1279
1280 if (delegate_) {
1281 delegate_->WebContentsCreated(
1282 this, params.opener_frame_id, params.target_url, new_contents);
1283 }
1284
1285 if (params.opener_suppressed) {
1286 // When the opener is suppressed, the original renderer cannot access the
1287 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001288 bool was_blocked = false;
1289 if (delegate_) {
1290 gfx::Rect initial_pos;
1291 delegate_->AddNewContents(
1292 this, new_contents, params.disposition, initial_pos,
1293 params.user_gesture, &was_blocked);
1294 }
1295 if (!was_blocked) {
1296 content::OpenURLParams open_params(params.target_url,
1297 content::Referrer(),
1298 CURRENT_TAB,
1299 content::PAGE_TRANSITION_LINK,
1300 true /* is_renderer_initiated */);
1301 new_contents->OpenURL(open_params);
1302 }
[email protected]bafe6cd2012-05-23 23:09:501303 }
1304}
1305
1306void WebContentsImpl::CreateNewWidget(int route_id,
1307 WebKit::WebPopupType popup_type) {
1308 CreateNewWidget(route_id, false, popup_type);
1309}
1310
1311void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1312 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1313}
1314
1315void WebContentsImpl::CreateNewWidget(int route_id,
1316 bool is_fullscreen,
1317 WebKit::WebPopupType popup_type) {
1318 content::RenderProcessHost* process = GetRenderProcessHost();
1319 RenderWidgetHostImpl* widget_host =
1320 new RenderWidgetHostImpl(this, process, route_id);
1321 RenderWidgetHostViewPort* widget_view =
1322 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1323 if (!is_fullscreen) {
1324 // Popups should not get activated.
1325 widget_view->SetPopupType(popup_type);
1326 }
1327 // Save the created widget associated with the route so we can show it later.
1328 pending_widget_views_[route_id] = widget_view;
1329
1330#if defined(OS_MACOSX)
1331 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1332 // to allow it to survive the trip without being hosted.
1333 base::mac::NSObjectRetain(widget_view->GetNativeView());
1334#endif
1335}
1336
1337void WebContentsImpl::ShowCreatedWindow(int route_id,
1338 WindowOpenDisposition disposition,
1339 const gfx::Rect& initial_pos,
1340 bool user_gesture) {
1341 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001342 if (contents) {
1343 WebContentsDelegate* delegate = GetDelegate();
1344 if (delegate) {
1345 delegate->AddNewContents(
1346 this, contents, disposition, initial_pos, user_gesture, NULL);
1347 }
1348 }
[email protected]bafe6cd2012-05-23 23:09:501349}
1350
1351void WebContentsImpl::ShowCreatedWidget(int route_id,
1352 const gfx::Rect& initial_pos) {
1353 ShowCreatedWidget(route_id, false, initial_pos);
1354}
1355
1356void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1357 ShowCreatedWidget(route_id, true, gfx::Rect());
1358}
1359
1360void WebContentsImpl::ShowCreatedWidget(int route_id,
1361 bool is_fullscreen,
1362 const gfx::Rect& initial_pos) {
1363 if (delegate_)
1364 delegate_->RenderWidgetShowing();
1365
1366 RenderWidgetHostViewPort* widget_host_view =
1367 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1368 if (!widget_host_view)
1369 return;
1370 if (is_fullscreen) {
1371 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1372 } else {
1373 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1374 }
[email protected]89054502012-06-03 10:29:241375
1376 RenderWidgetHostImpl* render_widget_host_impl =
1377 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1378 render_widget_host_impl->Init();
1379 // Only allow privileged mouse lock for fullscreen render widget, which is
1380 // used to implement Pepper Flash fullscreen.
1381 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501382
1383#if defined(OS_MACOSX)
1384 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1385 // properly embedded (or purposefully ignored) we can release the retain we
1386 // took in CreateNewWidget().
1387 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1388#endif
1389}
1390
1391WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1392 PendingContents::iterator iter = pending_contents_.find(route_id);
1393
1394 // Certain systems can block the creation of new windows. If we didn't succeed
1395 // in creating one, just return NULL.
1396 if (iter == pending_contents_.end()) {
1397 return NULL;
1398 }
1399
1400 WebContentsImpl* new_contents = iter->second;
1401 pending_contents_.erase(route_id);
1402
1403 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1404 !new_contents->GetRenderViewHost()->GetView())
1405 return NULL;
1406
1407 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1408 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1409 return new_contents;
1410}
1411
1412RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1413 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1414 if (iter == pending_widget_views_.end()) {
1415 DCHECK(false);
1416 return NULL;
1417 }
1418
1419 RenderWidgetHostView* widget_host_view = iter->second;
1420 pending_widget_views_.erase(route_id);
1421
1422 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1423 if (!widget_host->GetProcess()->HasConnection()) {
1424 // The view has gone away or the renderer crashed. Nothing to do.
1425 return NULL;
1426 }
1427
1428 return widget_host_view;
1429}
1430
1431void WebContentsImpl::ShowContextMenu(
[email protected]ba16e3a2012-09-07 04:14:521432 const content::ContextMenuParams& params,
1433 const content::ContextMenuSourceType& type) {
[email protected]bafe6cd2012-05-23 23:09:501434 // Allow WebContentsDelegates to handle the context menu operation first.
1435 if (delegate_ && delegate_->HandleContextMenu(params))
1436 return;
1437
[email protected]ba16e3a2012-09-07 04:14:521438 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501439}
1440
[email protected]f13b4202012-06-12 23:53:231441void WebContentsImpl::RequestMediaAccessPermission(
1442 const content::MediaStreamRequest* request,
1443 const content::MediaResponseCallback& callback) {
1444 if (delegate_)
1445 delegate_->RequestMediaAccessPermission(this, request, callback);
1446 else
1447 callback.Run(content::MediaStreamDevices());
1448}
1449
[email protected]16383382012-09-05 23:57:261450#if defined(OS_ANDROID)
1451void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1452 if (delegate_)
1453 delegate_->AttachLayer(this, layer);
1454}
1455
1456void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1457 if (delegate_)
1458 delegate_->RemoveLayer(this, layer);
1459}
1460#endif
1461
[email protected]b172aee2012-04-10 17:05:261462void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231463 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331464 if (delegate_)
1465 delegate_->UpdatePreferredSize(this, pref_size);
1466}
1467
[email protected]b172aee2012-04-10 17:05:261468void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341469 if (delegate_)
1470 delegate_->ResizeDueToAutoResize(this, new_size);
1471}
1472
[email protected]b172aee2012-04-10 17:05:261473WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201474 if (!delegate_)
1475 return NULL;
[email protected]00c37fc2011-08-02 00:22:501476
[email protected]e5d549d2011-12-28 01:29:201477 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1478 // Notify observers.
1479 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1480 DidOpenURL(params.url, params.referrer,
1481 params.disposition, params.transition));
1482 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341483}
1484
[email protected]6b618e62012-08-16 12:59:181485bool WebContentsImpl::Send(IPC::Message* message) {
1486 if (!GetRenderViewHost()) {
1487 delete message;
1488 return false;
1489 }
1490
1491 return GetRenderViewHost()->Send(message);
1492}
1493
[email protected]b172aee2012-04-10 17:05:261494bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501495 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251496 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231497 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251498 reload_type);
[email protected]876bc832010-09-07 16:29:541499}
[email protected]96d185d2009-04-24 03:28:541500
[email protected]ba45bfd2012-05-22 21:51:441501void WebContentsImpl::RenderViewForInterstitialPageCreated(
1502 content::RenderViewHost* render_view_host) {
1503 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1504 RenderViewForInterstitialPageCreated(render_view_host));
1505}
1506
[email protected]b172aee2012-04-10 17:05:261507bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231508 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501509 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401510 // The renderer will reject IPC messages with URLs longer than
1511 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511512 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401513 return false;
1514
[email protected]9f76c1e2012-03-05 15:15:581515 RenderViewHostImpl* dest_render_view_host =
1516 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401517 if (!dest_render_view_host)
1518 return false; // Unable to create the desired render view host.
1519
[email protected]80a8fad2011-01-29 04:02:381520 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071521 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581522 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501523 WebUIControllerFactory* factory =
1524 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271525 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501526 bool is_allowed_in_web_ui_renderer =
1527 factory &&
[email protected]24e18252012-04-16 21:26:271528 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1529 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231530 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1531 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271532 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231533 content::GetContentClient()->SetActiveURL(entry.GetURL());
1534 CHECK(0);
1535 }
[email protected]54ec6472010-04-09 19:39:581536
[email protected]96d185d2009-04-24 03:28:541537 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441538 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521539 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441540 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511541 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541542
[email protected]7bb761892012-07-20 09:32:471543 // Notify observers that we will navigate in this RV.
1544 FOR_EACH_OBSERVER(WebContentsObserver,
1545 observers_,
1546 AboutToNavigateRenderView(dest_render_view_host));
1547
[email protected]96d185d2009-04-24 03:28:541548 // Used for page load time metrics.
1549 current_load_start_ = base::TimeTicks::Now();
1550
1551 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241552 std::string embedder_channel_name;
1553 int embedder_container_id;
1554 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1555 &embedder_channel_name,
1556 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341557 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271558 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241559 embedder_channel_name,
1560 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471561 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341562 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541563
[email protected]36fc0392011-12-25 03:59:511564 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541565 // HACK!! This code suppresses javascript: URLs from being added to
1566 // session history, which is what we want to do for javascript: URLs that
1567 // do not generate content. What we really need is a message from the
1568 // renderer telling us that a new page was not created. The same message
1569 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511570 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541571 return false;
1572 }
1573
[email protected]3c9e1872010-11-18 16:17:491574 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251575 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041576 observers_,
[email protected]36fc0392011-12-25 03:59:511577 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541578
[email protected]09b29342011-06-24 19:18:481579 if (delegate_)
1580 delegate_->DidNavigateToPendingEntry(this);
1581
[email protected]d5f942ba2008-09-26 19:30:341582 return true;
1583}
1584
[email protected]b172aee2012-04-10 17:05:261585void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331586 const SiteInstance* site_instance,
1587 int history_length,
1588 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411589 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1590 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191591 if (render_manager_.pending_render_view_host()) {
1592 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141593 return;
[email protected]9e1ad4b2011-08-14 16:49:191594 }
[email protected]9f76c1e2012-03-05 15:15:581595 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191596 if (!rvh) {
1597 NOTREACHED();
1598 return;
1599 }
[email protected]9f76c1e2012-03-05 15:15:581600 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191601 NOTREACHED();
1602 return;
1603 }
[email protected]6b618e62012-08-16 12:59:181604 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1605 history_length,
1606 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141607}
1608
[email protected]b172aee2012-04-10 17:05:261609void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271610 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541611 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1612 return;
1613 }
[email protected]9f76c1e2012-03-05 15:15:581614 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541615}
1616
[email protected]b172aee2012-04-10 17:05:261617bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271618 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541619}
1620
[email protected]b172aee2012-04-10 17:05:261621InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271622 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221623}
1624
[email protected]b172aee2012-04-10 17:05:261625bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161626 // WebKit creates Document object when MIME type is application/xhtml+xml,
1627 // so we also support this MIME type.
1628 return contents_mime_type_ == "text/html" ||
1629 contents_mime_type_ == "text/xml" ||
1630 contents_mime_type_ == "application/xhtml+xml" ||
1631 contents_mime_type_ == "text/plain" ||
1632 contents_mime_type_ == "text/css" ||
1633 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1634}
1635
[email protected]b172aee2012-04-10 17:05:261636void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591637 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161638 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481639 download_stats::RecordDownloadSource(
1640 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461641 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141642 return;
[email protected]c7dd2f62011-07-18 15:57:591643 }
1644
1645 Stop();
1646
1647 // Create the save package and possibly prompt the user for the name to save
1648 // the page as. The user prompt is an asynchronous operation that runs on
1649 // another thread.
1650 save_package_ = new SavePackage(this);
1651 save_package_->GetSaveInfo();
1652}
1653
1654// Used in automated testing to bypass prompting the user for file names.
1655// Instead, the names and paths are hard coded rather than running them through
1656// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261657bool WebContentsImpl::SavePage(const FilePath& main_file,
1658 const FilePath& dir_path,
1659 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591660 // Stop the page from navigating.
1661 Stop();
1662
1663 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271664 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591665}
1666
[email protected]b172aee2012-04-10 17:05:261667void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121668 const FilePath& file,
1669 const base::Callback<void(const FilePath&, int64)>& callback) {
1670 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1671}
1672
[email protected]b172aee2012-04-10 17:05:261673bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231674 NavigationEntryImpl* active_entry =
1675 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321676 return (active_entry != NULL &&
1677 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511678 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321679}
1680
[email protected]b172aee2012-04-10 17:05:261681const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271682 return contents_mime_type_;
1683}
1684
[email protected]b172aee2012-04-10 17:05:261685bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271686 return notify_disconnection_;
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311690 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181691 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311695 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181696 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161697}
1698
[email protected]b172aee2012-04-10 17:05:261699content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271700 return &renderer_preferences_;
1701}
1702
[email protected]b172aee2012-04-10 17:05:261703void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271704 new_tab_start_time_ = time;
1705}
1706
[email protected]b172aee2012-04-10 17:05:261707base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271708 return new_tab_start_time_;
1709}
1710
[email protected]e35ccd52012-05-23 16:22:471711void WebContentsImpl::Close() {
1712 Close(GetRenderViewHost());
1713}
1714
[email protected]b172aee2012-04-10 17:05:261715void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151716 if (close_start_time_.is_null())
1717 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011718}
1719
[email protected]b172aee2012-04-10 17:05:261720bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191721#if defined(OS_CHROMEOS)
1722 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1723 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511724 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201725 return false;
1726 return true;
[email protected]46624bf2010-06-09 16:04:191727#else
1728 return true;
1729#endif
1730}
1731
[email protected]b172aee2012-04-10 17:05:261732void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521733 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581734 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511735 if (delegate_)
1736 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341737}
1738
[email protected]e35ccd52012-05-23 16:22:471739void WebContentsImpl::UserGestureDone() {
1740 OnUserGesture();
1741}
1742
[email protected]b172aee2012-04-10 17:05:261743void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271744 closed_by_user_gesture_ = value;
1745}
1746
[email protected]b172aee2012-04-10 17:05:261747bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271748 return closed_by_user_gesture_;
1749}
1750
[email protected]b172aee2012-04-10 17:05:261751double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051752 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561753 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251754 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171755 return 0;
[email protected]b75b8292010-10-01 07:28:251756
1757 double zoom_level;
1758 if (temporary_zoom_settings_) {
1759 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581760 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251761 } else {
[email protected]2ae88d12011-10-14 09:11:191762 GURL url;
[email protected]10f417c52011-12-28 21:04:231763 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191764 // Since zoom map is updated using rewritten URL, use rewritten URL
1765 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511766 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191767 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251768 }
[email protected]d0b8d092010-10-25 04:05:171769 return zoom_level;
1770}
[email protected]b75b8292010-10-01 07:28:251771
[email protected]b172aee2012-04-10 17:05:261772int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1773 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171774 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011775 // Calculate the zoom percent from the factor. Round up to the nearest whole
1776 // number.
[email protected]b75b8292010-10-01 07:28:251777 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011778 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251779 *enable_decrement = percent > minimum_zoom_percent_;
1780 *enable_increment = percent < maximum_zoom_percent_;
1781 return percent;
1782}
1783
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501785 if (!delegate_)
1786 return;
1787
[email protected]10f417c52011-12-28 21:04:231788 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501789 if (!active_entry)
1790 return;
1791
[email protected]36fc0392011-12-25 03:59:511792 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121793}
1794
[email protected]b172aee2012-04-10 17:05:261795void WebContentsImpl::ViewFrameSource(const GURL& url,
1796 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271797 if (!delegate_)
1798 return;
1799
1800 delegate_->ViewSourceForFrame(this, url, content_state);
1801}
1802
[email protected]b172aee2012-04-10 17:05:261803int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271804 return minimum_zoom_percent_;
1805}
1806
[email protected]b172aee2012-04-10 17:05:261807int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271808 return maximum_zoom_percent_;
1809}
1810
[email protected]b172aee2012-04-10 17:05:261811gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231812 return preferred_size_;
1813}
1814
[email protected]b172aee2012-04-10 17:05:261815int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271816 return content_restrictions_;
1817}
1818
[email protected]b172aee2012-04-10 17:05:261819WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501820 WebUIControllerFactory* factory =
1821 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1822 if (!factory)
1823 return WebUI::kNoWebUI;
1824 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271825}
1826
[email protected]b172aee2012-04-10 17:05:261827content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271828 // When there is a pending navigation entry, we want to use the pending WebUI
1829 // that goes along with it to control the basic flags. For example, we want to
1830 // show the pending URL in the URL bar, so we want the display_url flag to
1831 // be from the pending entry.
1832 //
1833 // The confusion comes because there are multiple possibilities for the
1834 // initial load in a tab as a side effect of the way the RenderViewHostManager
1835 // works.
1836 //
1837 // - For the very first tab the load looks "normal". The new tab Web UI is
1838 // the pending one, and we want it to apply here.
1839 //
1840 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1841 // get switched to the one previously associated with the new tab pages.
1842 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1843 // have a committed Web UI in this case.
1844 //
1845 // This condition handles all of these cases:
1846 //
1847 // - First load in first tab: no committed nav entry + pending nav entry +
1848 // pending dom ui:
1849 // -> Use pending Web UI if any.
1850 //
1851 // - First load in second tab: no committed nav entry + pending nav entry +
1852 // no pending Web UI:
1853 // -> Use the committed Web UI if any.
1854 //
1855 // - Second navigation in any tab: committed nav entry + pending nav entry:
1856 // -> Use pending Web UI if any.
1857 //
1858 // - Normal state with no load: committed nav entry + no pending nav entry:
1859 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251860 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271861 (controller_.GetLastCommittedEntry() ||
1862 render_manager_.pending_web_ui()))
1863 return render_manager_.pending_web_ui();
1864 return render_manager_.web_ui();
1865}
1866
[email protected]b172aee2012-04-10 17:05:261867bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271868 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581869 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271870}
1871
[email protected]b172aee2012-04-10 17:05:261872bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441873 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501874}
1875
[email protected]b172aee2012-04-10 17:05:261876void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321877 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181878 Send(new ViewMsg_DidChooseColorResponse(
1879 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201880}
1881
[email protected]b172aee2012-04-10 17:05:261882void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181883 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201884 if (delegate_)
1885 delegate_->DidEndColorChooser();
1886 color_chooser_ = NULL;
1887}
1888
[email protected]b172aee2012-04-10 17:05:261889bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471890 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271891 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221892 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231893 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411894 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271895}
1896
[email protected]b172aee2012-04-10 17:05:261897void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271898 if (delegate_)
1899 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211900}
1901
[email protected]3a3b75a2012-06-01 08:38:361902void WebContentsImpl::OnRegisterIntentService(
1903 const webkit_glue::WebIntentServiceData& data,
1904 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431905 if (delegate_)
1906 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301907}
1908
[email protected]b172aee2012-04-10 17:05:261909void WebContentsImpl::OnWebIntentDispatch(
1910 const webkit_glue::WebIntentData& intent,
1911 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431912 if (!delegate_)
1913 return;
1914
[email protected]0d9989d2011-12-21 20:26:001915 WebIntentsDispatcherImpl* intents_dispatcher =
1916 new WebIntentsDispatcherImpl(this, intent, intent_id);
1917 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301918}
1919
[email protected]54047eb52012-05-08 21:45:571920void WebContentsImpl::DidStartProvisionalLoadForFrame(
1921 content::RenderViewHost* render_view_host,
1922 int64 frame_id,
1923 bool is_main_frame,
1924 const GURL& opener_url,
1925 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281926 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181927 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451928 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571929 content::RenderProcessHost* render_process_host =
1930 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541931 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571932 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451933 false,
[email protected]9f76c1e2012-03-05 15:15:581934 &validated_url);
[email protected]ef108e72012-06-20 14:03:541935 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571936 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451937 true,
1938 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181939
[email protected]0d60f0192011-04-14 12:40:101940 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251941 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101942 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571943 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541944
1945 if (is_main_frame) {
1946 // Notify observers about the provisional change in the main frame URL.
1947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1948 ProvisionalChangeToMainFrameUrl(validated_url,
1949 validated_opener_url,
1950 render_view_host));
1951 }
1952}
1953
1954void WebContentsImpl::DidRedirectProvisionalLoad(
1955 content::RenderViewHost* render_view_host,
1956 int32 page_id,
1957 const GURL& opener_url,
1958 const GURL& source_url,
1959 const GURL& target_url) {
1960 // TODO(creis): Remove this method and have the pre-rendering code listen to
1961 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1962 // instead. See http://crbug.com/78512.
1963 GURL validated_source_url(source_url);
1964 GURL validated_target_url(target_url);
1965 GURL validated_opener_url(opener_url);
1966 content::RenderProcessHost* render_process_host =
1967 render_view_host->GetProcess();
1968 RenderViewHostImpl::FilterURL(
1969 ChildProcessSecurityPolicyImpl::GetInstance(),
1970 render_process_host->GetID(),
1971 false,
1972 &validated_source_url);
1973 RenderViewHostImpl::FilterURL(
1974 ChildProcessSecurityPolicyImpl::GetInstance(),
1975 render_process_host->GetID(),
1976 false,
1977 &validated_target_url);
1978 RenderViewHostImpl::FilterURL(
1979 ChildProcessSecurityPolicyImpl::GetInstance(),
1980 render_process_host->GetID(),
1981 true,
1982 &validated_opener_url);
1983 NavigationEntry* entry;
1984 if (page_id == -1) {
1985 entry = controller_.GetPendingEntry();
1986 } else {
1987 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1988 page_id);
1989 }
1990 if (!entry || entry->GetURL() != validated_source_url)
1991 return;
1992
1993 // Notify observers about the provisional change in the main frame URL.
1994 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1995 ProvisionalChangeToMainFrameUrl(validated_target_url,
1996 validated_opener_url,
1997 render_view_host));
[email protected]724159a2010-12-30 01:11:181998}
1999
[email protected]54047eb52012-05-08 21:45:572000void WebContentsImpl::DidFailProvisionalLoadWithError(
2001 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582002 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2003 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2004 << ", error_code: " << params.error_code
2005 << ", error_description: " << params.error_description
2006 << ", is_main_frame: " << params.is_main_frame
2007 << ", showing_repost_interstitial: " <<
2008 params.showing_repost_interstitial
2009 << ", frame_id: " << params.frame_id;
2010 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:572011 content::RenderProcessHost* render_process_host =
2012 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542013 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572014 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452015 false,
[email protected]9f76c1e2012-03-05 15:15:582016 &validated_url);
[email protected]724159a2010-12-30 01:11:182017
[email protected]d7b175e2011-10-11 15:31:582018 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182019 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2020 // This means that the interstitial won't be torn down properly, which is
2021 // bad. But if we have an interstitial, go back to another tab type, and
2022 // then load the same interstitial again, we could end up getting the first
2023 // interstitial's "failed" message (as a result of the cancel) when we're on
2024 // the second one.
2025 //
2026 // We can't tell this apart, so we think we're tearing down the current page
2027 // which will cause a crash later one. There is also some code in
2028 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2029 // out because of this problem.
2030 //
2031 // http://code.google.com/p/chromium/issues/detail?id=2855
2032 // Because this will not tear down the interstitial properly, if "back" is
2033 // back to another tab type, the interstitial will still be somewhat alive
2034 // in the previous tab type. If you navigate somewhere that activates the
2035 // tab with the interstitial again, you'll see a flash before the new load
2036 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272037 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182038 LOG(WARNING) << "Discarding message during interstitial.";
2039 return;
2040 }
2041
[email protected]a16690732012-07-13 19:22:172042 // Do not clear the pending entry if one exists, so that the user's typed
2043 // URL is not lost when a navigation fails or is aborted. We'll allow
2044 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182045
[email protected]54047eb52012-05-08 21:45:572046 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182047 }
2048
[email protected]d8c660432011-12-22 20:51:252049 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582050 observers_,
2051 DidFailProvisionalLoad(params.frame_id,
2052 params.is_main_frame,
2053 validated_url,
2054 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462055 params.error_description,
2056 render_view_host));
[email protected]724159a2010-12-30 01:11:182057}
2058
[email protected]b172aee2012-04-10 17:05:262059void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182060 const GURL& url,
[email protected]70435962011-08-02 20:13:282061 const std::string& security_info,
2062 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182063 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282064 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192065 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182066 cache.Increment();
2067
2068 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082069 int cert_id = 0;
2070 net::CertStatus cert_status = 0;
2071 int security_bits = -1;
2072 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512073 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2074 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002075 content::LoadFromMemoryCacheDetails details(
2076 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2077 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182078
[email protected]ad50def52011-10-19 23:17:072079 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272080 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502081 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002082 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382086 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182087 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192088 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182089}
2090
[email protected]b172aee2012-04-10 17:05:262091void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022092 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232093 LOG(INFO) << security_origin << " ran insecure content from "
2094 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382095 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412096 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2097 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182098 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412099 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192100 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182101}
2102
[email protected]b172aee2012-04-10 17:05:262103void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182104 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252105 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472106 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312110 int64 frame_id,
2111 const GURL& validated_url,
2112 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252113 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472114 DidFinishLoad(frame_id, validated_url, is_main_frame,
2115 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312116}
2117
[email protected]b172aee2012-04-10 17:05:262118void WebContentsImpl::OnDidFailLoadWithError(
2119 int64 frame_id,
2120 const GURL& validated_url,
2121 bool is_main_frame,
2122 int error_code,
2123 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252124 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312125 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472126 error_code, error_description,
2127 message_source_));
[email protected]724159a2010-12-30 01:11:182128}
2129
[email protected]b172aee2012-04-10 17:05:262130void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272131 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432132 if (delegate_)
2133 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262137 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232138 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252139 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262140 if (!entry)
2141 return;
2142 // Note that we don't call NavigationController::GotToOffset() as we don't
2143 // want to create a pending navigation entry (it might end up lingering
2144 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252145 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582146 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512147 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582148 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472149 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572150
2151 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2152 // it in now that we know. This allows us to find the entry when it commits.
2153 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232154 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332155 entry->set_site_instance(
2156 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572157 }
[email protected]216813952011-05-19 22:21:262158 }
2159}
2160
[email protected]b172aee2012-04-10 17:05:262161void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2162 int maximum_percent,
2163 bool remember) {
[email protected]216813952011-05-19 22:21:262164 minimum_zoom_percent_ = minimum_percent;
2165 maximum_zoom_percent_ = maximum_percent;
2166 temporary_zoom_settings_ = !remember;
2167}
2168
[email protected]20b433a2012-05-15 21:23:462169void WebContentsImpl::OnSaveURL(const GURL& url,
2170 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482171 download_stats::RecordDownloadSource(
2172 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262173 // Check if the URL to save matches the URL of the main frame. Since this
2174 // message originates from Pepper plugins, it may not be the case if the
2175 // plugin is an embedded element.
2176 GURL main_frame_url = GetURL();
2177 if (!main_frame_url.is_valid())
2178 return;
2179 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462180 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272181}
2182
[email protected]b172aee2012-04-10 17:05:262183void WebContentsImpl::OnEnumerateDirectory(int request_id,
2184 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432185 if (!delegate_)
2186 return;
2187
[email protected]b9535422012-02-09 01:47:592188 ChildProcessSecurityPolicyImpl* policy =
2189 ChildProcessSecurityPolicyImpl::GetInstance();
2190 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2191 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212192}
2193
[email protected]b172aee2012-04-10 17:05:262194void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432195 if (delegate_)
2196 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202197}
2198
[email protected]b172aee2012-04-10 17:05:262199void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2200 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362201 const string16& title,
2202 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432203 if (!delegate_)
2204 return;
2205
[email protected]b9535422012-02-09 01:47:592206 ChildProcessSecurityPolicyImpl* policy =
2207 ChildProcessSecurityPolicyImpl::GetInstance();
2208 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2209 return;
[email protected]3a3b75a2012-06-01 08:38:362210 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202211}
2212
[email protected]b172aee2012-04-10 17:05:262213void WebContentsImpl::OnFindReply(int request_id,
2214 int number_of_matches,
2215 const gfx::Rect& selection_rect,
2216 int active_match_ordinal,
2217 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432218 if (delegate_) {
2219 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2220 active_match_ordinal, final_update);
2221 }
[email protected]b888919c2011-09-02 00:32:162222}
2223
[email protected]59363fc92012-09-05 03:46:312224#if defined(OS_ANDROID)
2225void WebContentsImpl::OnFindMatchRectsReply(
2226 int version,
2227 const std::vector<gfx::RectF>& rects,
2228 const gfx::RectF& active_rect) {
2229 if (delegate_)
2230 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2231}
2232#endif
2233
[email protected]b172aee2012-04-10 17:05:262234void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442235 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2236 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452237}
2238
[email protected]b172aee2012-04-10 17:05:262239void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2240 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102241 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252242 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102243 AppCacheAccessed(manifest_url, blocked_by_policy));
2244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322247 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432248 color_chooser_ = delegate_ ?
2249 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202253 if (color_chooser_ &&
2254 color_chooser_id == color_chooser_->identifier())
2255 color_chooser_->End();
2256}
2257
[email protected]b172aee2012-04-10 17:05:262258void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322259 SkColor color) {
[email protected]da8543762012-03-20 08:52:202260 if (color_chooser_ &&
2261 color_chooser_id == color_chooser_->identifier())
2262 color_chooser_->SetSelectedColor(color);
2263}
2264
[email protected]9f2a9d72012-04-16 16:02:222265void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2266 const FilePath& path,
2267 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442268 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2269 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292270}
2271
[email protected]d0759f492012-04-19 22:50:502272// This exists for render views that don't have a WebUI, but do have WebUI
2273// bindings enabled.
2274void WebContentsImpl::OnWebUISend(const GURL& source_url,
2275 const std::string& name,
2276 const base::ListValue& args) {
2277 if (delegate_)
2278 delegate_->WebUISend(this, source_url, name, args);
2279}
2280
[email protected]d8415ad92012-08-23 14:40:502281void WebContentsImpl::OnRequestPpapiBrokerPermission(
2282 int request_id,
2283 const GURL& url,
2284 const FilePath& plugin_path) {
2285 base::Callback<void(bool)> callback =
2286 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2287 base::Unretained(this), request_id);
2288 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2289 WebContentsObserver* observer;
2290 while ((observer = it.GetNext()) != NULL) {
2291 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2292 callback))
2293 return;
2294 }
2295
2296 // Fall back to allowing the request if no observer handled it.
2297 OnPpapiBrokerPermissionResult(request_id, true);
2298}
2299
2300void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2301 bool result) {
2302 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2303 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2304 request_id,
2305 result));
2306}
2307
[email protected]96d185d2009-04-24 03:28:542308// Notifies the RenderWidgetHost instance about the fact that the page is
2309// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262310void WebContentsImpl::SetIsLoading(bool is_loading,
2311 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542312 if (is_loading == is_loading_)
2313 return;
2314
2315 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212316 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542317 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562318 upload_size_ = 0;
2319 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542320 }
2321
2322 render_manager_.SetIsLoading(is_loading);
2323
2324 is_loading_ = is_loading;
2325 waiting_for_response_ = is_loading;
2326
[email protected]6ebdc9b2010-09-27 16:55:572327 if (delegate_)
2328 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462329 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542330
[email protected]432115822011-07-10 15:52:272331 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2332 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072333 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542334 if (details)
[email protected]6c2381d2011-10-19 02:52:532335 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072336 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502337 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542338 det);
2339}
2340
[email protected]b172aee2012-04-10 17:05:262341void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132342 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322343 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562344 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382345 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442346 // that opened the window, as long as both renderers have the same
2347 // privileges.
[email protected]1fd1a502011-03-30 16:55:562348 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562349 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582350 // web_ui might be NULL if the URL refers to a non-existent extension.
2351 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402352 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522353 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442354 }
2355 }
[email protected]1fd1a502011-03-30 16:55:562356 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442357 }
2358
[email protected]4e697b042011-07-08 06:44:562359 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322360 // Clear the status bubble. This is a workaround for a bug where WebKit
2361 // doesn't let us know that the cursor left an element during a
2362 // transition (this is also why the mouse cursor remains as a hand after
2363 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2364 // clear the bubble when a user navigates to a named anchor in the same
2365 // page.
[email protected]36fc0392011-12-25 03:59:512366 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322367 }
2368
[email protected]a6e82fc2010-02-24 22:28:142369 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472370 // Once the main frame is navigated, we're no longer considered to have
2371 // displayed insecure content.
2372 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172373 }
[email protected]ce5c4502009-05-06 16:46:112374
[email protected]3c9e1872010-11-18 16:17:492375 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252376 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042377 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322378}
2379
[email protected]b172aee2012-04-10 17:05:262380void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322381 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132382 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322383 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062384 // If we navigate off the page, reset JavaScript state. This does nothing
2385 // to prevent a malicious script from spamming messages, since the script
2386 // could just reload the page to stop blocking.
2387 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552388 dialog_creator_->ResetJavaScriptState(this);
2389 dialog_creator_ = NULL;
2390 }
[email protected]420ae012009-04-24 05:16:322391
[email protected]3c9e1872010-11-18 16:17:492392 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252393 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042394 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322395}
2396
[email protected]b172aee2012-04-10 17:05:262397void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462398 // If we are creating a RVH for a restored controller, then we need to make
2399 // sure the RenderView starts with a next_page_id_ larger than the number
2400 // of restored entries. This must be called before the RenderView starts
2401 // navigating (to avoid a race between the browser updating max_page_id and
2402 // the renderer updating next_page_id_). Because of this, we only call this
2403 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562404 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582405 if (max_restored_page_id >
2406 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2407 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2408 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322409}
2410
[email protected]b172aee2012-04-10 17:05:262411bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2412 const string16& title) {
[email protected]420ae012009-04-24 05:16:322413 // For file URLs without a title, use the pathname instead. In the case of a
2414 // synthesized title, we don't want the update to count toward the "one set
2415 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512416 string16 final_title;
[email protected]420ae012009-04-24 05:16:322417 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512418 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2419 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322420 explicit_set = false; // Don't count synthetic titles toward the set limit.
2421 } else {
[email protected]acafd272011-07-26 17:35:572422 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322423 explicit_set = true;
2424 }
2425
[email protected]987fc3a2011-05-26 14:18:092426 // If a page is created via window.open and never navigated,
2427 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552428 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092429 if (entry) {
[email protected]36fc0392011-12-25 03:59:512430 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092431 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322432
[email protected]36fc0392011-12-25 03:59:512433 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092434 } else {
2435 if (page_title_when_no_navigation_entry_ == final_title)
2436 return false; // Nothing changed, don't bother.
2437
2438 page_title_when_no_navigation_entry_ = final_title;
2439 }
[email protected]420ae012009-04-24 05:16:322440
[email protected]420ae012009-04-24 05:16:322441 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232442 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322443
[email protected]2bb171882012-03-07 02:09:462444 std::pair<content::NavigationEntry*, bool> details =
2445 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142446
[email protected]ad50def52011-10-19 23:17:072447 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442448 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2449 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462450 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042451
[email protected]420ae012009-04-24 05:16:322452 return true;
2453}
2454
[email protected]b172aee2012-04-10 17:05:262455void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322456 // After sending out a swap notification, we need to send a disconnect
2457 // notification so that clients that pick up a pointer to |this| can NULL the
2458 // pointer. See Bug 1230284.
2459 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072460 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202461 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2462 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072463 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322464}
2465
[email protected]b172aee2012-04-10 17:05:262466void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322467 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072468 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122469 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2470 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072471 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322472}
2473
[email protected]b172aee2012-04-10 17:05:262474void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322475 if (!notify_disconnection_)
2476 return;
2477
2478 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072479 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322480 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2481 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072482 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322483}
2484
[email protected]5a3bdf52012-05-24 15:12:572485RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2486 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322487}
2488
[email protected]8d3347f2009-07-09 22:00:212489RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262490WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212491 return &render_manager_;
2492}
2493
[email protected]b172aee2012-04-10 17:05:262494content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372495 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462496 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512497}
2498
[email protected]b172aee2012-04-10 17:05:262499WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172500 return this;
2501}
2502
[email protected]b172aee2012-04-10 17:05:262503gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172504 if (delegate_)
2505 return delegate_->GetRootWindowResizerRect();
2506 return gfx::Rect();
2507}
2508
[email protected]b172aee2012-04-10 17:05:262509void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442510 // Don't send notifications if we are just creating a swapped-out RVH for
2511 // the opener chain. These won't be used for view-source or WebUI, so it's
2512 // ok to return early.
2513 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2514 return;
2515
[email protected]ad50def52011-10-19 23:17:072516 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302517 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322518 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532519 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232520 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322521 if (!entry)
2522 return;
2523
2524 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352525 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562526 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582527 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322528
2529 if (entry->IsViewSourceMode()) {
2530 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182531 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582532 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322533 }
[email protected]0666aef2009-05-13 19:48:082534
[email protected]d487beefe2011-12-21 05:41:212535 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262536
2537 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252538 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322539}
2540
[email protected]b172aee2012-04-10 17:05:262541void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522542 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322543 // Don't notify the world, since this came from a renderer in the
2544 // background.
2545 return;
2546 }
2547
2548 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312549 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232550 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302551
2552 // Restore the focus to the tab (otherwise the focus will be on the top
2553 // window).
[email protected]484ae5912010-09-29 19:16:142554 if (was_crashed && !FocusLocationBarByDefault() &&
2555 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302556 Focus();
[email protected]484ae5912010-09-29 19:16:142557 }
[email protected]32ded2212011-11-10 18:51:432558
[email protected]d8c660432011-12-22 20:51:252559 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322560}
2561
[email protected]b172aee2012-04-10 17:05:262562void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2563 base::TerminationStatus status,
2564 int error_code) {
[email protected]151a63d2011-12-20 22:32:522565 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322566 // The pending page's RenderViewHost is gone.
2567 return;
2568 }
2569
2570 SetIsLoading(false, NULL);
2571 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232572 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312573 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322574
[email protected]d8c660432011-12-22 20:51:252575 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272576 observers_,
[email protected]be1f56ab2011-12-22 06:55:312577 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322578}
2579
[email protected]b172aee2012-04-10 17:05:262580void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482581 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252582 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062583}
2584
[email protected]b172aee2012-04-10 17:05:262585void WebContentsImpl::DidNavigate(
2586 RenderViewHost* rvh,
2587 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582588 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322589 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372590
[email protected]434f69f2012-02-06 21:56:522591 // Update the site of the SiteInstance if it doesn't have one yet, unless
2592 // this is for about:blank. In that case, the SiteInstance can still be
2593 // considered unused until a navigation to a real page.
2594 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2595 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332596 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522597 }
[email protected]420ae012009-04-24 05:16:322598
2599 // Need to update MIME type here because it's referred to in
2600 // UpdateNavigationCommands() called by RendererDidNavigate() to
2601 // determine whether or not to enable the encoding menu.
2602 // It's updated only for the main frame. For a subframe,
2603 // RenderView::UpdateURL does not set params.contents_mime_type.
2604 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2605 // TODO(jungshik): Add a test for the encoding menu to avoid
2606 // regressing it again.
[email protected]2905f742011-10-13 03:51:582607 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322608 contents_mime_type_ = params.contents_mime_type;
2609
[email protected]8286f51a2011-05-31 17:39:132610 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002611 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392612
[email protected]a9c0bfe2010-09-17 08:35:222613 // Send notification about committed provisional loads. This notification is
2614 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2615 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082616 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072617 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2618 // that is not recorded in the navigation history. For the purpose of
2619 // tracking navigation events, we treat this event as a sub frame navigation
2620 // event.
2621 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582622 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222623 // Whether or not a page transition was triggered by going backward or
2624 // forward in the history is only stored in the navigation controller's
2625 // entry list.
2626 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512627 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582628 content::PAGE_TRANSITION_FORWARD_BACK)) {
2629 transition_type = content::PageTransitionFromInt(
2630 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222631 }
[email protected]0d60f0192011-04-14 12:40:102632 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252633 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102634 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462635 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222636 }
2637
[email protected]76543b92009-08-31 17:27:452638 if (!did_navigate)
2639 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322640
2641 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2642 // for the appropriate notification (best) or you can add it to
2643 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2644 // necessary, please).
2645
2646 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002647 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322648 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512649 if (delegate_)
2650 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002651 }
[email protected]420ae012009-04-24 05:16:322652 DidNavigateAnyFramePostCommit(rvh, details, params);
2653}
2654
[email protected]b172aee2012-04-10 17:05:262655void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2656 int32 page_id,
2657 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152658 // Ensure that this state update comes from either the active RVH or one of
2659 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522660 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322661
2662 // We must be prepared to handle state updates for any page, these occur
2663 // when the user is scrolling and entering form data, as well as when we're
2664 // leaving a page, in which case our state may have already been moved to
2665 // the next page. The navigation controller will look up the appropriate
2666 // NavigationEntry and update it when it is notified via the delegate.
2667
2668 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582669 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322670 if (entry_index < 0)
2671 return;
[email protected]10f417c52011-12-28 21:04:232672 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322673
[email protected]36fc0392011-12-25 03:59:512674 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322675 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512676 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322677 controller_.NotifyEntryChanged(entry, entry_index);
2678}
2679
[email protected]b172aee2012-04-10 17:05:262680void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2681 int32 page_id,
2682 const string16& title,
2683 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322684 // If we have a title, that's a pretty good indication that we've started
2685 // getting useful data.
2686 SetNotWaitingForResponse();
2687
[email protected]73eb2602012-02-09 19:50:552688 // Try to find the navigation entry, which might not be the current one.
2689 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232690 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582691 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092692
[email protected]73eb2602012-02-09 19:50:552693 // We can handle title updates when we don't have an entry in
2694 // UpdateTitleForEntry, but only if the update is from the current RVH.
2695 if (!entry && rvh != GetRenderViewHost())
2696 return;
2697
[email protected]a49e10b2011-08-01 23:57:462698 // TODO(evan): make use of title_direction.
2699 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092700 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322701 return;
2702
2703 // Broadcast notifications when the UI should be updated.
2704 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462705 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322706}
2707
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2709 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312710 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322711}
2712
[email protected]b172aee2012-04-10 17:05:262713void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512714 if (delegate_)
2715 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322716}
2717
[email protected]b172aee2012-04-10 17:05:262718void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292719 // The UI may be in an event-tracking loop, such as between the
2720 // mouse-down and mouse-up in text selection or a button click.
2721 // Defer the close until after tracking is complete, so that we
2722 // don't free objects out from under the UI.
2723 // TODO(shess): This could probably be integrated with the
2724 // IsDoingDrag() test below. Punting for now because I need more
2725 // research to understand how this impacts platforms other than Mac.
2726 // TODO(shess): This could get more fine-grained. For instance,
2727 // closing a tab in another window while selecting text in the
2728 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212729 if (GetView()->IsEventTracking()) {
2730 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292731 return;
2732 }
2733
[email protected]24a4d1062009-07-10 23:10:422734 // If we close the tab while we're in the middle of a drag, we'll crash.
2735 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212736 if (GetView()->IsDoingDrag()) {
2737 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422738 return;
2739 }
2740
[email protected]420ae012009-04-24 05:16:322741 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522742 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512743 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322744}
2745
[email protected]b172aee2012-04-10 17:05:262746void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522747 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512748 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572749}
2750
[email protected]b172aee2012-04-10 17:05:262751void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512752 if (delegate_ && delegate_->IsPopupOrPanel(this))
2753 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322754}
2755
[email protected]89793072012-07-23 22:25:292756void WebContentsImpl::DidStartLoading(
2757 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322758 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492759
[email protected]82114f52012-03-20 22:53:412760 if (delegate_ && content_restrictions_)
2761 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492762
2763 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292764 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2765 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322766}
2767
[email protected]89793072012-07-23 22:25:292768void WebContentsImpl::DidStopLoading(
2769 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322770 scoped_ptr<LoadNotificationDetails> details;
2771
[email protected]10f417c52011-12-28 21:04:232772 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322773 // An entry may not exist for a stop when loading an initial blank page or
2774 // if an iframe injected by script into a blank page finishes loading.
2775 if (entry) {
[email protected]420ae012009-04-24 05:16:322776 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2777
2778 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512779 entry->GetVirtualURL(),
2780 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322781 elapsed,
2782 &controller_,
2783 controller_.GetCurrentEntryIndex()));
2784 }
2785
[email protected]420ae012009-04-24 05:16:322786 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492787
2788 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292789 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2790 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322791}
2792
[email protected]b172aee2012-04-10 17:05:262793void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162794 controller_.DiscardNonCommittedEntries();
2795
2796 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462797 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162798}
2799
[email protected]b172aee2012-04-10 17:05:262800void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512801 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132802 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402803}
2804
[email protected]0720b532012-08-28 19:23:372805void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2806 render_manager_.DidUpdateFrameTree(rvh);
2807}
2808
[email protected]87717d0e2012-04-26 02:58:432809void WebContentsImpl::DocumentAvailableInMainFrame(
2810 RenderViewHost* render_view_host) {
2811 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2812 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102813}
2814
[email protected]b172aee2012-04-10 17:05:262815void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082816 RenderViewHost* render_view_host,
2817 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072818 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272819 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322820 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532821 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082822}
2823
[email protected]196159d2012-05-04 17:26:542824void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2825 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262826 const content::Referrer& referrer,
2827 WindowOpenDisposition disposition,
2828 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542829 // If this came from a swapped out RenderViewHost, we only allow the request
2830 // if we are still in the same BrowsingInstance.
2831 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2832 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2833 return;
2834 }
2835
[email protected]4ad5d77d2011-12-03 02:00:482836 // Delegate to RequestTransferURL because this is just the generic
2837 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582838 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482839 GlobalRequestID());
2840}
2841
[email protected]b172aee2012-04-10 17:05:262842void WebContentsImpl::RequestTransferURL(
2843 const GURL& url,
2844 const content::Referrer& referrer,
2845 WindowOpenDisposition disposition,
2846 int64 source_frame_id,
2847 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202848 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582849 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582850 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352851 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322852 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2853 // generated suggestions).
2854 //
[email protected]e0112912011-02-02 22:54:352855 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162856 // want web sites to see a referrer of "chrome://blah" (and some
2857 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322858 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432859 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222860 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482861 false /* is_renderer_initiated */);
2862 params.transferred_global_request_id = old_request_id;
2863 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222864 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322865 } else {
[email protected]6bf6a6b52012-02-03 15:41:432866 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482867 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2868 params.transferred_global_request_id = old_request_id;
2869 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582870 }
2871 if (new_contents) {
2872 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252873 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582874 DidOpenRequestedURL(new_contents,
2875 url,
2876 referrer,
2877 disposition,
2878 transition_type,
2879 source_frame_id));
[email protected]420ae012009-04-24 05:16:322880 }
2881}
2882
[email protected]e1c3a552012-05-04 20:51:322883void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2884 // Tell the active RenderViewHost to run unload handlers and close, as long
2885 // as the request came from a RenderViewHost in the same BrowsingInstance.
2886 // In most cases, we receive this from a swapped out RenderViewHost.
2887 // It is possible to receive it from one that has just been swapped in,
2888 // in which case we might as well deliver the message anyway.
2889 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2890 GetRenderViewHost()->ClosePage();
2891}
2892
[email protected]f546640b2012-05-15 00:03:492893void WebContentsImpl::RouteMessageEvent(
2894 RenderViewHost* rvh,
2895 const ViewMsg_PostMessage_Params& params) {
2896 // Only deliver the message to the active RenderViewHost if the request
2897 // came from a RenderViewHost in the same BrowsingInstance.
2898 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2899 return;
2900
2901 ViewMsg_PostMessage_Params new_params(params);
2902
[email protected]0720b532012-08-28 19:23:372903 // If the renderer has changed while the post message is being routed,
2904 // drop the message, as it will not be delivered to the right target.
2905 if (GetRenderViewHost()->GetProcess()->GetID() != params.target_process_id)
2906 return;
2907 DCHECK(params.target_frame_id != 0);
2908
[email protected]f546640b2012-05-15 00:03:492909 // If there is a source_routing_id, translate it to the routing ID for
2910 // the equivalent swapped out RVH in the target process. If we need
2911 // to create a swapped out RVH for the source tab, we create its opener
2912 // chain as well, since those will also be accessible to the target page.
2913 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2914 // Try to look up the WebContents for the source page.
2915 WebContentsImpl* source_contents = NULL;
2916 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2917 rvh->GetProcess()->GetID(), params.source_routing_id);
2918 if (source_rvh) {
2919 source_contents = static_cast<WebContentsImpl*>(
2920 source_rvh->GetDelegate()->GetAsWebContents());
2921 }
2922
2923 if (source_contents) {
2924 new_params.source_routing_id =
2925 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2926 } else {
2927 // We couldn't find it, so don't pass a source frame.
2928 new_params.source_routing_id = MSG_ROUTING_NONE;
2929 }
2930 }
2931
2932 // In most cases, we receive this from a swapped out RenderViewHost.
2933 // It is possible to receive it from one that has just been swapped in,
2934 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182935 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492936}
2937
[email protected]b172aee2012-04-10 17:05:262938void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342939 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412940 const string16& message,
2941 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322942 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142943 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322944 IPC::Message* reply_msg,
2945 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072946 // Suppress JavaScript dialogs when requested. Also suppress messages when
2947 // showing an interstitial as it's shown over the previous page and we don't
2948 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502949 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582950 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272951 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072952 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522953 delegate_->ShouldSuppressDialogs() ||
2954 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322955
2956 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432957 std::string accept_lang = content::GetContentClient()->browser()->
2958 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552959 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522960 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432961 this,
2962 frame_url.GetOrigin(),
2963 accept_lang,
2964 javascript_message_type,
2965 message,
[email protected]51da7e32012-01-30 19:24:522966 default_prompt,
[email protected]b172aee2012-04-10 17:05:262967 base::Bind(&WebContentsImpl::OnDialogClosed,
2968 base::Unretained(this),
2969 rvh,
2970 reply_msg),
[email protected]51da7e32012-01-30 19:24:522971 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322972 }
[email protected]3ab9cb82011-06-03 18:02:072973
2974 if (suppress_this_message) {
2975 // If we are suppressing messages, just reply as if the user immediately
2976 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342977 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072978 }
2979
2980 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322981}
2982
[email protected]b172aee2012-04-10 17:05:262983void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2984 const string16& message,
2985 bool is_reload,
2986 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582987 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512988 if (delegate_)
2989 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072990
2991 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582992 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072993 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522994 delegate_->ShouldSuppressDialogs() ||
2995 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152996 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342997 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582998 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502999 return;
3000 }
[email protected]3ab9cb82011-06-03 18:02:073001
[email protected]7ab1e7d62009-10-14 23:32:013002 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553003 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523004 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323005 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263006 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523007 reply_msg));
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]a796f202012-05-30 14:14:253010bool WebContentsImpl::AddMessageToConsole(int32 level,
3011 const string16& message,
3012 int32 line_no,
3013 const string16& source_id) {
3014 if (!delegate_)
3015 return false;
3016 return delegate_->AddMessageToConsole(this, level, message, line_no,
3017 source_id);
3018}
3019
[email protected]b172aee2012-04-10 17:05:263020WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333021 // We want to base the page config off of the real URL, rather than the
3022 // display URL.
3023 GURL url = controller_.GetActiveEntry()
3024 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3025 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323026}
3027
[email protected]b172aee2012-04-10 17:05:263028void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273029 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253030 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223031
[email protected]ea114722012-03-12 01:11:253032 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173033 if (rdh) // NULL in unittests.
3034 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253035}
3036
[email protected]b172aee2012-04-10 17:05:263037void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443038 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253039 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443040}
3041
[email protected]b172aee2012-04-10 17:05:263042void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3043 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153044 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523045 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153046 return;
3047
[email protected]9f76c1e2012-03-05 15:15:583048 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3049
[email protected]e5fc1632011-08-08 07:51:533050 // Ignore renderer unresponsive event if debugger is attached to the tab
3051 // since the event may be a result of the renderer sitting on a breakpoint.
3052 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443053 DevToolsAgentHost* agent =
3054 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3055 if (agent &&
3056 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533057 return;
3058
[email protected]420ae012009-04-24 05:16:323059 if (is_during_unload) {
3060 // Hang occurred while firing the beforeunload/unload handler.
3061 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583062 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323063
3064 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3065 return;
3066
3067 // If the tab hangs in the beforeunload/unload handler there's really
3068 // nothing we can do to recover. Pretend the unload listeners have
3069 // all fired and close the tab. If the hang is in the beforeunload handler
3070 // then the user will not have the option of cancelling the close.
3071 Close(rvh);
3072 return;
3073 }
3074
[email protected]9f76c1e2012-03-05 15:15:583075 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473076 return;
3077
[email protected]6934a702011-12-20 00:04:513078 if (delegate_)
3079 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323080}
3081
[email protected]b172aee2012-04-10 17:05:263082void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513083 if (delegate_)
3084 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323085}
3086
[email protected]b172aee2012-04-10 17:05:263087void WebContentsImpl::LoadStateChanged(
3088 const GURL& url,
3089 const net::LoadStateWithParam& load_state,
3090 uint64 upload_position,
3091 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323092 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563093 upload_position_ = upload_position;
3094 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503095 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203096 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303097 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213098 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323099 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463100 if (IsLoading()) {
3101 NotifyNavigationStateChanged(
3102 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3103 }
[email protected]420ae012009-04-24 05:16:323104}
3105
[email protected]b172aee2012-04-10 17:05:263106void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513107 if (delegate_)
3108 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323112 bool proceed,
3113 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513114 if (delegate_)
3115 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323116}
3117
[email protected]b172aee2012-04-10 17:05:263118void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543119 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233120 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3121 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543122}
3123
[email protected]b172aee2012-04-10 17:05:263124void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103125 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263126 gfx::Size size = view_->GetContainerSize();
3127 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3128 // here during container initialization and normal window size will be set
3129 // later. In case of tab duplication this resizing to 0x0 prevents setting
3130 // normal size later so just ignore it.
3131 if (!size.IsEmpty())
3132 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323133}
3134
[email protected]b172aee2012-04-10 17:05:263135void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543136 NotifySwapped();
3137}
3138
[email protected]14392a52012-05-02 20:28:443139int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3140 SiteInstance* instance) {
3141 if (!opener_)
3142 return MSG_ROUTING_NONE;
3143
3144 // Recursively create RenderViews for anything else in the opener chain.
3145 return opener_->CreateOpenerRenderViews(instance);
3146}
3147
3148int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3149 int opener_route_id = MSG_ROUTING_NONE;
3150
3151 // If this tab has an opener, ensure it has a RenderView in the given
3152 // SiteInstance as well.
3153 if (opener_)
3154 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3155
[email protected]0720b532012-08-28 19:23:373156 // If any of the renderers for this WebContents has the same SiteInstance,
3157 // use it.
3158 if (render_manager_.current_host()->GetSiteInstance() == instance)
3159 return render_manager_.current_host()->GetRoutingID();
3160
3161 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3162 instance);
3163 if (rvh)
3164 return rvh->GetRoutingID();
3165
[email protected]14392a52012-05-02 20:28:443166 // Create a swapped out RenderView in the given SiteInstance if none exists,
3167 // setting its opener to the given route_id. Return the new view's route_id.
3168 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3169}
3170
[email protected]b172aee2012-04-10 17:05:263171NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193172 return GetController();
[email protected]3a3d47472010-07-15 21:03:543173}
3174
[email protected]b172aee2012-04-10 17:05:263175WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563176 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323177}
3178
[email protected]10f417c52011-12-28 21:04:233179NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263180 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323181 return controller_.GetLastCommittedEntry();
3182}
3183
[email protected]b172aee2012-04-10 17:05:263184bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443185 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443186 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323187 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523188
[email protected]420ae012009-04-24 05:16:323189 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443190 if (rwh_view)
3191 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323192
[email protected]74ce1ad2011-12-16 21:51:463193 // Make sure we use the correct starting page_id in the new RenderView.
3194 UpdateMaxPageIDIfNecessary(render_view_host);
3195 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583196 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463197
[email protected]7900bfdb2012-05-24 19:31:243198 std::string embedder_channel_name;
3199 int embedder_container_id;
3200 GetBrowserPluginEmbedderInfo(render_view_host,
3201 &embedder_channel_name,
3202 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583203 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493204 render_view_host)->CreateRenderView(string16(),
3205 opener_route_id,
3206 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243207 embedder_channel_name,
3208 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523209 return false;
[email protected]14392a52012-05-02 20:28:443210 }
[email protected]a4127722011-04-27 23:13:523211
[email protected]e60c0232011-11-11 19:56:353212#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503213 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3214 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443215 if (rwh_view) {
3216 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3217 render_widget_host->WasResized();
3218 }
[email protected]f8233cc2011-05-31 20:24:503219#endif
3220
[email protected]420ae012009-04-24 05:16:323221 return true;
3222}
3223
[email protected]b172aee2012-04-10 17:05:263224void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3225 IPC::Message* reply_msg,
3226 bool success,
3227 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543228 if (is_showing_before_unload_dialog_ && !success) {
3229 // If a beforeunload dialog is canceled, we need to stop the throbber from
3230 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293231 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353232 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543233
[email protected]3bbacc5b2012-04-17 17:46:153234 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543235 }
3236 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583237 static_cast<RenderViewHostImpl*>(
3238 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543239}
3240
[email protected]b172aee2012-04-10 17:05:263241void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123242 encoding_ = content::GetContentClient()->browser()->
3243 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103244}
[email protected]f45d2a72010-03-08 23:28:353245
[email protected]b172aee2012-04-10 17:05:263246void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463247 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263248 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573249 DownloadManager* dlm =
3250 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143251 if (!dlm)
3252 return;
3253 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263254 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143255 const NavigationEntry* entry = controller_.GetActiveEntry();
3256 if (entry)
3257 post_id = entry->GetPostID();
3258 }
[email protected]29a5ffc82012-03-13 19:35:583259 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143260 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143261 scoped_ptr<DownloadUrlParameters> params(
3262 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493263 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143264 params->set_post_id(post_id);
3265 params->set_prefer_cache(true);
3266 if (post_id >= 0)
3267 params->set_method("POST");
3268 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143269}
3270
[email protected]b172aee2012-04-10 17:05:263271void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213272 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443273 // Can be NULL during tests.
3274 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213275 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363276}
[email protected]9f76c1e2012-03-05 15:15:583277
[email protected]b172aee2012-04-10 17:05:263278RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583279 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3280}
[email protected]7900bfdb2012-05-24 19:31:243281
3282void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3283 content::RenderViewHost* render_view_host,
3284 std::string* embedder_channel_name,
3285 int* embedder_container_id) {
3286 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283287 old_browser_plugin_host()->embedder_render_process_host();
3288 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243289 int embedder_process_id =
3290 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3291 if (embedder_process_id != -1) {
3292 *embedder_channel_name =
3293 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3294 embedder_process_id);
3295 }
3296}