blob: 43c12ae7d442c837bd295c798cf340206ed374e7 [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]2afdb072012-09-17 15:56:08493 prefs.accelerated_compositing_for_overflow_scroll_enabled =
494 command_line.HasSwitch(
495 switches::kEnableAcceleratedCompositingForOverflowScroll);
[email protected]8611a852012-05-23 22:11:19496 prefs.show_paint_rects =
497 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52498 prefs.render_vsync_enabled =
499 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54500 prefs.accelerated_compositing_enabled =
501 GpuProcessHost::gpu_enabled() &&
502 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54503 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23504 command_line.HasSwitch(switches::kForceCompositingMode) &&
505 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54506 prefs.fixed_position_compositing_enabled =
507 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
508 prefs.accelerated_2d_canvas_enabled =
509 GpuProcessHost::gpu_enabled() &&
510 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58511 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27512 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54513 prefs.accelerated_painting_enabled =
514 GpuProcessHost::gpu_enabled() &&
515 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
516 prefs.accelerated_filters_enabled =
517 GpuProcessHost::gpu_enabled() &&
518 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
519 prefs.accelerated_layers_enabled =
520 prefs.accelerated_animation_enabled =
521 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54522 prefs.accelerated_plugins_enabled =
523 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
524 prefs.accelerated_video_enabled =
525 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54526 prefs.fullscreen_enabled =
527 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43528 prefs.css_sticky_position_enabled =
529 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]37ac2a82012-03-01 05:30:16530 prefs.css_regions_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03531 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29532 prefs.css_shaders_enabled =
533 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01534 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03535 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]c71fe6402012-08-15 15:22:55536#if defined(USE_AURA) && defined(USE_X11)
537 prefs.device_supports_touch |=
538 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
539#endif
[email protected]25ee94f2012-09-11 19:16:16540#if defined(OS_WIN)
541 prefs.device_supports_touch = ui::IsTouchDevicePresent();
542#endif
[email protected]d849b122012-07-18 07:35:26543#if defined(OS_ANDROID)
544 prefs.device_supports_mouse = false;
545#endif
[email protected]64d69de42012-02-06 00:19:54546
547#if defined(OS_MACOSX)
548 bool default_enable_scroll_animator = true;
549#else
550 // On CrOS, the launcher always passes in the --enable flag.
551 bool default_enable_scroll_animator = false;
552#endif
553 prefs.enable_scroll_animator = default_enable_scroll_animator;
554 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
555 prefs.enable_scroll_animator = true;
556 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
557 prefs.enable_scroll_animator = false;
558
559 prefs.visual_word_movement_enabled =
560 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54561
562 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32563 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54564 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39565 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]d56ecf922012-02-15 16:03:11566 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54567 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11568 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54569 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19570 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
571 prefs.flash_3d_enabled = false;
572 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
573 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11574 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54575 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11576 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54577 prefs.gl_multisampling_enabled = false;
578
579 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45580 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32581 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54582 prefs.accelerated_video_enabled = false;
583 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45584 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09585 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54586 }
587 }
588
[email protected]b9535422012-02-09 01:47:59589 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58590 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54591 prefs.loads_images_automatically = true;
592 prefs.javascript_enabled = true;
593 }
594
595 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
596
597 // Force accelerated compositing and 2d canvas off for chrome:, about: and
598 // chrome-devtools: pages (unless it's specifically allowed).
599 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54600 url.SchemeIs(chrome::kChromeUIScheme) ||
601 (url.SchemeIs(chrome::kAboutScheme) &&
602 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25603 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54604 prefs.accelerated_compositing_enabled = false;
605 prefs.accelerated_2d_canvas_enabled = false;
606 }
[email protected]43d9d782012-03-01 15:40:09607
[email protected]f98f5092012-05-19 00:08:14608 if (command_line.HasSwitch(switches::kDefaultTileWidth))
609 prefs.default_tile_width =
610 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
611 if (command_line.HasSwitch(switches::kDefaultTileHeight))
612 prefs.default_tile_height =
613 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
614 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
615 prefs.max_untiled_layer_width =
616 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
617 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
618 prefs.max_untiled_layer_height =
619 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
620
[email protected]2486dce2012-05-23 17:18:19621 if (gfx::Screen::IsDIPEnabled()) {
622 // Only apply when using DIP coordinate system as this setting interferes
623 // with fixed layout mode.
624 prefs.apply_default_device_scale_factor_in_compositor = true;
625 }
626
[email protected]de023762012-07-26 17:10:17627 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
628 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10629
[email protected]e755a382012-09-13 17:16:35630 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
631 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12632
[email protected]6b4dcb072012-06-18 22:26:51633 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
634
[email protected]2e21fe292012-03-02 22:52:32635 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54636
637 return prefs;
638}
639
[email protected]b172aee2012-04-10 17:05:26640RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28641 return &render_manager_;
642}
643
[email protected]7bb761892012-07-20 09:32:47644bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
645 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56646 if (GetWebUI() &&
647 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17648 return true;
[email protected]d2353452012-01-19 19:53:56649 }
[email protected]f82d57b52011-04-27 19:13:17650
[email protected]d8c660432011-12-22 20:51:25651 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
652 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10653 while ((observer = it.GetNext()) != NULL)
654 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53655 return true;
[email protected]403415a2011-01-10 18:57:53656
[email protected]7bb761892012-07-20 09:32:47657 // Message handlers should be aware of which RenderViewHost sent the
658 // message, which is temporarily stored in message_source_.
659 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18660 bool handled = true;
661 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26662 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58663 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
664 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24665 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
666 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18667 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
668 OnDidLoadResourceFromMemoryCache)
669 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
670 OnDidDisplayInsecureContent)
671 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
672 OnDidRunInsecureContent)
673 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
674 OnDocumentLoadedInFrame)
675 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26676 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
677 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17678 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
679 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25680 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26681 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59682 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21683 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20684 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
685 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
686 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16687 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]59363fc92012-09-05 03:46:31688#if defined(OS_ANDROID)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
690 OnFindMatchRectsReply)
691#endif
[email protected]d952a052011-09-06 18:42:45692 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10693 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20694 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
695 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
696 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
697 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29698 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50699 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50700 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
701 OnRequestPpapiBrokerPermission)
[email protected]724159a2010-12-30 01:11:18702 IPC_MESSAGE_UNHANDLED(handled = false)
703 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47704 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18705
706 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38707 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18708 GetRenderProcessHost()->ReceivedBadMessage();
709 }
710
711 return handled;
712}
713
[email protected]b172aee2012-04-10 17:05:26714void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18715 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23716 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43717 if (delegate_)
718 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18719}
720
[email protected]d1198fd2012-08-13 22:50:19721NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56722 return controller_;
723}
724
[email protected]d1198fd2012-08-13 22:50:19725const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56726 return controller_;
727}
728
[email protected]b172aee2012-04-10 17:05:26729content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55730 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30731}
732
[email protected]b172aee2012-04-10 17:05:26733const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31734 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23735 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51736 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31737}
738
[email protected]b172aee2012-04-10 17:05:26739content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31740 return delegate_;
741}
742
[email protected]b172aee2012-04-10 17:05:26743void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31744 // TODO(cbentzel): remove this debugging code?
745 if (delegate == delegate_)
746 return;
747 if (delegate_)
748 delegate_->Detach(this);
749 delegate_ = delegate;
750 if (delegate_)
751 delegate_->Attach(this);
752}
753
[email protected]b172aee2012-04-10 17:05:26754content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41755 RenderViewHostImpl* host = render_manager_.current_host();
756 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16757}
758
[email protected]b172aee2012-04-10 17:05:26759RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31760 return render_manager_.current_host();
761}
762
[email protected]6b618e62012-08-16 12:59:18763int WebContentsImpl::GetRoutingID() const {
764 if (!GetRenderViewHost())
765 return MSG_ROUTING_NONE;
766
767 return GetRenderViewHost()->GetRoutingID();
768}
769
[email protected]b172aee2012-04-10 17:05:26770RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31771 return render_manager_.GetRenderWidgetHostView();
772}
773
[email protected]b172aee2012-04-10 17:05:26774content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31775 return view_.get();
776}
777
[email protected]b172aee2012-04-10 17:05:26778content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50779 WebUIControllerFactory* factory =
780 content::GetContentClient()->browser()->GetWebUIControllerFactory();
781 if (!factory)
782 return NULL;
[email protected]d2353452012-01-19 19:53:56783 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22784 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50785 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22786 if (controller) {
787 web_ui->SetController(controller);
788 return web_ui;
789 }
790
791 delete web_ui;
792 return NULL;
793}
794
[email protected]b172aee2012-04-10 17:05:26795content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31796 return render_manager_.web_ui() ? render_manager_.web_ui()
797 : render_manager_.pending_web_ui();
798}
799
[email protected]b172aee2012-04-10 17:05:26800content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31801 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34802}
803
[email protected]86ef6a392012-05-11 22:03:11804void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22805 if (GetUserAgentOverride() == override)
806 return;
807
808 renderer_preferences_.user_agent_override = override;
809
810 // Send the new override string to the renderer.
811 RenderViewHost* host = GetRenderViewHost();
812 if (host)
813 host->SyncRendererPrefs();
814
815 // Reload the page if a load is currently in progress to avoid having
816 // different parts of the page loaded using different user agents.
817 NavigationEntry* entry = controller_.GetActiveEntry();
818 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
819 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53820
821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
822 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11823}
824
825const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22826 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11827}
828
[email protected]b172aee2012-04-10 17:05:26829const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55830 // Transient entries take precedence. They are used for interstitial pages
831 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23832 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08833 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20834 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30835 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23836 if (entry) {
[email protected]b5cca982011-05-26 04:42:08837 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23838 }
[email protected]7ade2732011-02-10 00:13:58839 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
840 render_manager_.pending_web_ui() : render_manager_.web_ui();
841 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54842 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55843 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54844 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35845 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22846 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54847 if (!title.empty())
848 return title;
849 }
850 }
851
852 // We use the title for the last committed entry rather than a pending
853 // navigation entry. For example, when the user types in a URL, we want to
854 // keep the old page's title until the new load has committed and we get a new
855 // title.
[email protected]96d185d2009-04-24 03:28:54856 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23857 if (entry) {
[email protected]b5cca982011-05-26 04:42:08858 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23859 }
[email protected]987fc3a2011-05-26 14:18:09860
861 // |page_title_when_no_navigation_entry_| is finally used
862 // if no title cannot be retrieved.
863 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54864}
865
[email protected]b172aee2012-04-10 17:05:26866int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46867 return GetMaxPageIDForSiteInstance(GetSiteInstance());
868}
869
[email protected]b172aee2012-04-10 17:05:26870int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
871 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33872 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
873 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46874
[email protected]b6583592012-01-25 19:52:33875 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34876}
877
[email protected]b172aee2012-04-10 17:05:26878void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46879 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
880}
881
[email protected]b172aee2012-04-10 17:05:26882void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33883 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46884 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33885 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34886}
887
[email protected]b172aee2012-04-10 17:05:26888void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
889 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57890}
891
[email protected]b172aee2012-04-10 17:05:26892SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58893 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54894}
895
[email protected]b172aee2012-04-10 17:05:26896SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38897 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
898 render_manager_.pending_render_view_host() :
899 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58900 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38901}
902
[email protected]b172aee2012-04-10 17:05:26903bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31904 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49905}
906
[email protected]b172aee2012-04-10 17:05:26907bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return waiting_for_response_;
909}
910
[email protected]b172aee2012-04-10 17:05:26911const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31912 return load_state_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31916 return load_state_host_;
917}
918
[email protected]b172aee2012-04-10 17:05:26919uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31920 return upload_size_;
921}
922
[email protected]b172aee2012-04-10 17:05:26923uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31924 return upload_position_;
925}
926
[email protected]b172aee2012-04-10 17:05:26927const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return encoding_;
929}
930
[email protected]b172aee2012-04-10 17:05:26931bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31932 return displayed_insecure_content_;
933}
934
[email protected]b172aee2012-04-10 17:05:26935void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31936 capturing_contents_ = cap;
937}
938
[email protected]b172aee2012-04-10 17:05:26939bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31940 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
941 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
942 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49943}
944
[email protected]b172aee2012-04-10 17:05:26945void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
946 int error_code) {
[email protected]443b80e2010-12-14 00:42:23947 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34948 return;
949
[email protected]443b80e2010-12-14 00:42:23950 crashed_status_ = status;
951 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46952 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34953}
954
[email protected]b172aee2012-04-10 17:05:26955base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31956 return crashed_status_;
957}
958
[email protected]b172aee2012-04-10 17:05:26959bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31960 return is_being_destroyed_;
961}
962
[email protected]b172aee2012-04-10 17:05:26963void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34964 if (delegate_)
965 delegate_->NavigationStateChanged(this, changed_flags);
966}
967
[email protected]3e324142012-06-25 18:26:33968base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
969 return last_selected_time_;
970}
971
[email protected]9e2e4632012-07-27 16:38:41972void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54973 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04974 RenderWidgetHostViewPort* rwhv =
975 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16976 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41977 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43978#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16979 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43980#endif
981 }
[email protected]96d185d2009-04-24 03:28:54982
[email protected]5ac20162010-11-24 23:33:11983 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38984
[email protected]9e2e4632012-07-27 16:38:41985 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59986
987 // The resize rect might have changed while this was inactive -- send the new
988 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58989 RenderViewHostImpl* rvh =
990 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59991 if (rvh) {
992 rvh->ResizeRectChanged(GetRootWindowResizerRect());
993 }
[email protected]96d185d2009-04-24 03:28:54994
[email protected]3e324142012-06-25 18:26:33995 bool is_visible = true;
996 content::NotificationService::current()->Notify(
997 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
998 content::Source<WebContents>(this),
999 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311000}
1001
[email protected]b172aee2012-04-10 17:05:261002void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311003 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521004 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1005 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261006 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521007 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331008 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521009 // calls us).
[email protected]c30585c2012-02-16 15:02:041010 RenderWidgetHostViewPort* rwhv =
1011 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161012 if (rwhv)
1013 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541014 }
1015
[email protected]375fa1b2012-05-22 22:05:371016 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071017 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371018 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091019 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371020 content::Details<bool>(&is_visible));
1021}
1022
[email protected]b172aee2012-04-10 17:05:261023bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311024 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271025 return WillNotifyDisconnection() &&
1026 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581027 !static_cast<RenderViewHostImpl*>(
1028 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311029}
1030
[email protected]b172aee2012-04-10 17:05:261031void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271032 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251033 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271034}
1035
[email protected]b172aee2012-04-10 17:05:261036WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441037 // We use our current SiteInstance since the cloned entry will use it anyway.
1038 // We pass |this| for the |base_web_contents| to size the view correctly, and
1039 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191040 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1041 GetSiteInstance(), MSG_ROUTING_NONE,
1042 this, opener_);
1043 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221044 FOR_EACH_OBSERVER(WebContentsObserver,
1045 observers_,
1046 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271047 return tc;
1048}
1049
[email protected]b172aee2012-04-10 17:05:261050gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271051 return view_->GetContentNativeView();
1052}
1053
[email protected]b172aee2012-04-10 17:05:261054gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271055 return view_->GetNativeView();
1056}
1057
[email protected]b172aee2012-04-10 17:05:261058void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271059 view_->GetContainerBounds(out);
1060}
1061
[email protected]b172aee2012-04-10 17:05:261062void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271063 view_->Focus();
1064}
1065
[email protected]14392a52012-05-02 20:28:441066void WebContentsImpl::Observe(int type,
1067 const content::NotificationSource& source,
1068 const content::NotificationDetails& details) {
1069 switch (type) {
1070 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1071 OnWebContentsDestroyed(
1072 content::Source<content::WebContents>(source).ptr());
1073 break;
[email protected]bafe6cd2012-05-23 23:09:501074 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1075 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1076 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1077 i != pending_widget_views_.end(); ++i) {
1078 if (host->GetView() == i->second) {
1079 pending_widget_views_.erase(i);
1080 break;
1081 }
1082 }
1083 break;
1084 }
[email protected]14392a52012-05-02 20:28:441085 default:
1086 NOTREACHED();
1087 }
1088}
1089
[email protected]d1198fd2012-08-13 22:50:191090void WebContentsImpl::Init(BrowserContext* browser_context,
1091 SiteInstance* site_instance,
1092 int routing_id,
1093 const WebContents* base_web_contents) {
1094 render_manager_.Init(browser_context, site_instance, routing_id);
1095
1096 view_.reset(content::GetContentClient()->browser()->
1097 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1098 if (view_.get()) {
1099 CHECK(render_view_host_delegate_view_);
1100 } else {
1101 content::WebContentsViewDelegate* delegate =
1102 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1103 this);
1104 view_.reset(CreateWebContentsView(
1105 this, delegate, &render_view_host_delegate_view_));
1106 CHECK(render_view_host_delegate_view_);
1107 }
1108 CHECK(view_.get());
1109
1110 // We have the initial size of the view be based on the size of the view of
1111 // the passed in WebContents.
1112 view_->CreateView(base_web_contents ?
1113 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1114
1115 // Listen for whether our opener gets destroyed.
1116 if (opener_) {
1117 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1118 content::Source<WebContents>(opener_));
1119 }
1120
1121 registrar_.Add(this,
1122 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1123 content::NotificationService::AllBrowserContextsAndSources());
1124#if defined(ENABLE_JAVA_BRIDGE)
1125 java_bridge_dispatcher_host_manager_.reset(
1126 new JavaBridgeDispatcherHostManager(this));
1127#endif
1128
1129 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1130}
1131
[email protected]14392a52012-05-02 20:28:441132void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1133 // Clear the opener if it has been closed.
1134 if (web_contents == opener_) {
1135 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1136 content::Source<WebContents>(opener_));
1137 opener_ = NULL;
1138 }
1139}
1140
[email protected]b172aee2012-04-10 17:05:261141void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311142 observers_.AddObserver(observer);
1143}
1144
[email protected]b172aee2012-04-10 17:05:261145void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311146 observers_.RemoveObserver(observer);
1147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341150 if (delegate_)
1151 delegate_->ActivateContents(this);
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121155 if (delegate_)
1156 delegate_->DeactivateContents(this);
1157}
1158
[email protected]b172aee2012-04-10 17:05:261159void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481160 if (delegate_)
1161 delegate_->LostCapture();
1162}
1163
[email protected]b172aee2012-04-10 17:05:261164bool WebContentsImpl::PreHandleKeyboardEvent(
1165 const NativeWebKeyboardEvent& event,
1166 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481167 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131168 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481172 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131173 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481174}
1175
[email protected]b172aee2012-04-10 17:05:261176void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431177 if (delegate_)
1178 delegate_->HandleMouseDown();
1179}
1180
[email protected]b172aee2012-04-10 17:05:261181void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481182 if (delegate_)
1183 delegate_->HandleMouseUp();
1184}
1185
[email protected]590a634e2012-07-19 16:38:231186void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481187 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231188 delegate_->HandlePointerActivate();
1189}
1190
1191void WebContentsImpl::HandleGestureBegin() {
1192 if (delegate_)
1193 delegate_->HandleGestureBegin();
1194}
1195
1196void WebContentsImpl::HandleGestureEnd() {
1197 if (delegate_)
1198 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481199}
1200
[email protected]b172aee2012-04-10 17:05:261201void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471202 if (delegate_)
1203 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1204}
1205
[email protected]b172aee2012-04-10 17:05:261206bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381207 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121208}
1209
[email protected]a9c81f02012-06-01 00:15:441210void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1211 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371212 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441213 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371214 } else {
1215 GotResponseToLockMouseRequest(false);
1216 }
1217}
1218
[email protected]b172aee2012-04-10 17:05:261219void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371220 if (delegate_)
1221 delegate_->LostMouseLock();
1222}
1223
[email protected]bafe6cd2012-05-23 23:09:501224void WebContentsImpl::CreateNewWindow(
1225 int route_id,
[email protected]97714c82012-06-06 10:15:131226 const ViewHostMsg_CreateWindow_Params& params,
1227 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501228 if (delegate_ && !delegate_->ShouldCreateWebContents(
1229 this, route_id, params.window_container_type, params.frame_name,
1230 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091231 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501232 return;
1233 }
1234
1235 // We usually create the new window in the same BrowsingInstance (group of
1236 // script-related windows), by passing in the current SiteInstance. However,
1237 // if the opener is being suppressed, we create a new SiteInstance in its own
1238 // BrowsingInstance.
1239 scoped_refptr<SiteInstance> site_instance =
1240 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571241 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501242 GetSiteInstance();
1243
1244 // Create the new web contents. This will automatically create the new
1245 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191246 WebContentsImpl* new_contents =
1247 new WebContentsImpl(GetBrowserContext(),
1248 params.opener_suppressed ? NULL : this);
1249
1250 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341251 //
1252 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191253 const std::string& partition_id =
1254 content::GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571255 GetStoragePartitionIdForSite(GetBrowserContext(),
1256 site_instance->GetSite());
[email protected]4c3a23582012-08-18 08:54:341257 content::StoragePartition* partition =
1258 BrowserContext::GetStoragePartition(GetBrowserContext(),
1259 site_instance);
[email protected]d1198fd2012-08-13 22:50:191260 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341261 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191262 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1263 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1264 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1265 new_contents->GetController().SetSessionStorageNamespace(
1266 partition_id,
1267 session_storage_namespace);
1268 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1269
[email protected]bafe6cd2012-05-23 23:09:501270 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1271
1272 if (!params.opener_suppressed) {
1273 content::WebContentsView* new_view = new_contents->GetView();
1274
1275 // TODO(brettw): It seems bogus that we have to call this function on the
1276 // newly created object and give it one of its own member variables.
1277 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1278
1279 // Save the created window associated with the route so we can show it
1280 // later.
1281 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1282 pending_contents_[route_id] = new_contents;
1283 }
1284
1285 if (delegate_) {
1286 delegate_->WebContentsCreated(
1287 this, params.opener_frame_id, params.target_url, new_contents);
1288 }
1289
1290 if (params.opener_suppressed) {
1291 // When the opener is suppressed, the original renderer cannot access the
1292 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001293 bool was_blocked = false;
1294 if (delegate_) {
1295 gfx::Rect initial_pos;
1296 delegate_->AddNewContents(
1297 this, new_contents, params.disposition, initial_pos,
1298 params.user_gesture, &was_blocked);
1299 }
1300 if (!was_blocked) {
1301 content::OpenURLParams open_params(params.target_url,
1302 content::Referrer(),
1303 CURRENT_TAB,
1304 content::PAGE_TRANSITION_LINK,
1305 true /* is_renderer_initiated */);
1306 new_contents->OpenURL(open_params);
1307 }
[email protected]bafe6cd2012-05-23 23:09:501308 }
1309}
1310
1311void WebContentsImpl::CreateNewWidget(int route_id,
1312 WebKit::WebPopupType popup_type) {
1313 CreateNewWidget(route_id, false, popup_type);
1314}
1315
1316void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1317 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1318}
1319
1320void WebContentsImpl::CreateNewWidget(int route_id,
1321 bool is_fullscreen,
1322 WebKit::WebPopupType popup_type) {
1323 content::RenderProcessHost* process = GetRenderProcessHost();
1324 RenderWidgetHostImpl* widget_host =
1325 new RenderWidgetHostImpl(this, process, route_id);
1326 RenderWidgetHostViewPort* widget_view =
1327 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1328 if (!is_fullscreen) {
1329 // Popups should not get activated.
1330 widget_view->SetPopupType(popup_type);
1331 }
1332 // Save the created widget associated with the route so we can show it later.
1333 pending_widget_views_[route_id] = widget_view;
1334
1335#if defined(OS_MACOSX)
1336 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1337 // to allow it to survive the trip without being hosted.
1338 base::mac::NSObjectRetain(widget_view->GetNativeView());
1339#endif
1340}
1341
1342void WebContentsImpl::ShowCreatedWindow(int route_id,
1343 WindowOpenDisposition disposition,
1344 const gfx::Rect& initial_pos,
1345 bool user_gesture) {
1346 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001347 if (contents) {
1348 WebContentsDelegate* delegate = GetDelegate();
1349 if (delegate) {
1350 delegate->AddNewContents(
1351 this, contents, disposition, initial_pos, user_gesture, NULL);
1352 }
1353 }
[email protected]bafe6cd2012-05-23 23:09:501354}
1355
1356void WebContentsImpl::ShowCreatedWidget(int route_id,
1357 const gfx::Rect& initial_pos) {
1358 ShowCreatedWidget(route_id, false, initial_pos);
1359}
1360
1361void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1362 ShowCreatedWidget(route_id, true, gfx::Rect());
1363}
1364
1365void WebContentsImpl::ShowCreatedWidget(int route_id,
1366 bool is_fullscreen,
1367 const gfx::Rect& initial_pos) {
1368 if (delegate_)
1369 delegate_->RenderWidgetShowing();
1370
1371 RenderWidgetHostViewPort* widget_host_view =
1372 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1373 if (!widget_host_view)
1374 return;
1375 if (is_fullscreen) {
1376 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1377 } else {
1378 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1379 }
[email protected]89054502012-06-03 10:29:241380
1381 RenderWidgetHostImpl* render_widget_host_impl =
1382 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1383 render_widget_host_impl->Init();
1384 // Only allow privileged mouse lock for fullscreen render widget, which is
1385 // used to implement Pepper Flash fullscreen.
1386 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501387
1388#if defined(OS_MACOSX)
1389 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1390 // properly embedded (or purposefully ignored) we can release the retain we
1391 // took in CreateNewWidget().
1392 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1393#endif
1394}
1395
1396WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1397 PendingContents::iterator iter = pending_contents_.find(route_id);
1398
1399 // Certain systems can block the creation of new windows. If we didn't succeed
1400 // in creating one, just return NULL.
1401 if (iter == pending_contents_.end()) {
1402 return NULL;
1403 }
1404
1405 WebContentsImpl* new_contents = iter->second;
1406 pending_contents_.erase(route_id);
1407
1408 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1409 !new_contents->GetRenderViewHost()->GetView())
1410 return NULL;
1411
1412 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1413 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1414 return new_contents;
1415}
1416
1417RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1418 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1419 if (iter == pending_widget_views_.end()) {
1420 DCHECK(false);
1421 return NULL;
1422 }
1423
1424 RenderWidgetHostView* widget_host_view = iter->second;
1425 pending_widget_views_.erase(route_id);
1426
1427 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1428 if (!widget_host->GetProcess()->HasConnection()) {
1429 // The view has gone away or the renderer crashed. Nothing to do.
1430 return NULL;
1431 }
1432
1433 return widget_host_view;
1434}
1435
1436void WebContentsImpl::ShowContextMenu(
[email protected]ba16e3a2012-09-07 04:14:521437 const content::ContextMenuParams& params,
1438 const content::ContextMenuSourceType& type) {
[email protected]bafe6cd2012-05-23 23:09:501439 // Allow WebContentsDelegates to handle the context menu operation first.
1440 if (delegate_ && delegate_->HandleContextMenu(params))
1441 return;
1442
[email protected]ba16e3a2012-09-07 04:14:521443 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501444}
1445
[email protected]f13b4202012-06-12 23:53:231446void WebContentsImpl::RequestMediaAccessPermission(
1447 const content::MediaStreamRequest* request,
1448 const content::MediaResponseCallback& callback) {
1449 if (delegate_)
1450 delegate_->RequestMediaAccessPermission(this, request, callback);
1451 else
1452 callback.Run(content::MediaStreamDevices());
1453}
1454
[email protected]16383382012-09-05 23:57:261455#if defined(OS_ANDROID)
1456void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1457 if (delegate_)
1458 delegate_->AttachLayer(this, layer);
1459}
1460
1461void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1462 if (delegate_)
1463 delegate_->RemoveLayer(this, layer);
1464}
1465#endif
1466
[email protected]b172aee2012-04-10 17:05:261467void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231468 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331469 if (delegate_)
1470 delegate_->UpdatePreferredSize(this, pref_size);
1471}
1472
[email protected]b172aee2012-04-10 17:05:261473void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341474 if (delegate_)
1475 delegate_->ResizeDueToAutoResize(this, new_size);
1476}
1477
[email protected]b172aee2012-04-10 17:05:261478WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201479 if (!delegate_)
1480 return NULL;
[email protected]00c37fc2011-08-02 00:22:501481
[email protected]e5d549d2011-12-28 01:29:201482 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1483 // Notify observers.
1484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1485 DidOpenURL(params.url, params.referrer,
1486 params.disposition, params.transition));
1487 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341488}
1489
[email protected]6b618e62012-08-16 12:59:181490bool WebContentsImpl::Send(IPC::Message* message) {
1491 if (!GetRenderViewHost()) {
1492 delete message;
1493 return false;
1494 }
1495
1496 return GetRenderViewHost()->Send(message);
1497}
1498
[email protected]b172aee2012-04-10 17:05:261499bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501500 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251501 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231502 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251503 reload_type);
[email protected]876bc832010-09-07 16:29:541504}
[email protected]96d185d2009-04-24 03:28:541505
[email protected]ba45bfd2012-05-22 21:51:441506void WebContentsImpl::RenderViewForInterstitialPageCreated(
1507 content::RenderViewHost* render_view_host) {
1508 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1509 RenderViewForInterstitialPageCreated(render_view_host));
1510}
1511
[email protected]b172aee2012-04-10 17:05:261512bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231513 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501514 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401515 // The renderer will reject IPC messages with URLs longer than
1516 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511517 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401518 return false;
1519
[email protected]9f76c1e2012-03-05 15:15:581520 RenderViewHostImpl* dest_render_view_host =
1521 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401522 if (!dest_render_view_host)
1523 return false; // Unable to create the desired render view host.
1524
[email protected]80a8fad2011-01-29 04:02:381525 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071526 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581527 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501528 WebUIControllerFactory* factory =
1529 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271530 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501531 bool is_allowed_in_web_ui_renderer =
1532 factory &&
[email protected]24e18252012-04-16 21:26:271533 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1534 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231535 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1536 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271537 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231538 content::GetContentClient()->SetActiveURL(entry.GetURL());
1539 CHECK(0);
1540 }
[email protected]54ec6472010-04-09 19:39:581541
[email protected]96d185d2009-04-24 03:28:541542 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441543 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521544 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441545 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511546 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541547
[email protected]7bb761892012-07-20 09:32:471548 // Notify observers that we will navigate in this RV.
1549 FOR_EACH_OBSERVER(WebContentsObserver,
1550 observers_,
1551 AboutToNavigateRenderView(dest_render_view_host));
1552
[email protected]96d185d2009-04-24 03:28:541553 // Used for page load time metrics.
1554 current_load_start_ = base::TimeTicks::Now();
1555
1556 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241557 std::string embedder_channel_name;
1558 int embedder_container_id;
1559 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1560 &embedder_channel_name,
1561 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341562 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271563 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241564 embedder_channel_name,
1565 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471566 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341567 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541568
[email protected]36fc0392011-12-25 03:59:511569 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541570 // HACK!! This code suppresses javascript: URLs from being added to
1571 // session history, which is what we want to do for javascript: URLs that
1572 // do not generate content. What we really need is a message from the
1573 // renderer telling us that a new page was not created. The same message
1574 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511575 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541576 return false;
1577 }
1578
[email protected]3c9e1872010-11-18 16:17:491579 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251580 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041581 observers_,
[email protected]36fc0392011-12-25 03:59:511582 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541583
[email protected]09b29342011-06-24 19:18:481584 if (delegate_)
1585 delegate_->DidNavigateToPendingEntry(this);
1586
[email protected]d5f942ba2008-09-26 19:30:341587 return true;
1588}
1589
[email protected]b172aee2012-04-10 17:05:261590void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331591 const SiteInstance* site_instance,
1592 int history_length,
1593 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411594 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1595 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191596 if (render_manager_.pending_render_view_host()) {
1597 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141598 return;
[email protected]9e1ad4b2011-08-14 16:49:191599 }
[email protected]9f76c1e2012-03-05 15:15:581600 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191601 if (!rvh) {
1602 NOTREACHED();
1603 return;
1604 }
[email protected]9f76c1e2012-03-05 15:15:581605 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191606 NOTREACHED();
1607 return;
1608 }
[email protected]6b618e62012-08-16 12:59:181609 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1610 history_length,
1611 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141612}
1613
[email protected]b172aee2012-04-10 17:05:261614void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271615 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541616 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1617 return;
1618 }
[email protected]9f76c1e2012-03-05 15:15:581619 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541620}
1621
[email protected]b172aee2012-04-10 17:05:261622bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271623 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541624}
1625
[email protected]b172aee2012-04-10 17:05:261626InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271627 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221628}
1629
[email protected]b172aee2012-04-10 17:05:261630bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161631 // WebKit creates Document object when MIME type is application/xhtml+xml,
1632 // so we also support this MIME type.
1633 return contents_mime_type_ == "text/html" ||
1634 contents_mime_type_ == "text/xml" ||
1635 contents_mime_type_ == "application/xhtml+xml" ||
1636 contents_mime_type_ == "text/plain" ||
1637 contents_mime_type_ == "text/css" ||
1638 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1639}
1640
[email protected]b172aee2012-04-10 17:05:261641void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591642 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161643 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481644 download_stats::RecordDownloadSource(
1645 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461646 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141647 return;
[email protected]c7dd2f62011-07-18 15:57:591648 }
1649
1650 Stop();
1651
1652 // Create the save package and possibly prompt the user for the name to save
1653 // the page as. The user prompt is an asynchronous operation that runs on
1654 // another thread.
1655 save_package_ = new SavePackage(this);
1656 save_package_->GetSaveInfo();
1657}
1658
1659// Used in automated testing to bypass prompting the user for file names.
1660// Instead, the names and paths are hard coded rather than running them through
1661// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261662bool WebContentsImpl::SavePage(const FilePath& main_file,
1663 const FilePath& dir_path,
1664 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591665 // Stop the page from navigating.
1666 Stop();
1667
1668 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271669 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591670}
1671
[email protected]b172aee2012-04-10 17:05:261672void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121673 const FilePath& file,
1674 const base::Callback<void(const FilePath&, int64)>& callback) {
1675 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1676}
1677
[email protected]b172aee2012-04-10 17:05:261678bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231679 NavigationEntryImpl* active_entry =
1680 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321681 return (active_entry != NULL &&
1682 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511683 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321684}
1685
[email protected]b172aee2012-04-10 17:05:261686const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271687 return contents_mime_type_;
1688}
1689
[email protected]b172aee2012-04-10 17:05:261690bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271691 return notify_disconnection_;
1692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311695 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181696 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311700 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181701 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161702}
1703
[email protected]b172aee2012-04-10 17:05:261704content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271705 return &renderer_preferences_;
1706}
1707
[email protected]b172aee2012-04-10 17:05:261708void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271709 new_tab_start_time_ = time;
1710}
1711
[email protected]b172aee2012-04-10 17:05:261712base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271713 return new_tab_start_time_;
1714}
1715
[email protected]e35ccd52012-05-23 16:22:471716void WebContentsImpl::Close() {
1717 Close(GetRenderViewHost());
1718}
1719
[email protected]b172aee2012-04-10 17:05:261720void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151721 if (close_start_time_.is_null())
1722 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011723}
1724
[email protected]b172aee2012-04-10 17:05:261725bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191726#if defined(OS_CHROMEOS)
1727 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1728 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511729 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201730 return false;
1731 return true;
[email protected]46624bf2010-06-09 16:04:191732#else
1733 return true;
1734#endif
1735}
1736
[email protected]b172aee2012-04-10 17:05:261737void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521738 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581739 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511740 if (delegate_)
1741 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341742}
1743
[email protected]e35ccd52012-05-23 16:22:471744void WebContentsImpl::UserGestureDone() {
1745 OnUserGesture();
1746}
1747
[email protected]b172aee2012-04-10 17:05:261748void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271749 closed_by_user_gesture_ = value;
1750}
1751
[email protected]b172aee2012-04-10 17:05:261752bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271753 return closed_by_user_gesture_;
1754}
1755
[email protected]b172aee2012-04-10 17:05:261756double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051757 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561758 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251759 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171760 return 0;
[email protected]b75b8292010-10-01 07:28:251761
1762 double zoom_level;
1763 if (temporary_zoom_settings_) {
1764 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581765 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251766 } else {
[email protected]2ae88d12011-10-14 09:11:191767 GURL url;
[email protected]10f417c52011-12-28 21:04:231768 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191769 // Since zoom map is updated using rewritten URL, use rewritten URL
1770 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511771 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191772 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251773 }
[email protected]d0b8d092010-10-25 04:05:171774 return zoom_level;
1775}
[email protected]b75b8292010-10-01 07:28:251776
[email protected]b172aee2012-04-10 17:05:261777int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1778 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171779 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011780 // Calculate the zoom percent from the factor. Round up to the nearest whole
1781 // number.
[email protected]b75b8292010-10-01 07:28:251782 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011783 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251784 *enable_decrement = percent > minimum_zoom_percent_;
1785 *enable_increment = percent < maximum_zoom_percent_;
1786 return percent;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501790 if (!delegate_)
1791 return;
1792
[email protected]10f417c52011-12-28 21:04:231793 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501794 if (!active_entry)
1795 return;
1796
[email protected]36fc0392011-12-25 03:59:511797 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121798}
1799
[email protected]b172aee2012-04-10 17:05:261800void WebContentsImpl::ViewFrameSource(const GURL& url,
1801 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271802 if (!delegate_)
1803 return;
1804
1805 delegate_->ViewSourceForFrame(this, url, content_state);
1806}
1807
[email protected]b172aee2012-04-10 17:05:261808int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271809 return minimum_zoom_percent_;
1810}
1811
[email protected]b172aee2012-04-10 17:05:261812int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271813 return maximum_zoom_percent_;
1814}
1815
[email protected]b172aee2012-04-10 17:05:261816gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231817 return preferred_size_;
1818}
1819
[email protected]b172aee2012-04-10 17:05:261820int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271821 return content_restrictions_;
1822}
1823
[email protected]b172aee2012-04-10 17:05:261824WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501825 WebUIControllerFactory* factory =
1826 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1827 if (!factory)
1828 return WebUI::kNoWebUI;
1829 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271830}
1831
[email protected]b172aee2012-04-10 17:05:261832content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271833 // When there is a pending navigation entry, we want to use the pending WebUI
1834 // that goes along with it to control the basic flags. For example, we want to
1835 // show the pending URL in the URL bar, so we want the display_url flag to
1836 // be from the pending entry.
1837 //
1838 // The confusion comes because there are multiple possibilities for the
1839 // initial load in a tab as a side effect of the way the RenderViewHostManager
1840 // works.
1841 //
1842 // - For the very first tab the load looks "normal". The new tab Web UI is
1843 // the pending one, and we want it to apply here.
1844 //
1845 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1846 // get switched to the one previously associated with the new tab pages.
1847 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1848 // have a committed Web UI in this case.
1849 //
1850 // This condition handles all of these cases:
1851 //
1852 // - First load in first tab: no committed nav entry + pending nav entry +
1853 // pending dom ui:
1854 // -> Use pending Web UI if any.
1855 //
1856 // - First load in second tab: no committed nav entry + pending nav entry +
1857 // no pending Web UI:
1858 // -> Use the committed Web UI if any.
1859 //
1860 // - Second navigation in any tab: committed nav entry + pending nav entry:
1861 // -> Use pending Web UI if any.
1862 //
1863 // - Normal state with no load: committed nav entry + no pending nav entry:
1864 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251865 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271866 (controller_.GetLastCommittedEntry() ||
1867 render_manager_.pending_web_ui()))
1868 return render_manager_.pending_web_ui();
1869 return render_manager_.web_ui();
1870}
1871
[email protected]b172aee2012-04-10 17:05:261872bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271873 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581874 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271875}
1876
[email protected]b172aee2012-04-10 17:05:261877bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441878 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501879}
1880
[email protected]b172aee2012-04-10 17:05:261881void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321882 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181883 Send(new ViewMsg_DidChooseColorResponse(
1884 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201885}
1886
[email protected]b172aee2012-04-10 17:05:261887void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181888 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201889 if (delegate_)
1890 delegate_->DidEndColorChooser();
1891 color_chooser_ = NULL;
1892}
1893
[email protected]b172aee2012-04-10 17:05:261894bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471895 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271896 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221897 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231898 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411899 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271900}
1901
[email protected]b172aee2012-04-10 17:05:261902void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271903 if (delegate_)
1904 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211905}
1906
[email protected]3a3b75a2012-06-01 08:38:361907void WebContentsImpl::OnRegisterIntentService(
1908 const webkit_glue::WebIntentServiceData& data,
1909 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431910 if (delegate_)
1911 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301912}
1913
[email protected]b172aee2012-04-10 17:05:261914void WebContentsImpl::OnWebIntentDispatch(
1915 const webkit_glue::WebIntentData& intent,
1916 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431917 if (!delegate_)
1918 return;
1919
[email protected]0d9989d2011-12-21 20:26:001920 WebIntentsDispatcherImpl* intents_dispatcher =
1921 new WebIntentsDispatcherImpl(this, intent, intent_id);
1922 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301923}
1924
[email protected]54047eb52012-05-08 21:45:571925void WebContentsImpl::DidStartProvisionalLoadForFrame(
1926 content::RenderViewHost* render_view_host,
1927 int64 frame_id,
1928 bool is_main_frame,
1929 const GURL& opener_url,
1930 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281931 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181932 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451933 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571934 content::RenderProcessHost* render_process_host =
1935 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541936 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571937 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451938 false,
[email protected]9f76c1e2012-03-05 15:15:581939 &validated_url);
[email protected]ef108e72012-06-20 14:03:541940 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571941 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451942 true,
1943 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181944
[email protected]0d60f0192011-04-14 12:40:101945 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251946 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101947 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571948 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541949
1950 if (is_main_frame) {
1951 // Notify observers about the provisional change in the main frame URL.
1952 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1953 ProvisionalChangeToMainFrameUrl(validated_url,
1954 validated_opener_url,
1955 render_view_host));
1956 }
1957}
1958
1959void WebContentsImpl::DidRedirectProvisionalLoad(
1960 content::RenderViewHost* render_view_host,
1961 int32 page_id,
1962 const GURL& opener_url,
1963 const GURL& source_url,
1964 const GURL& target_url) {
1965 // TODO(creis): Remove this method and have the pre-rendering code listen to
1966 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1967 // instead. See http://crbug.com/78512.
1968 GURL validated_source_url(source_url);
1969 GURL validated_target_url(target_url);
1970 GURL validated_opener_url(opener_url);
1971 content::RenderProcessHost* render_process_host =
1972 render_view_host->GetProcess();
1973 RenderViewHostImpl::FilterURL(
1974 ChildProcessSecurityPolicyImpl::GetInstance(),
1975 render_process_host->GetID(),
1976 false,
1977 &validated_source_url);
1978 RenderViewHostImpl::FilterURL(
1979 ChildProcessSecurityPolicyImpl::GetInstance(),
1980 render_process_host->GetID(),
1981 false,
1982 &validated_target_url);
1983 RenderViewHostImpl::FilterURL(
1984 ChildProcessSecurityPolicyImpl::GetInstance(),
1985 render_process_host->GetID(),
1986 true,
1987 &validated_opener_url);
1988 NavigationEntry* entry;
1989 if (page_id == -1) {
1990 entry = controller_.GetPendingEntry();
1991 } else {
1992 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1993 page_id);
1994 }
1995 if (!entry || entry->GetURL() != validated_source_url)
1996 return;
1997
1998 // Notify observers about the provisional change in the main frame URL.
1999 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2000 ProvisionalChangeToMainFrameUrl(validated_target_url,
2001 validated_opener_url,
2002 render_view_host));
[email protected]724159a2010-12-30 01:11:182003}
2004
[email protected]54047eb52012-05-08 21:45:572005void WebContentsImpl::DidFailProvisionalLoadWithError(
2006 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582007 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2008 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2009 << ", error_code: " << params.error_code
2010 << ", error_description: " << params.error_description
2011 << ", is_main_frame: " << params.is_main_frame
2012 << ", showing_repost_interstitial: " <<
2013 params.showing_repost_interstitial
2014 << ", frame_id: " << params.frame_id;
2015 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:572016 content::RenderProcessHost* render_process_host =
2017 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542018 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572019 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452020 false,
[email protected]9f76c1e2012-03-05 15:15:582021 &validated_url);
[email protected]724159a2010-12-30 01:11:182022
[email protected]d7b175e2011-10-11 15:31:582023 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182024 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2025 // This means that the interstitial won't be torn down properly, which is
2026 // bad. But if we have an interstitial, go back to another tab type, and
2027 // then load the same interstitial again, we could end up getting the first
2028 // interstitial's "failed" message (as a result of the cancel) when we're on
2029 // the second one.
2030 //
2031 // We can't tell this apart, so we think we're tearing down the current page
2032 // which will cause a crash later one. There is also some code in
2033 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2034 // out because of this problem.
2035 //
2036 // http://code.google.com/p/chromium/issues/detail?id=2855
2037 // Because this will not tear down the interstitial properly, if "back" is
2038 // back to another tab type, the interstitial will still be somewhat alive
2039 // in the previous tab type. If you navigate somewhere that activates the
2040 // tab with the interstitial again, you'll see a flash before the new load
2041 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272042 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182043 LOG(WARNING) << "Discarding message during interstitial.";
2044 return;
2045 }
2046
[email protected]a16690732012-07-13 19:22:172047 // Do not clear the pending entry if one exists, so that the user's typed
2048 // URL is not lost when a navigation fails or is aborted. We'll allow
2049 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182050
[email protected]54047eb52012-05-08 21:45:572051 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182052 }
2053
[email protected]d8c660432011-12-22 20:51:252054 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582055 observers_,
2056 DidFailProvisionalLoad(params.frame_id,
2057 params.is_main_frame,
2058 validated_url,
2059 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462060 params.error_description,
2061 render_view_host));
[email protected]724159a2010-12-30 01:11:182062}
2063
[email protected]b172aee2012-04-10 17:05:262064void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182065 const GURL& url,
[email protected]70435962011-08-02 20:13:282066 const std::string& security_info,
2067 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182068 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282069 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192070 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182071 cache.Increment();
2072
2073 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082074 int cert_id = 0;
2075 net::CertStatus cert_status = 0;
2076 int security_bits = -1;
2077 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512078 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2079 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002080 content::LoadFromMemoryCacheDetails details(
2081 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2082 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182083
[email protected]ad50def52011-10-19 23:17:072084 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272085 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502086 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002087 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182088}
2089
[email protected]b172aee2012-04-10 17:05:262090void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382091 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182092 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192093 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182094}
2095
[email protected]b172aee2012-04-10 17:05:262096void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022097 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232098 LOG(INFO) << security_origin << " ran insecure content from "
2099 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382100 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412101 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2102 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182103 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412104 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192105 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182109 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252110 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472111 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182112}
2113
[email protected]b172aee2012-04-10 17:05:262114void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312115 int64 frame_id,
2116 const GURL& validated_url,
2117 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252118 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472119 DidFinishLoad(frame_id, validated_url, is_main_frame,
2120 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312121}
2122
[email protected]b172aee2012-04-10 17:05:262123void WebContentsImpl::OnDidFailLoadWithError(
2124 int64 frame_id,
2125 const GURL& validated_url,
2126 bool is_main_frame,
2127 int error_code,
2128 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252129 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312130 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472131 error_code, error_description,
2132 message_source_));
[email protected]724159a2010-12-30 01:11:182133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272136 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432137 if (delegate_)
2138 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172139}
2140
[email protected]b172aee2012-04-10 17:05:262141void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262142 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232143 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252144 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262145 if (!entry)
2146 return;
2147 // Note that we don't call NavigationController::GotToOffset() as we don't
2148 // want to create a pending navigation entry (it might end up lingering
2149 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252150 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582151 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512152 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582153 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472154 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572155
2156 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2157 // it in now that we know. This allows us to find the entry when it commits.
2158 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232159 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332160 entry->set_site_instance(
2161 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572162 }
[email protected]216813952011-05-19 22:21:262163 }
2164}
2165
[email protected]b172aee2012-04-10 17:05:262166void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2167 int maximum_percent,
2168 bool remember) {
[email protected]216813952011-05-19 22:21:262169 minimum_zoom_percent_ = minimum_percent;
2170 maximum_zoom_percent_ = maximum_percent;
2171 temporary_zoom_settings_ = !remember;
2172}
2173
[email protected]20b433a2012-05-15 21:23:462174void WebContentsImpl::OnSaveURL(const GURL& url,
2175 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482176 download_stats::RecordDownloadSource(
2177 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262178 // Check if the URL to save matches the URL of the main frame. Since this
2179 // message originates from Pepper plugins, it may not be the case if the
2180 // plugin is an embedded element.
2181 GURL main_frame_url = GetURL();
2182 if (!main_frame_url.is_valid())
2183 return;
2184 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462185 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272186}
2187
[email protected]b172aee2012-04-10 17:05:262188void WebContentsImpl::OnEnumerateDirectory(int request_id,
2189 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432190 if (!delegate_)
2191 return;
2192
[email protected]b9535422012-02-09 01:47:592193 ChildProcessSecurityPolicyImpl* policy =
2194 ChildProcessSecurityPolicyImpl::GetInstance();
2195 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2196 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212197}
2198
[email protected]b172aee2012-04-10 17:05:262199void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432200 if (delegate_)
2201 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202202}
2203
[email protected]b172aee2012-04-10 17:05:262204void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2205 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362206 const string16& title,
2207 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432208 if (!delegate_)
2209 return;
2210
[email protected]b9535422012-02-09 01:47:592211 ChildProcessSecurityPolicyImpl* policy =
2212 ChildProcessSecurityPolicyImpl::GetInstance();
2213 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2214 return;
[email protected]3a3b75a2012-06-01 08:38:362215 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202216}
2217
[email protected]b172aee2012-04-10 17:05:262218void WebContentsImpl::OnFindReply(int request_id,
2219 int number_of_matches,
2220 const gfx::Rect& selection_rect,
2221 int active_match_ordinal,
2222 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432223 if (delegate_) {
2224 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2225 active_match_ordinal, final_update);
2226 }
[email protected]b888919c2011-09-02 00:32:162227}
2228
[email protected]59363fc92012-09-05 03:46:312229#if defined(OS_ANDROID)
2230void WebContentsImpl::OnFindMatchRectsReply(
2231 int version,
2232 const std::vector<gfx::RectF>& rects,
2233 const gfx::RectF& active_rect) {
2234 if (delegate_)
2235 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2236}
2237#endif
2238
[email protected]b172aee2012-04-10 17:05:262239void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442240 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2241 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452242}
2243
[email protected]b172aee2012-04-10 17:05:262244void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2245 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102246 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252247 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102248 AppCacheAccessed(manifest_url, blocked_by_policy));
2249}
2250
[email protected]b172aee2012-04-10 17:05:262251void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322252 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432253 color_chooser_ = delegate_ ?
2254 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202258 if (color_chooser_ &&
2259 color_chooser_id == color_chooser_->identifier())
2260 color_chooser_->End();
2261}
2262
[email protected]b172aee2012-04-10 17:05:262263void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322264 SkColor color) {
[email protected]da8543762012-03-20 08:52:202265 if (color_chooser_ &&
2266 color_chooser_id == color_chooser_->identifier())
2267 color_chooser_->SetSelectedColor(color);
2268}
2269
[email protected]9f2a9d72012-04-16 16:02:222270void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2271 const FilePath& path,
2272 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442273 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2274 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292275}
2276
[email protected]d0759f492012-04-19 22:50:502277// This exists for render views that don't have a WebUI, but do have WebUI
2278// bindings enabled.
2279void WebContentsImpl::OnWebUISend(const GURL& source_url,
2280 const std::string& name,
2281 const base::ListValue& args) {
2282 if (delegate_)
2283 delegate_->WebUISend(this, source_url, name, args);
2284}
2285
[email protected]d8415ad92012-08-23 14:40:502286void WebContentsImpl::OnRequestPpapiBrokerPermission(
2287 int request_id,
2288 const GURL& url,
2289 const FilePath& plugin_path) {
2290 base::Callback<void(bool)> callback =
2291 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2292 base::Unretained(this), request_id);
2293 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2294 WebContentsObserver* observer;
2295 while ((observer = it.GetNext()) != NULL) {
2296 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2297 callback))
2298 return;
2299 }
2300
2301 // Fall back to allowing the request if no observer handled it.
2302 OnPpapiBrokerPermissionResult(request_id, true);
2303}
2304
2305void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2306 bool result) {
2307 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2308 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2309 request_id,
2310 result));
2311}
2312
[email protected]96d185d2009-04-24 03:28:542313// Notifies the RenderWidgetHost instance about the fact that the page is
2314// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262315void WebContentsImpl::SetIsLoading(bool is_loading,
2316 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542317 if (is_loading == is_loading_)
2318 return;
2319
2320 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212321 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542322 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562323 upload_size_ = 0;
2324 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542325 }
2326
2327 render_manager_.SetIsLoading(is_loading);
2328
2329 is_loading_ = is_loading;
2330 waiting_for_response_ = is_loading;
2331
[email protected]6ebdc9b2010-09-27 16:55:572332 if (delegate_)
2333 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462334 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542335
[email protected]432115822011-07-10 15:52:272336 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2337 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072338 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542339 if (details)
[email protected]6c2381d2011-10-19 02:52:532340 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072341 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502342 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542343 det);
2344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132347 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322348 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562349 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382350 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442351 // that opened the window, as long as both renderers have the same
2352 // privileges.
[email protected]1fd1a502011-03-30 16:55:562353 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562354 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582355 // web_ui might be NULL if the URL refers to a non-existent extension.
2356 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402357 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522358 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442359 }
2360 }
[email protected]1fd1a502011-03-30 16:55:562361 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442362 }
2363
[email protected]4e697b042011-07-08 06:44:562364 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322365 // Clear the status bubble. This is a workaround for a bug where WebKit
2366 // doesn't let us know that the cursor left an element during a
2367 // transition (this is also why the mouse cursor remains as a hand after
2368 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2369 // clear the bubble when a user navigates to a named anchor in the same
2370 // page.
[email protected]36fc0392011-12-25 03:59:512371 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322372 }
2373
[email protected]a6e82fc2010-02-24 22:28:142374 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472375 // Once the main frame is navigated, we're no longer considered to have
2376 // displayed insecure content.
2377 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172378 }
[email protected]ce5c4502009-05-06 16:46:112379
[email protected]3c9e1872010-11-18 16:17:492380 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252381 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042382 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322383}
2384
[email protected]b172aee2012-04-10 17:05:262385void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322386 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132387 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322388 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062389 // If we navigate off the page, reset JavaScript state. This does nothing
2390 // to prevent a malicious script from spamming messages, since the script
2391 // could just reload the page to stop blocking.
2392 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552393 dialog_creator_->ResetJavaScriptState(this);
2394 dialog_creator_ = NULL;
2395 }
[email protected]420ae012009-04-24 05:16:322396
[email protected]3c9e1872010-11-18 16:17:492397 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252398 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042399 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322400}
2401
[email protected]b172aee2012-04-10 17:05:262402void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462403 // If we are creating a RVH for a restored controller, then we need to make
2404 // sure the RenderView starts with a next_page_id_ larger than the number
2405 // of restored entries. This must be called before the RenderView starts
2406 // navigating (to avoid a race between the browser updating max_page_id and
2407 // the renderer updating next_page_id_). Because of this, we only call this
2408 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562409 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582410 if (max_restored_page_id >
2411 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2412 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2413 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322414}
2415
[email protected]b172aee2012-04-10 17:05:262416bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2417 const string16& title) {
[email protected]420ae012009-04-24 05:16:322418 // For file URLs without a title, use the pathname instead. In the case of a
2419 // synthesized title, we don't want the update to count toward the "one set
2420 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512421 string16 final_title;
[email protected]420ae012009-04-24 05:16:322422 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512423 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2424 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322425 explicit_set = false; // Don't count synthetic titles toward the set limit.
2426 } else {
[email protected]acafd272011-07-26 17:35:572427 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322428 explicit_set = true;
2429 }
2430
[email protected]987fc3a2011-05-26 14:18:092431 // If a page is created via window.open and never navigated,
2432 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552433 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092434 if (entry) {
[email protected]36fc0392011-12-25 03:59:512435 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092436 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322437
[email protected]36fc0392011-12-25 03:59:512438 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092439 } else {
2440 if (page_title_when_no_navigation_entry_ == final_title)
2441 return false; // Nothing changed, don't bother.
2442
2443 page_title_when_no_navigation_entry_ = final_title;
2444 }
[email protected]420ae012009-04-24 05:16:322445
[email protected]420ae012009-04-24 05:16:322446 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232447 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322448
[email protected]2bb171882012-03-07 02:09:462449 std::pair<content::NavigationEntry*, bool> details =
2450 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142451
[email protected]ad50def52011-10-19 23:17:072452 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442453 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2454 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462455 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042456
[email protected]420ae012009-04-24 05:16:322457 return true;
2458}
2459
[email protected]b172aee2012-04-10 17:05:262460void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322461 // After sending out a swap notification, we need to send a disconnect
2462 // notification so that clients that pick up a pointer to |this| can NULL the
2463 // pointer. See Bug 1230284.
2464 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072465 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202466 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2467 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072468 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322469}
2470
[email protected]b172aee2012-04-10 17:05:262471void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322472 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072473 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122474 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2475 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072476 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322477}
2478
[email protected]b172aee2012-04-10 17:05:262479void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322480 if (!notify_disconnection_)
2481 return;
2482
2483 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072484 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322485 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2486 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072487 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322488}
2489
[email protected]5a3bdf52012-05-24 15:12:572490RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2491 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322492}
2493
[email protected]8d3347f2009-07-09 22:00:212494RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262495WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212496 return &render_manager_;
2497}
2498
[email protected]b172aee2012-04-10 17:05:262499content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372500 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462501 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512502}
2503
[email protected]b172aee2012-04-10 17:05:262504WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172505 return this;
2506}
2507
[email protected]b172aee2012-04-10 17:05:262508gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172509 if (delegate_)
2510 return delegate_->GetRootWindowResizerRect();
2511 return gfx::Rect();
2512}
2513
[email protected]b172aee2012-04-10 17:05:262514void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442515 // Don't send notifications if we are just creating a swapped-out RVH for
2516 // the opener chain. These won't be used for view-source or WebUI, so it's
2517 // ok to return early.
2518 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2519 return;
2520
[email protected]ad50def52011-10-19 23:17:072521 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302522 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322523 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532524 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232525 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322526 if (!entry)
2527 return;
2528
2529 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352530 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562531 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582532 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322533
2534 if (entry->IsViewSourceMode()) {
2535 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182536 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582537 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322538 }
[email protected]0666aef2009-05-13 19:48:082539
[email protected]d487beefe2011-12-21 05:41:212540 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262541
2542 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252543 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322544}
2545
[email protected]b172aee2012-04-10 17:05:262546void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522547 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322548 // Don't notify the world, since this came from a renderer in the
2549 // background.
2550 return;
2551 }
2552
2553 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312554 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232555 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302556
2557 // Restore the focus to the tab (otherwise the focus will be on the top
2558 // window).
[email protected]484ae5912010-09-29 19:16:142559 if (was_crashed && !FocusLocationBarByDefault() &&
2560 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302561 Focus();
[email protected]484ae5912010-09-29 19:16:142562 }
[email protected]32ded2212011-11-10 18:51:432563
[email protected]d8c660432011-12-22 20:51:252564 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322565}
2566
[email protected]b172aee2012-04-10 17:05:262567void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2568 base::TerminationStatus status,
2569 int error_code) {
[email protected]151a63d2011-12-20 22:32:522570 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322571 // The pending page's RenderViewHost is gone.
2572 return;
2573 }
2574
2575 SetIsLoading(false, NULL);
2576 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232577 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312578 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322579
[email protected]d8c660432011-12-22 20:51:252580 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272581 observers_,
[email protected]be1f56ab2011-12-22 06:55:312582 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322583}
2584
[email protected]b172aee2012-04-10 17:05:262585void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482586 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252587 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062588}
2589
[email protected]b172aee2012-04-10 17:05:262590void WebContentsImpl::DidNavigate(
2591 RenderViewHost* rvh,
2592 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582593 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322594 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372595
[email protected]434f69f2012-02-06 21:56:522596 // Update the site of the SiteInstance if it doesn't have one yet, unless
2597 // this is for about:blank. In that case, the SiteInstance can still be
2598 // considered unused until a navigation to a real page.
2599 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2600 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332601 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522602 }
[email protected]420ae012009-04-24 05:16:322603
2604 // Need to update MIME type here because it's referred to in
2605 // UpdateNavigationCommands() called by RendererDidNavigate() to
2606 // determine whether or not to enable the encoding menu.
2607 // It's updated only for the main frame. For a subframe,
2608 // RenderView::UpdateURL does not set params.contents_mime_type.
2609 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2610 // TODO(jungshik): Add a test for the encoding menu to avoid
2611 // regressing it again.
[email protected]2905f742011-10-13 03:51:582612 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322613 contents_mime_type_ = params.contents_mime_type;
2614
[email protected]8286f51a2011-05-31 17:39:132615 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002616 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392617
[email protected]a9c0bfe2010-09-17 08:35:222618 // Send notification about committed provisional loads. This notification is
2619 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2620 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082621 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072622 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2623 // that is not recorded in the navigation history. For the purpose of
2624 // tracking navigation events, we treat this event as a sub frame navigation
2625 // event.
2626 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582627 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222628 // Whether or not a page transition was triggered by going backward or
2629 // forward in the history is only stored in the navigation controller's
2630 // entry list.
2631 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512632 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582633 content::PAGE_TRANSITION_FORWARD_BACK)) {
2634 transition_type = content::PageTransitionFromInt(
2635 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222636 }
[email protected]0d60f0192011-04-14 12:40:102637 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102639 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462640 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222641 }
2642
[email protected]76543b92009-08-31 17:27:452643 if (!did_navigate)
2644 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322645
2646 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2647 // for the appropriate notification (best) or you can add it to
2648 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2649 // necessary, please).
2650
2651 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002652 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322653 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512654 if (delegate_)
2655 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002656 }
[email protected]420ae012009-04-24 05:16:322657 DidNavigateAnyFramePostCommit(rvh, details, params);
2658}
2659
[email protected]b172aee2012-04-10 17:05:262660void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2661 int32 page_id,
2662 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152663 // Ensure that this state update comes from either the active RVH or one of
2664 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522665 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322666
2667 // We must be prepared to handle state updates for any page, these occur
2668 // when the user is scrolling and entering form data, as well as when we're
2669 // leaving a page, in which case our state may have already been moved to
2670 // the next page. The navigation controller will look up the appropriate
2671 // NavigationEntry and update it when it is notified via the delegate.
2672
2673 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582674 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322675 if (entry_index < 0)
2676 return;
[email protected]10f417c52011-12-28 21:04:232677 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322678
[email protected]36fc0392011-12-25 03:59:512679 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322680 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512681 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322682 controller_.NotifyEntryChanged(entry, entry_index);
2683}
2684
[email protected]b172aee2012-04-10 17:05:262685void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2686 int32 page_id,
2687 const string16& title,
2688 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322689 // If we have a title, that's a pretty good indication that we've started
2690 // getting useful data.
2691 SetNotWaitingForResponse();
2692
[email protected]73eb2602012-02-09 19:50:552693 // Try to find the navigation entry, which might not be the current one.
2694 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232695 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582696 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092697
[email protected]73eb2602012-02-09 19:50:552698 // We can handle title updates when we don't have an entry in
2699 // UpdateTitleForEntry, but only if the update is from the current RVH.
2700 if (!entry && rvh != GetRenderViewHost())
2701 return;
2702
[email protected]a49e10b2011-08-01 23:57:462703 // TODO(evan): make use of title_direction.
2704 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092705 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322706 return;
2707
2708 // Broadcast notifications when the UI should be updated.
2709 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462710 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322711}
2712
[email protected]b172aee2012-04-10 17:05:262713void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2714 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312715 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322716}
2717
[email protected]b172aee2012-04-10 17:05:262718void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512719 if (delegate_)
2720 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322721}
2722
[email protected]b172aee2012-04-10 17:05:262723void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292724 // The UI may be in an event-tracking loop, such as between the
2725 // mouse-down and mouse-up in text selection or a button click.
2726 // Defer the close until after tracking is complete, so that we
2727 // don't free objects out from under the UI.
2728 // TODO(shess): This could probably be integrated with the
2729 // IsDoingDrag() test below. Punting for now because I need more
2730 // research to understand how this impacts platforms other than Mac.
2731 // TODO(shess): This could get more fine-grained. For instance,
2732 // closing a tab in another window while selecting text in the
2733 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212734 if (GetView()->IsEventTracking()) {
2735 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292736 return;
2737 }
2738
[email protected]24a4d1062009-07-10 23:10:422739 // If we close the tab while we're in the middle of a drag, we'll crash.
2740 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212741 if (GetView()->IsDoingDrag()) {
2742 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422743 return;
2744 }
2745
[email protected]420ae012009-04-24 05:16:322746 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522747 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512748 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322749}
2750
[email protected]b172aee2012-04-10 17:05:262751void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522752 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512753 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572754}
2755
[email protected]b172aee2012-04-10 17:05:262756void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512757 if (delegate_ && delegate_->IsPopupOrPanel(this))
2758 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322759}
2760
[email protected]89793072012-07-23 22:25:292761void WebContentsImpl::DidStartLoading(
2762 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322763 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492764
[email protected]82114f52012-03-20 22:53:412765 if (delegate_ && content_restrictions_)
2766 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492767
2768 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292769 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2770 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322771}
2772
[email protected]89793072012-07-23 22:25:292773void WebContentsImpl::DidStopLoading(
2774 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322775 scoped_ptr<LoadNotificationDetails> details;
2776
[email protected]10f417c52011-12-28 21:04:232777 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322778 // An entry may not exist for a stop when loading an initial blank page or
2779 // if an iframe injected by script into a blank page finishes loading.
2780 if (entry) {
[email protected]420ae012009-04-24 05:16:322781 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2782
2783 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512784 entry->GetVirtualURL(),
2785 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322786 elapsed,
2787 &controller_,
2788 controller_.GetCurrentEntryIndex()));
2789 }
2790
[email protected]420ae012009-04-24 05:16:322791 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492792
2793 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292794 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2795 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322796}
2797
[email protected]b172aee2012-04-10 17:05:262798void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162799 controller_.DiscardNonCommittedEntries();
2800
2801 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462802 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162803}
2804
[email protected]b172aee2012-04-10 17:05:262805void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512806 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132807 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402808}
2809
[email protected]0720b532012-08-28 19:23:372810void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2811 render_manager_.DidUpdateFrameTree(rvh);
2812}
2813
[email protected]87717d0e2012-04-26 02:58:432814void WebContentsImpl::DocumentAvailableInMainFrame(
2815 RenderViewHost* render_view_host) {
2816 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2817 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102818}
2819
[email protected]b172aee2012-04-10 17:05:262820void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082821 RenderViewHost* render_view_host,
2822 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072823 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272824 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322825 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532826 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082827}
2828
[email protected]196159d2012-05-04 17:26:542829void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2830 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262831 const content::Referrer& referrer,
2832 WindowOpenDisposition disposition,
2833 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542834 // If this came from a swapped out RenderViewHost, we only allow the request
2835 // if we are still in the same BrowsingInstance.
2836 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2837 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2838 return;
2839 }
2840
[email protected]4ad5d77d2011-12-03 02:00:482841 // Delegate to RequestTransferURL because this is just the generic
2842 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582843 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482844 GlobalRequestID());
2845}
2846
[email protected]b172aee2012-04-10 17:05:262847void WebContentsImpl::RequestTransferURL(
2848 const GURL& url,
2849 const content::Referrer& referrer,
2850 WindowOpenDisposition disposition,
2851 int64 source_frame_id,
2852 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202853 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582854 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582855 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352856 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322857 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2858 // generated suggestions).
2859 //
[email protected]e0112912011-02-02 22:54:352860 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162861 // want web sites to see a referrer of "chrome://blah" (and some
2862 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322863 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432864 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222865 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482866 false /* is_renderer_initiated */);
2867 params.transferred_global_request_id = old_request_id;
2868 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222869 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322870 } else {
[email protected]6bf6a6b52012-02-03 15:41:432871 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482872 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2873 params.transferred_global_request_id = old_request_id;
2874 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582875 }
2876 if (new_contents) {
2877 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582879 DidOpenRequestedURL(new_contents,
2880 url,
2881 referrer,
2882 disposition,
2883 transition_type,
2884 source_frame_id));
[email protected]420ae012009-04-24 05:16:322885 }
2886}
2887
[email protected]e1c3a552012-05-04 20:51:322888void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2889 // Tell the active RenderViewHost to run unload handlers and close, as long
2890 // as the request came from a RenderViewHost in the same BrowsingInstance.
2891 // In most cases, we receive this from a swapped out RenderViewHost.
2892 // It is possible to receive it from one that has just been swapped in,
2893 // in which case we might as well deliver the message anyway.
2894 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2895 GetRenderViewHost()->ClosePage();
2896}
2897
[email protected]f546640b2012-05-15 00:03:492898void WebContentsImpl::RouteMessageEvent(
2899 RenderViewHost* rvh,
2900 const ViewMsg_PostMessage_Params& params) {
2901 // Only deliver the message to the active RenderViewHost if the request
2902 // came from a RenderViewHost in the same BrowsingInstance.
2903 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2904 return;
2905
2906 ViewMsg_PostMessage_Params new_params(params);
2907
[email protected]0720b532012-08-28 19:23:372908 // If the renderer has changed while the post message is being routed,
2909 // drop the message, as it will not be delivered to the right target.
2910 if (GetRenderViewHost()->GetProcess()->GetID() != params.target_process_id)
2911 return;
2912 DCHECK(params.target_frame_id != 0);
2913
[email protected]f546640b2012-05-15 00:03:492914 // If there is a source_routing_id, translate it to the routing ID for
2915 // the equivalent swapped out RVH in the target process. If we need
2916 // to create a swapped out RVH for the source tab, we create its opener
2917 // chain as well, since those will also be accessible to the target page.
2918 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2919 // Try to look up the WebContents for the source page.
2920 WebContentsImpl* source_contents = NULL;
2921 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2922 rvh->GetProcess()->GetID(), params.source_routing_id);
2923 if (source_rvh) {
2924 source_contents = static_cast<WebContentsImpl*>(
2925 source_rvh->GetDelegate()->GetAsWebContents());
2926 }
2927
2928 if (source_contents) {
2929 new_params.source_routing_id =
2930 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2931 } else {
2932 // We couldn't find it, so don't pass a source frame.
2933 new_params.source_routing_id = MSG_ROUTING_NONE;
2934 }
2935 }
2936
2937 // In most cases, we receive this from a swapped out RenderViewHost.
2938 // It is possible to receive it from one that has just been swapped in,
2939 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182940 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492941}
2942
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342944 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412945 const string16& message,
2946 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322947 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142948 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322949 IPC::Message* reply_msg,
2950 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072951 // Suppress JavaScript dialogs when requested. Also suppress messages when
2952 // showing an interstitial as it's shown over the previous page and we don't
2953 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502954 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582955 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272956 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072957 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522958 delegate_->ShouldSuppressDialogs() ||
2959 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322960
2961 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432962 std::string accept_lang = content::GetContentClient()->browser()->
2963 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552964 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522965 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432966 this,
2967 frame_url.GetOrigin(),
2968 accept_lang,
2969 javascript_message_type,
2970 message,
[email protected]51da7e32012-01-30 19:24:522971 default_prompt,
[email protected]b172aee2012-04-10 17:05:262972 base::Bind(&WebContentsImpl::OnDialogClosed,
2973 base::Unretained(this),
2974 rvh,
2975 reply_msg),
[email protected]51da7e32012-01-30 19:24:522976 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322977 }
[email protected]3ab9cb82011-06-03 18:02:072978
2979 if (suppress_this_message) {
2980 // If we are suppressing messages, just reply as if the user immediately
2981 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342982 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072983 }
2984
2985 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322986}
2987
[email protected]b172aee2012-04-10 17:05:262988void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2989 const string16& message,
2990 bool is_reload,
2991 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582992 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512993 if (delegate_)
2994 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072995
2996 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582997 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072998 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522999 delegate_->ShouldSuppressDialogs() ||
3000 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153001 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343002 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583003 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503004 return;
3005 }
[email protected]3ab9cb82011-06-03 18:02:073006
[email protected]7ab1e7d62009-10-14 23:32:013007 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553008 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523009 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323010 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263011 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523012 reply_msg));
[email protected]420ae012009-04-24 05:16:323013}
3014
[email protected]a796f202012-05-30 14:14:253015bool WebContentsImpl::AddMessageToConsole(int32 level,
3016 const string16& message,
3017 int32 line_no,
3018 const string16& source_id) {
3019 if (!delegate_)
3020 return false;
3021 return delegate_->AddMessageToConsole(this, level, message, line_no,
3022 source_id);
3023}
3024
[email protected]b172aee2012-04-10 17:05:263025WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333026 // We want to base the page config off of the real URL, rather than the
3027 // display URL.
3028 GURL url = controller_.GetActiveEntry()
3029 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3030 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323031}
3032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273034 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253035 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223036
[email protected]ea114722012-03-12 01:11:253037 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173038 if (rdh) // NULL in unittests.
3039 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253040}
3041
[email protected]b172aee2012-04-10 17:05:263042void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443043 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253044 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443045}
3046
[email protected]b172aee2012-04-10 17:05:263047void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3048 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153049 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523050 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153051 return;
3052
[email protected]9f76c1e2012-03-05 15:15:583053 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3054
[email protected]e5fc1632011-08-08 07:51:533055 // Ignore renderer unresponsive event if debugger is attached to the tab
3056 // since the event may be a result of the renderer sitting on a breakpoint.
3057 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443058 DevToolsAgentHost* agent =
3059 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3060 if (agent &&
3061 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533062 return;
3063
[email protected]420ae012009-04-24 05:16:323064 if (is_during_unload) {
3065 // Hang occurred while firing the beforeunload/unload handler.
3066 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583067 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323068
3069 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3070 return;
3071
3072 // If the tab hangs in the beforeunload/unload handler there's really
3073 // nothing we can do to recover. Pretend the unload listeners have
3074 // all fired and close the tab. If the hang is in the beforeunload handler
3075 // then the user will not have the option of cancelling the close.
3076 Close(rvh);
3077 return;
3078 }
3079
[email protected]9f76c1e2012-03-05 15:15:583080 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473081 return;
3082
[email protected]6934a702011-12-20 00:04:513083 if (delegate_)
3084 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323085}
3086
[email protected]b172aee2012-04-10 17:05:263087void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513088 if (delegate_)
3089 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323090}
3091
[email protected]b172aee2012-04-10 17:05:263092void WebContentsImpl::LoadStateChanged(
3093 const GURL& url,
3094 const net::LoadStateWithParam& load_state,
3095 uint64 upload_position,
3096 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323097 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563098 upload_position_ = upload_position;
3099 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503100 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203101 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303102 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213103 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323104 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463105 if (IsLoading()) {
3106 NotifyNavigationStateChanged(
3107 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3108 }
[email protected]420ae012009-04-24 05:16:323109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513112 if (delegate_)
3113 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253114}
3115
[email protected]b172aee2012-04-10 17:05:263116void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323117 bool proceed,
3118 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513119 if (delegate_)
3120 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323121}
3122
[email protected]b172aee2012-04-10 17:05:263123void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543124 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233125 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3126 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543127}
3128
[email protected]b172aee2012-04-10 17:05:263129void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103130 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263131 gfx::Size size = view_->GetContainerSize();
3132 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3133 // here during container initialization and normal window size will be set
3134 // later. In case of tab duplication this resizing to 0x0 prevents setting
3135 // normal size later so just ignore it.
3136 if (!size.IsEmpty())
3137 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323138}
3139
[email protected]b172aee2012-04-10 17:05:263140void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543141 NotifySwapped();
3142}
3143
[email protected]14392a52012-05-02 20:28:443144int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3145 SiteInstance* instance) {
3146 if (!opener_)
3147 return MSG_ROUTING_NONE;
3148
3149 // Recursively create RenderViews for anything else in the opener chain.
3150 return opener_->CreateOpenerRenderViews(instance);
3151}
3152
3153int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3154 int opener_route_id = MSG_ROUTING_NONE;
3155
3156 // If this tab has an opener, ensure it has a RenderView in the given
3157 // SiteInstance as well.
3158 if (opener_)
3159 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3160
[email protected]0720b532012-08-28 19:23:373161 // If any of the renderers for this WebContents has the same SiteInstance,
3162 // use it.
3163 if (render_manager_.current_host()->GetSiteInstance() == instance)
3164 return render_manager_.current_host()->GetRoutingID();
3165
3166 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3167 instance);
3168 if (rvh)
3169 return rvh->GetRoutingID();
3170
[email protected]14392a52012-05-02 20:28:443171 // Create a swapped out RenderView in the given SiteInstance if none exists,
3172 // setting its opener to the given route_id. Return the new view's route_id.
3173 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3174}
3175
[email protected]b172aee2012-04-10 17:05:263176NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193177 return GetController();
[email protected]3a3d47472010-07-15 21:03:543178}
3179
[email protected]b172aee2012-04-10 17:05:263180WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563181 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323182}
3183
[email protected]10f417c52011-12-28 21:04:233184NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263185 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323186 return controller_.GetLastCommittedEntry();
3187}
3188
[email protected]b172aee2012-04-10 17:05:263189bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443190 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443191 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323192 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523193
[email protected]420ae012009-04-24 05:16:323194 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443195 if (rwh_view)
3196 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323197
[email protected]74ce1ad2011-12-16 21:51:463198 // Make sure we use the correct starting page_id in the new RenderView.
3199 UpdateMaxPageIDIfNecessary(render_view_host);
3200 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583201 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463202
[email protected]7900bfdb2012-05-24 19:31:243203 std::string embedder_channel_name;
3204 int embedder_container_id;
3205 GetBrowserPluginEmbedderInfo(render_view_host,
3206 &embedder_channel_name,
3207 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583208 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493209 render_view_host)->CreateRenderView(string16(),
3210 opener_route_id,
3211 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243212 embedder_channel_name,
3213 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523214 return false;
[email protected]14392a52012-05-02 20:28:443215 }
[email protected]a4127722011-04-27 23:13:523216
[email protected]e60c0232011-11-11 19:56:353217#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503218 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3219 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443220 if (rwh_view) {
3221 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3222 render_widget_host->WasResized();
3223 }
[email protected]f8233cc2011-05-31 20:24:503224#endif
3225
[email protected]420ae012009-04-24 05:16:323226 return true;
3227}
3228
[email protected]b172aee2012-04-10 17:05:263229void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3230 IPC::Message* reply_msg,
3231 bool success,
3232 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543233 if (is_showing_before_unload_dialog_ && !success) {
3234 // If a beforeunload dialog is canceled, we need to stop the throbber from
3235 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293236 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353237 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543238
[email protected]3bbacc5b2012-04-17 17:46:153239 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543240 }
3241 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583242 static_cast<RenderViewHostImpl*>(
3243 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543244}
3245
[email protected]b172aee2012-04-10 17:05:263246void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123247 encoding_ = content::GetContentClient()->browser()->
3248 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103249}
[email protected]f45d2a72010-03-08 23:28:353250
[email protected]b172aee2012-04-10 17:05:263251void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463252 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263253 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573254 DownloadManager* dlm =
3255 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143256 if (!dlm)
3257 return;
3258 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263259 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143260 const NavigationEntry* entry = controller_.GetActiveEntry();
3261 if (entry)
3262 post_id = entry->GetPostID();
3263 }
[email protected]29a5ffc82012-03-13 19:35:583264 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143265 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143266 scoped_ptr<DownloadUrlParameters> params(
3267 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493268 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143269 params->set_post_id(post_id);
3270 params->set_prefer_cache(true);
3271 if (post_id >= 0)
3272 params->set_method("POST");
3273 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143274}
3275
[email protected]b172aee2012-04-10 17:05:263276void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213277 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443278 // Can be NULL during tests.
3279 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213280 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363281}
[email protected]9f76c1e2012-03-05 15:15:583282
[email protected]b172aee2012-04-10 17:05:263283RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583284 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3285}
[email protected]7900bfdb2012-05-24 19:31:243286
3287void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3288 content::RenderViewHost* render_view_host,
3289 std::string* embedder_channel_name,
3290 int* embedder_container_id) {
3291 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283292 old_browser_plugin_host()->embedder_render_process_host();
3293 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243294 int embedder_process_id =
3295 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3296 if (embedder_process_id != -1) {
3297 *embedder_channel_name =
3298 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3299 embedder_process_id);
3300 }
3301}