blob: c8f374634b0827b092b5fa9d9cb5c9f41b633b63 [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]d353541f2012-05-03 22:45:4174#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0175#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4176#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5277#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2478#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3679#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3180#include "webkit/glue/webpreferences.h"
81
[email protected]f66df822012-05-18 16:52:1782#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5083#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4184#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5785#endif
[email protected]3e45ba92009-02-20 21:09:0086
[email protected]c71fe6402012-08-15 15:22:5587#if defined(USE_AURA) && defined(USE_X11)
88#include "ui/base/touch/touch_factory.h"
89#endif // defined (USE_AURA) && defined(USE_X11)
90
[email protected]420ae012009-04-24 05:16:3291// Cross-Site Navigations
92//
[email protected]b172aee2012-04-10 17:05:2693// If a WebContentsImpl is told to navigate to a different web site (as
94// determined by SiteInstance), it will replace its current RenderViewHost with
95// a new RenderViewHost dedicated to the new SiteInstance. This works as
96// follows:
[email protected]420ae012009-04-24 05:16:3297//
98// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4699// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32100// - The pending RVH is "suspended," so that no navigation messages are sent to
101// its renderer until the onbeforeunload JavaScript handler has a chance to
102// run in the current RVH.
103// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
104// that it has a pending cross-site request. ResourceDispatcherHost will
105// check for this when the response arrives.
106// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46107// cancel all the pending logic. Otherwise we allow the pending RVH to send
108// the navigation request to its renderer.
109// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
110// main resource load on the pending RVH. It checks CrossSiteRequestManager
111// to see that it is a cross-site request, and installs a
112// CrossSiteResourceHandler.
113// - When RDH receives a response, the BufferedResourceHandler determines
114// whether it is a download. If so, it sends a message to the new renderer
115// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26116// pending RVH remains until the next DidNavigate event for this
117// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32118// - After RDH receives a response and determines that it is safe and not a
119// download, it pauses the response to first run the old page's onunload
120// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26121// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32122// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15123// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32124// the ResourceDispatcherHost, who unpauses the response. Data is then sent
125// to the pending RVH.
126// - The pending renderer sends a FrameNavigate message that invokes the
127// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46128// pending RVH.
[email protected]992db4c2011-05-12 15:37:15129// - The previous renderer is kept swapped out in RenderViewHostManager in case
130// the user goes back. The process only stays live if another tab is using
131// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32132
[email protected]b441a8492012-06-06 14:55:57133using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44134using content::DevToolsAgentHost;
135using content::DevToolsAgentHostRegistry;
136using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17137using content::DownloadItem;
138using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14139using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20140using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56141using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13142using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27143using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54144using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50145using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23146using content::NavigationEntry;
147using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20148using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11149using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57150using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57151using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27152using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11153using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50154using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58155using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04156using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25157using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14158using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43159using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33160using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38161using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09162using content::WebContents;
[email protected]eda238a12012-09-07 23:44:00163using content::WebContentsDelegate;
[email protected]d8c660432011-12-22 20:51:25164using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56165using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22166using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50167using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25168using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44169
[email protected]420ae012009-04-24 05:16:32170namespace {
171
172// Amount of time we wait between when a key event is received and the renderer
173// is queried for its state and pushed to the NavigationEntry.
174const int kQueryStateDelay = 5000;
175
[email protected]6ebdc9b2010-09-27 16:55:57176const int kSyncWaitDelay = 40;
177
[email protected]82114f52012-03-20 22:53:41178const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05179
[email protected]420ae012009-04-24 05:16:32180#if defined(OS_WIN)
181
182BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
183 // Note: erase is required to properly paint some widgets borders. This can
184 // be seen with textfields.
185 InvalidateRect(hwnd, NULL, TRUE);
186 return TRUE;
187}
188#endif
189
[email protected]2c5569662011-03-22 20:45:02190ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23191 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50192 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16193 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47194 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47196 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23198 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
199 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47200 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16201 break; // Fall through to rest of function.
202 }
[email protected]5e369672009-11-03 23:48:30203
[email protected]59246c572012-02-10 13:32:13204 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
205 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23206 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13207 browser_context->DidLastSessionExitCleanly()) {
208 if (entry.GetHasPostData())
209 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02210 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13211 }
[email protected]5e369672009-11-03 23:48:30212
[email protected]2c5569662011-03-22 20:45:02213 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30214}
215
[email protected]10f417c52011-12-28 21:04:23216void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47217 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42218 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50219 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24220 const std::string& embedder_channel_name,
221 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16222 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51223 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54224 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55225 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
226 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36227 if (!entry.GetBaseURLForDataURL().is_empty()) {
228 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
229 params->history_url_for_data_url = entry.GetVirtualURL();
230 }
[email protected]36fc0392011-12-25 03:59:51231 params->referrer = entry.GetReferrer();
232 params->transition = entry.GetTransitionType();
233 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00234 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55235 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34236 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47237 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48238 params->transferred_request_child_id =
239 entry.transferred_global_request_id().child_id;
240 params->transferred_request_request_id =
241 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22242 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00243 // Avoid downloading when in view-source mode.
244 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24245 params->embedder_channel_name = embedder_channel_name;
246 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44247 params->is_post = entry.GetHasPostData();
248 if(entry.GetBrowserInitiatedPostData()) {
249 params->browser_initiated_post_data.assign(
250 entry.GetBrowserInitiatedPostData()->front(),
251 entry.GetBrowserInitiatedPostData()->front() +
252 entry.GetBrowserInitiatedPostData()->size());
253
254 }
[email protected]6c6b02d2011-09-02 03:36:47255
[email protected]7c16976c2012-08-04 02:38:23256 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
257 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
258 // We may have been redirected when navigating to the current URL.
259 // Use the URL the user originally intended to visit, if it's valid and if a
260 // POST wasn't involved; the latter case avoids issues with sending data to
261 // the wrong page.
262 params->url = entry.GetOriginalRequestURL();
263 } else {
264 params->url = entry.GetURL();
265 }
266
[email protected]6c6b02d2011-09-02 03:36:47267 if (delegate)
268 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34269}
270
[email protected]f98f5092012-05-19 00:08:14271int GetSwitchValueAsInt(
272 const CommandLine& command_line,
273 const std::string& switch_string,
274 int min_value) {
275 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
276 int int_value;
277 if (base::StringToInt(string_value, &int_value))
278 return std::max(min_value, int_value);
279 else
280 return min_value;
281}
282
[email protected]420ae012009-04-24 05:16:32283} // namespace
284
[email protected]a81343d232011-12-27 07:39:20285namespace content {
286
287WebContents* WebContents::Create(
288 BrowserContext* browser_context,
289 SiteInstance* site_instance,
290 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19291 const WebContents* base_web_contents) {
292 return WebContentsImpl::Create(
293 browser_context, site_instance, routing_id,
294 static_cast<const WebContentsImpl*>(base_web_contents));
295}
296
297WebContents* WebContents::CreateWithSessionStorage(
298 BrowserContext* browser_context,
299 SiteInstance* site_instance,
300 int routing_id,
[email protected]b172aee2012-04-10 17:05:26301 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19302 const SessionStorageNamespaceMap& session_storage_namespace_map) {
303 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
304
305 for (SessionStorageNamespaceMap::const_iterator it =
306 session_storage_namespace_map.begin();
307 it != session_storage_namespace_map.end();
308 ++it) {
309 new_contents->GetController().SetSessionStorageNamespace(it->first,
310 it->second);
311 }
312
313 new_contents->Init(browser_context, site_instance, routing_id,
314 static_cast<const WebContentsImpl*>(base_web_contents));
315 return new_contents;
[email protected]a81343d232011-12-27 07:39:20316}
[email protected]746d3052012-05-22 15:15:47317
[email protected]299d7f12012-05-23 05:31:15318WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47319 return rvh->GetDelegate()->GetAsWebContents();
320}
321
[email protected]a81343d232011-12-27 07:39:20322}
[email protected]f4f50ef2011-01-21 19:01:19323
[email protected]b172aee2012-04-10 17:05:26324// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32325
[email protected]b172aee2012-04-10 17:05:26326WebContentsImpl::WebContentsImpl(
327 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19328 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42329 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19330 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57331 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44332 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05333 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34334 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23335 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
336 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34337 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21338 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56339 upload_size_(0),
340 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47341 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57342 capturing_contents_(false),
343 is_being_destroyed_(false),
344 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55345 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57346#if defined(OS_WIN)
347 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
348#endif
[email protected]7ab1e7d62009-10-14 23:32:01349 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56350 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38351 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25352 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01353 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25354 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01355 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00356 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43357 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20358 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35359}
initial.commit09911bf2008-07-26 23:55:29360
[email protected]b172aee2012-04-10 17:05:26361WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32362 is_being_destroyed_ = true;
363
[email protected]3ab9cb82011-06-03 18:02:07364 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55365 if (dialog_creator_)
366 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07367
[email protected]da8543762012-03-20 08:52:20368 if (color_chooser_)
369 color_chooser_->End();
370
[email protected]420ae012009-04-24 05:16:32371 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32372
[email protected]ca13a442012-04-17 14:00:12373 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07374 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09375 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
376 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07377 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32378
379 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07380#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32381 // If we still have a window handle, destroy it. GetNativeView can return
382 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42383 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52384 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58385 if (host && host->GetView())
386 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42387 }
[email protected]420ae012009-04-24 05:16:32388#endif
[email protected]7ab1e7d62009-10-14 23:32:01389
390 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15391 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01392 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15393 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01394 }
[email protected]b5a1d11c2011-02-17 03:09:42395
[email protected]2db9bd72012-04-13 20:20:56396 FOR_EACH_OBSERVER(WebContentsObserver,
397 observers_,
398 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08399
[email protected]6934a702011-12-20 00:04:51400 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42401}
402
[email protected]d1198fd2012-08-13 22:50:19403WebContentsImpl* WebContentsImpl::Create(
404 BrowserContext* browser_context,
405 SiteInstance* site_instance,
406 int routing_id,
407 const WebContentsImpl* base_web_contents) {
408 return CreateWithOpener(browser_context, site_instance, routing_id,
409 base_web_contents, NULL);
410}
411
412WebContentsImpl* WebContentsImpl::CreateWithOpener(
413 BrowserContext* browser_context,
414 SiteInstance* site_instance,
415 int routing_id,
416 const WebContentsImpl* base_web_contents,
417 WebContentsImpl* opener) {
418 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
419
420 new_contents->Init(browser_context, site_instance, routing_id,
421 static_cast<const WebContentsImpl*>(base_web_contents));
422 return new_contents;
423}
424
[email protected]b172aee2012-04-10 17:05:26425WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
426 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54427 WebPreferences prefs;
428
429 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
430
431 prefs.developer_extras_enabled = true;
432 prefs.javascript_enabled =
433 !command_line.HasSwitch(switches::kDisableJavaScript);
434 prefs.web_security_enabled =
435 !command_line.HasSwitch(switches::kDisableWebSecurity);
436 prefs.plugins_enabled =
437 !command_line.HasSwitch(switches::kDisablePlugins);
438 prefs.java_enabled =
439 !command_line.HasSwitch(switches::kDisableJava);
440
441 prefs.uses_page_cache =
442 command_line.HasSwitch(switches::kEnableFastback);
443 prefs.remote_fonts_enabled =
444 !command_line.HasSwitch(switches::kDisableRemoteFonts);
445 prefs.xss_auditor_enabled =
446 !command_line.HasSwitch(switches::kDisableXSSAuditor);
447 prefs.application_cache_enabled =
448 !command_line.HasSwitch(switches::kDisableApplicationCache);
449
450 prefs.local_storage_enabled =
451 !command_line.HasSwitch(switches::kDisableLocalStorage);
452 prefs.databases_enabled =
453 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01454#if defined(OS_ANDROID)
455 prefs.webaudio_enabled =
456 command_line.HasSwitch(switches::kEnableWebAudio);
457#else
[email protected]64d69de42012-02-06 00:19:54458 prefs.webaudio_enabled =
459 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01460#endif
[email protected]64d69de42012-02-06 00:19:54461
462 prefs.experimental_webgl_enabled =
463 GpuProcessHost::gpu_enabled() &&
464 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07465#if defined(OS_ANDROID)
466 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
467#else
[email protected]64d69de42012-02-06 00:19:54468 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07469#endif
[email protected]64d69de42012-02-06 00:19:54470
[email protected]5a073092012-06-08 00:42:51471 prefs.flash_3d_enabled =
472 GpuProcessHost::gpu_enabled() &&
473 !command_line.HasSwitch(switches::kDisableFlash3d);
474 prefs.flash_stage3d_enabled =
475 GpuProcessHost::gpu_enabled() &&
476 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19477
[email protected]64d69de42012-02-06 00:19:54478 prefs.gl_multisampling_enabled =
479 !command_line.HasSwitch(switches::kDisableGLMultisampling);
480 prefs.privileged_webgl_extensions_enabled =
481 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
482 prefs.site_specific_quirks_enabled =
483 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
484 prefs.allow_file_access_from_file_urls =
485 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
486 prefs.show_composited_layer_borders =
487 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
488 prefs.show_composited_layer_tree =
489 command_line.HasSwitch(switches::kShowCompositedLayerTree);
490 prefs.show_fps_counter =
491 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19492 prefs.show_paint_rects =
493 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52494 prefs.render_vsync_enabled =
495 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54496 prefs.accelerated_compositing_enabled =
497 GpuProcessHost::gpu_enabled() &&
498 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54499 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23500 command_line.HasSwitch(switches::kForceCompositingMode) &&
501 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54502 prefs.fixed_position_compositing_enabled =
503 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
504 prefs.accelerated_2d_canvas_enabled =
505 GpuProcessHost::gpu_enabled() &&
506 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58507 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27508 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54509 prefs.accelerated_painting_enabled =
510 GpuProcessHost::gpu_enabled() &&
511 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
512 prefs.accelerated_filters_enabled =
513 GpuProcessHost::gpu_enabled() &&
514 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
515 prefs.accelerated_layers_enabled =
516 prefs.accelerated_animation_enabled =
517 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54518 prefs.accelerated_plugins_enabled =
519 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
520 prefs.accelerated_video_enabled =
521 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54522 prefs.fullscreen_enabled =
523 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16524 prefs.css_regions_enabled =
525 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29526 prefs.css_shaders_enabled =
527 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01528 prefs.css_variables_enabled =
529 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]8de0a372012-09-07 22:09:00530 prefs.device_supports_touch =
531 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]c71fe6402012-08-15 15:22:55532#if defined(USE_AURA) && defined(USE_X11)
533 prefs.device_supports_touch |=
534 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
535#endif
[email protected]d849b122012-07-18 07:35:26536#if defined(OS_ANDROID)
537 prefs.device_supports_mouse = false;
538#endif
[email protected]64d69de42012-02-06 00:19:54539
540#if defined(OS_MACOSX)
541 bool default_enable_scroll_animator = true;
542#else
543 // On CrOS, the launcher always passes in the --enable flag.
544 bool default_enable_scroll_animator = false;
545#endif
546 prefs.enable_scroll_animator = default_enable_scroll_animator;
547 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
548 prefs.enable_scroll_animator = true;
549 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
550 prefs.enable_scroll_animator = false;
551
552 prefs.visual_word_movement_enabled =
553 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54554
555 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32556 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54557 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39558 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]d56ecf922012-02-15 16:03:11559 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54560 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11561 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54562 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19563 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
564 prefs.flash_3d_enabled = false;
565 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
566 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11567 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54568 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11569 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54570 prefs.gl_multisampling_enabled = false;
571
572 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45573 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32574 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54575 prefs.accelerated_video_enabled = false;
576 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45577 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09578 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54579 }
580 }
581
[email protected]b9535422012-02-09 01:47:59582 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58583 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54584 prefs.loads_images_automatically = true;
585 prefs.javascript_enabled = true;
586 }
587
588 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
589
590 // Force accelerated compositing and 2d canvas off for chrome:, about: and
591 // chrome-devtools: pages (unless it's specifically allowed).
592 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54593 url.SchemeIs(chrome::kChromeUIScheme) ||
594 (url.SchemeIs(chrome::kAboutScheme) &&
595 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25596 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54597 prefs.accelerated_compositing_enabled = false;
598 prefs.accelerated_2d_canvas_enabled = false;
599 }
[email protected]43d9d782012-03-01 15:40:09600
[email protected]f98f5092012-05-19 00:08:14601 if (command_line.HasSwitch(switches::kDefaultTileWidth))
602 prefs.default_tile_width =
603 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
604 if (command_line.HasSwitch(switches::kDefaultTileHeight))
605 prefs.default_tile_height =
606 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
607 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
608 prefs.max_untiled_layer_width =
609 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
610 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
611 prefs.max_untiled_layer_height =
612 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
613
[email protected]2486dce2012-05-23 17:18:19614 if (gfx::Screen::IsDIPEnabled()) {
615 // Only apply when using DIP coordinate system as this setting interferes
616 // with fixed layout mode.
617 prefs.apply_default_device_scale_factor_in_compositor = true;
618 }
619
[email protected]de023762012-07-26 17:10:17620 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
621 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10622
[email protected]3f7e2062012-09-04 16:38:12623 prefs.gesture_tap_highlight_enabled = !command_line.HasSwitch(
624 switches::kDisableGestureTapHighlight);
625
[email protected]6b4dcb072012-06-18 22:26:51626 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
627
[email protected]2e21fe292012-03-02 22:52:32628 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54629
630 return prefs;
631}
632
[email protected]b172aee2012-04-10 17:05:26633RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28634 return &render_manager_;
635}
636
[email protected]7bb761892012-07-20 09:32:47637bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
638 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56639 if (GetWebUI() &&
640 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17641 return true;
[email protected]d2353452012-01-19 19:53:56642 }
[email protected]f82d57b52011-04-27 19:13:17643
[email protected]d8c660432011-12-22 20:51:25644 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
645 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10646 while ((observer = it.GetNext()) != NULL)
647 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53648 return true;
[email protected]403415a2011-01-10 18:57:53649
[email protected]7bb761892012-07-20 09:32:47650 // Message handlers should be aware of which RenderViewHost sent the
651 // message, which is temporarily stored in message_source_.
652 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18653 bool handled = true;
654 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26655 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58656 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
657 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24658 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
659 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18660 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
661 OnDidLoadResourceFromMemoryCache)
662 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
663 OnDidDisplayInsecureContent)
664 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
665 OnDidRunInsecureContent)
666 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
667 OnDocumentLoadedInFrame)
668 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26669 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
670 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17671 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
672 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25673 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26674 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59675 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21676 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20677 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
678 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
679 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16680 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]59363fc92012-09-05 03:46:31681#if defined(OS_ANDROID)
682 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
683 OnFindMatchRectsReply)
684#endif
[email protected]d952a052011-09-06 18:42:45685 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10686 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20687 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
690 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29691 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50692 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50693 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
694 OnRequestPpapiBrokerPermission)
[email protected]724159a2010-12-30 01:11:18695 IPC_MESSAGE_UNHANDLED(handled = false)
696 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47697 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18698
699 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38700 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18701 GetRenderProcessHost()->ReceivedBadMessage();
702 }
703
704 return handled;
705}
706
[email protected]b172aee2012-04-10 17:05:26707void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18708 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23709 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43710 if (delegate_)
711 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18712}
713
[email protected]d1198fd2012-08-13 22:50:19714NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56715 return controller_;
716}
717
[email protected]d1198fd2012-08-13 22:50:19718const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56719 return controller_;
720}
721
[email protected]b172aee2012-04-10 17:05:26722content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55723 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30724}
725
[email protected]b172aee2012-04-10 17:05:26726const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31727 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23728 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51729 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31730}
731
[email protected]b172aee2012-04-10 17:05:26732content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31733 return delegate_;
734}
735
[email protected]b172aee2012-04-10 17:05:26736void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31737 // TODO(cbentzel): remove this debugging code?
738 if (delegate == delegate_)
739 return;
740 if (delegate_)
741 delegate_->Detach(this);
742 delegate_ = delegate;
743 if (delegate_)
744 delegate_->Attach(this);
745}
746
[email protected]b172aee2012-04-10 17:05:26747content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41748 RenderViewHostImpl* host = render_manager_.current_host();
749 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16750}
751
[email protected]b172aee2012-04-10 17:05:26752RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31753 return render_manager_.current_host();
754}
755
[email protected]6b618e62012-08-16 12:59:18756int WebContentsImpl::GetRoutingID() const {
757 if (!GetRenderViewHost())
758 return MSG_ROUTING_NONE;
759
760 return GetRenderViewHost()->GetRoutingID();
761}
762
[email protected]b172aee2012-04-10 17:05:26763RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31764 return render_manager_.GetRenderWidgetHostView();
765}
766
[email protected]b172aee2012-04-10 17:05:26767content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31768 return view_.get();
769}
770
[email protected]b172aee2012-04-10 17:05:26771content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50772 WebUIControllerFactory* factory =
773 content::GetContentClient()->browser()->GetWebUIControllerFactory();
774 if (!factory)
775 return NULL;
[email protected]d2353452012-01-19 19:53:56776 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22777 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50778 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22779 if (controller) {
780 web_ui->SetController(controller);
781 return web_ui;
782 }
783
784 delete web_ui;
785 return NULL;
786}
787
[email protected]b172aee2012-04-10 17:05:26788content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31789 return render_manager_.web_ui() ? render_manager_.web_ui()
790 : render_manager_.pending_web_ui();
791}
792
[email protected]b172aee2012-04-10 17:05:26793content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31794 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34795}
796
[email protected]86ef6a392012-05-11 22:03:11797void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22798 if (GetUserAgentOverride() == override)
799 return;
800
801 renderer_preferences_.user_agent_override = override;
802
803 // Send the new override string to the renderer.
804 RenderViewHost* host = GetRenderViewHost();
805 if (host)
806 host->SyncRendererPrefs();
807
808 // Reload the page if a load is currently in progress to avoid having
809 // different parts of the page loaded using different user agents.
810 NavigationEntry* entry = controller_.GetActiveEntry();
811 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
812 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53813
814 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
815 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11816}
817
818const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22819 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11820}
821
[email protected]b172aee2012-04-10 17:05:26822const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55823 // Transient entries take precedence. They are used for interstitial pages
824 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23825 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08826 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20827 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30828 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23829 if (entry) {
[email protected]b5cca982011-05-26 04:42:08830 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23831 }
[email protected]7ade2732011-02-10 00:13:58832 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
833 render_manager_.pending_web_ui() : render_manager_.web_ui();
834 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54835 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55836 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54837 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35838 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22839 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54840 if (!title.empty())
841 return title;
842 }
843 }
844
845 // We use the title for the last committed entry rather than a pending
846 // navigation entry. For example, when the user types in a URL, we want to
847 // keep the old page's title until the new load has committed and we get a new
848 // title.
[email protected]96d185d2009-04-24 03:28:54849 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23850 if (entry) {
[email protected]b5cca982011-05-26 04:42:08851 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23852 }
[email protected]987fc3a2011-05-26 14:18:09853
854 // |page_title_when_no_navigation_entry_| is finally used
855 // if no title cannot be retrieved.
856 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54857}
858
[email protected]b172aee2012-04-10 17:05:26859int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46860 return GetMaxPageIDForSiteInstance(GetSiteInstance());
861}
862
[email protected]b172aee2012-04-10 17:05:26863int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
864 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33865 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
866 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46867
[email protected]b6583592012-01-25 19:52:33868 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34869}
870
[email protected]b172aee2012-04-10 17:05:26871void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46872 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
873}
874
[email protected]b172aee2012-04-10 17:05:26875void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33876 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46877 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33878 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34879}
880
[email protected]b172aee2012-04-10 17:05:26881void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
882 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57883}
884
[email protected]b172aee2012-04-10 17:05:26885SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58886 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54887}
888
[email protected]b172aee2012-04-10 17:05:26889SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38890 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
891 render_manager_.pending_render_view_host() :
892 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58893 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38894}
895
[email protected]b172aee2012-04-10 17:05:26896bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31897 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49898}
899
[email protected]b172aee2012-04-10 17:05:26900bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31901 return waiting_for_response_;
902}
903
[email protected]b172aee2012-04-10 17:05:26904const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31905 return load_state_;
906}
907
[email protected]b172aee2012-04-10 17:05:26908const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31909 return load_state_host_;
910}
911
[email protected]b172aee2012-04-10 17:05:26912uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return upload_size_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31917 return upload_position_;
918}
919
[email protected]b172aee2012-04-10 17:05:26920const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31921 return encoding_;
922}
923
[email protected]b172aee2012-04-10 17:05:26924bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31925 return displayed_insecure_content_;
926}
927
[email protected]b172aee2012-04-10 17:05:26928void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31929 capturing_contents_ = cap;
930}
931
[email protected]b172aee2012-04-10 17:05:26932bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
934 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
935 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49936}
937
[email protected]b172aee2012-04-10 17:05:26938void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
939 int error_code) {
[email protected]443b80e2010-12-14 00:42:23940 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34941 return;
942
[email protected]443b80e2010-12-14 00:42:23943 crashed_status_ = status;
944 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46945 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34946}
947
[email protected]b172aee2012-04-10 17:05:26948base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31949 return crashed_status_;
950}
951
[email protected]b172aee2012-04-10 17:05:26952bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31953 return is_being_destroyed_;
954}
955
[email protected]b172aee2012-04-10 17:05:26956void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34957 if (delegate_)
958 delegate_->NavigationStateChanged(this, changed_flags);
959}
960
[email protected]3e324142012-06-25 18:26:33961base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
962 return last_selected_time_;
963}
964
[email protected]9e2e4632012-07-27 16:38:41965void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54966 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04967 RenderWidgetHostViewPort* rwhv =
968 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16969 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41970 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43971#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16972 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43973#endif
974 }
[email protected]96d185d2009-04-24 03:28:54975
[email protected]5ac20162010-11-24 23:33:11976 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38977
[email protected]9e2e4632012-07-27 16:38:41978 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59979
980 // The resize rect might have changed while this was inactive -- send the new
981 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58982 RenderViewHostImpl* rvh =
983 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59984 if (rvh) {
985 rvh->ResizeRectChanged(GetRootWindowResizerRect());
986 }
[email protected]96d185d2009-04-24 03:28:54987
[email protected]3e324142012-06-25 18:26:33988 bool is_visible = true;
989 content::NotificationService::current()->Notify(
990 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
991 content::Source<WebContents>(this),
992 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31993}
994
[email protected]b172aee2012-04-10 17:05:26995void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31996 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52997 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
998 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26999 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521000 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331001 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521002 // calls us).
[email protected]c30585c2012-02-16 15:02:041003 RenderWidgetHostViewPort* rwhv =
1004 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161005 if (rwhv)
1006 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541007 }
1008
[email protected]375fa1b2012-05-22 22:05:371009 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071010 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371011 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091012 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371013 content::Details<bool>(&is_visible));
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311017 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271018 return WillNotifyDisconnection() &&
1019 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581020 !static_cast<RenderViewHostImpl*>(
1021 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271025 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251026 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271027}
1028
[email protected]b172aee2012-04-10 17:05:261029WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441030 // We use our current SiteInstance since the cloned entry will use it anyway.
1031 // We pass |this| for the |base_web_contents| to size the view correctly, and
1032 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191033 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1034 GetSiteInstance(), MSG_ROUTING_NONE,
1035 this, opener_);
1036 tc->GetController().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271037 return tc;
1038}
1039
[email protected]b172aee2012-04-10 17:05:261040gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271041 return view_->GetContentNativeView();
1042}
1043
[email protected]b172aee2012-04-10 17:05:261044gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271045 return view_->GetNativeView();
1046}
1047
[email protected]b172aee2012-04-10 17:05:261048void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271049 view_->GetContainerBounds(out);
1050}
1051
[email protected]b172aee2012-04-10 17:05:261052void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271053 view_->Focus();
1054}
1055
[email protected]14392a52012-05-02 20:28:441056void WebContentsImpl::Observe(int type,
1057 const content::NotificationSource& source,
1058 const content::NotificationDetails& details) {
1059 switch (type) {
1060 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1061 OnWebContentsDestroyed(
1062 content::Source<content::WebContents>(source).ptr());
1063 break;
[email protected]bafe6cd2012-05-23 23:09:501064 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1065 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1066 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1067 i != pending_widget_views_.end(); ++i) {
1068 if (host->GetView() == i->second) {
1069 pending_widget_views_.erase(i);
1070 break;
1071 }
1072 }
1073 break;
1074 }
[email protected]14392a52012-05-02 20:28:441075 default:
1076 NOTREACHED();
1077 }
1078}
1079
[email protected]d1198fd2012-08-13 22:50:191080void WebContentsImpl::Init(BrowserContext* browser_context,
1081 SiteInstance* site_instance,
1082 int routing_id,
1083 const WebContents* base_web_contents) {
1084 render_manager_.Init(browser_context, site_instance, routing_id);
1085
1086 view_.reset(content::GetContentClient()->browser()->
1087 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1088 if (view_.get()) {
1089 CHECK(render_view_host_delegate_view_);
1090 } else {
1091 content::WebContentsViewDelegate* delegate =
1092 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1093 this);
1094 view_.reset(CreateWebContentsView(
1095 this, delegate, &render_view_host_delegate_view_));
1096 CHECK(render_view_host_delegate_view_);
1097 }
1098 CHECK(view_.get());
1099
1100 // We have the initial size of the view be based on the size of the view of
1101 // the passed in WebContents.
1102 view_->CreateView(base_web_contents ?
1103 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1104
1105 // Listen for whether our opener gets destroyed.
1106 if (opener_) {
1107 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1108 content::Source<WebContents>(opener_));
1109 }
1110
1111 registrar_.Add(this,
1112 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1113 content::NotificationService::AllBrowserContextsAndSources());
1114#if defined(ENABLE_JAVA_BRIDGE)
1115 java_bridge_dispatcher_host_manager_.reset(
1116 new JavaBridgeDispatcherHostManager(this));
1117#endif
1118
1119 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1120}
1121
[email protected]14392a52012-05-02 20:28:441122void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1123 // Clear the opener if it has been closed.
1124 if (web_contents == opener_) {
1125 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1126 content::Source<WebContents>(opener_));
1127 opener_ = NULL;
1128 }
1129}
1130
[email protected]b172aee2012-04-10 17:05:261131void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311132 observers_.AddObserver(observer);
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311136 observers_.RemoveObserver(observer);
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341140 if (delegate_)
1141 delegate_->ActivateContents(this);
1142}
1143
[email protected]b172aee2012-04-10 17:05:261144void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121145 if (delegate_)
1146 delegate_->DeactivateContents(this);
1147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481150 if (delegate_)
1151 delegate_->LostCapture();
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154bool WebContentsImpl::PreHandleKeyboardEvent(
1155 const NativeWebKeyboardEvent& event,
1156 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481157 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131158 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481159}
1160
[email protected]b172aee2012-04-10 17:05:261161void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481162 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131163 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481164}
1165
[email protected]b172aee2012-04-10 17:05:261166void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431167 if (delegate_)
1168 delegate_->HandleMouseDown();
1169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481172 if (delegate_)
1173 delegate_->HandleMouseUp();
1174}
1175
[email protected]590a634e2012-07-19 16:38:231176void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481177 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231178 delegate_->HandlePointerActivate();
1179}
1180
1181void WebContentsImpl::HandleGestureBegin() {
1182 if (delegate_)
1183 delegate_->HandleGestureBegin();
1184}
1185
1186void WebContentsImpl::HandleGestureEnd() {
1187 if (delegate_)
1188 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481189}
1190
[email protected]b172aee2012-04-10 17:05:261191void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471192 if (delegate_)
1193 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1194}
1195
[email protected]b172aee2012-04-10 17:05:261196bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381197 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121198}
1199
[email protected]a9c81f02012-06-01 00:15:441200void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1201 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371202 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441203 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371204 } else {
1205 GotResponseToLockMouseRequest(false);
1206 }
1207}
1208
[email protected]b172aee2012-04-10 17:05:261209void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371210 if (delegate_)
1211 delegate_->LostMouseLock();
1212}
1213
[email protected]bafe6cd2012-05-23 23:09:501214void WebContentsImpl::CreateNewWindow(
1215 int route_id,
[email protected]97714c82012-06-06 10:15:131216 const ViewHostMsg_CreateWindow_Params& params,
1217 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501218 if (delegate_ && !delegate_->ShouldCreateWebContents(
1219 this, route_id, params.window_container_type, params.frame_name,
1220 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091221 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501222 return;
1223 }
1224
1225 // We usually create the new window in the same BrowsingInstance (group of
1226 // script-related windows), by passing in the current SiteInstance. However,
1227 // if the opener is being suppressed, we create a new SiteInstance in its own
1228 // BrowsingInstance.
1229 scoped_refptr<SiteInstance> site_instance =
1230 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571231 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501232 GetSiteInstance();
1233
1234 // Create the new web contents. This will automatically create the new
1235 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191236 WebContentsImpl* new_contents =
1237 new WebContentsImpl(GetBrowserContext(),
1238 params.opener_suppressed ? NULL : this);
1239
1240 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341241 //
1242 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191243 const std::string& partition_id =
1244 content::GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571245 GetStoragePartitionIdForSite(GetBrowserContext(),
1246 site_instance->GetSite());
[email protected]4c3a23582012-08-18 08:54:341247 content::StoragePartition* partition =
1248 BrowserContext::GetStoragePartition(GetBrowserContext(),
1249 site_instance);
[email protected]d1198fd2012-08-13 22:50:191250 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341251 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191252 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1253 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1254 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1255 new_contents->GetController().SetSessionStorageNamespace(
1256 partition_id,
1257 session_storage_namespace);
1258 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1259
[email protected]bafe6cd2012-05-23 23:09:501260 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1261
1262 if (!params.opener_suppressed) {
1263 content::WebContentsView* new_view = new_contents->GetView();
1264
1265 // TODO(brettw): It seems bogus that we have to call this function on the
1266 // newly created object and give it one of its own member variables.
1267 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1268
1269 // Save the created window associated with the route so we can show it
1270 // later.
1271 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1272 pending_contents_[route_id] = new_contents;
1273 }
1274
1275 if (delegate_) {
1276 delegate_->WebContentsCreated(
1277 this, params.opener_frame_id, params.target_url, new_contents);
1278 }
1279
1280 if (params.opener_suppressed) {
1281 // When the opener is suppressed, the original renderer cannot access the
1282 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001283 bool was_blocked = false;
1284 if (delegate_) {
1285 gfx::Rect initial_pos;
1286 delegate_->AddNewContents(
1287 this, new_contents, params.disposition, initial_pos,
1288 params.user_gesture, &was_blocked);
1289 }
1290 if (!was_blocked) {
1291 content::OpenURLParams open_params(params.target_url,
1292 content::Referrer(),
1293 CURRENT_TAB,
1294 content::PAGE_TRANSITION_LINK,
1295 true /* is_renderer_initiated */);
1296 new_contents->OpenURL(open_params);
1297 }
[email protected]bafe6cd2012-05-23 23:09:501298 }
1299}
1300
1301void WebContentsImpl::CreateNewWidget(int route_id,
1302 WebKit::WebPopupType popup_type) {
1303 CreateNewWidget(route_id, false, popup_type);
1304}
1305
1306void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1307 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1308}
1309
1310void WebContentsImpl::CreateNewWidget(int route_id,
1311 bool is_fullscreen,
1312 WebKit::WebPopupType popup_type) {
1313 content::RenderProcessHost* process = GetRenderProcessHost();
1314 RenderWidgetHostImpl* widget_host =
1315 new RenderWidgetHostImpl(this, process, route_id);
1316 RenderWidgetHostViewPort* widget_view =
1317 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1318 if (!is_fullscreen) {
1319 // Popups should not get activated.
1320 widget_view->SetPopupType(popup_type);
1321 }
1322 // Save the created widget associated with the route so we can show it later.
1323 pending_widget_views_[route_id] = widget_view;
1324
1325#if defined(OS_MACOSX)
1326 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1327 // to allow it to survive the trip without being hosted.
1328 base::mac::NSObjectRetain(widget_view->GetNativeView());
1329#endif
1330}
1331
1332void WebContentsImpl::ShowCreatedWindow(int route_id,
1333 WindowOpenDisposition disposition,
1334 const gfx::Rect& initial_pos,
1335 bool user_gesture) {
1336 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001337 if (contents) {
1338 WebContentsDelegate* delegate = GetDelegate();
1339 if (delegate) {
1340 delegate->AddNewContents(
1341 this, contents, disposition, initial_pos, user_gesture, NULL);
1342 }
1343 }
[email protected]bafe6cd2012-05-23 23:09:501344}
1345
1346void WebContentsImpl::ShowCreatedWidget(int route_id,
1347 const gfx::Rect& initial_pos) {
1348 ShowCreatedWidget(route_id, false, initial_pos);
1349}
1350
1351void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1352 ShowCreatedWidget(route_id, true, gfx::Rect());
1353}
1354
1355void WebContentsImpl::ShowCreatedWidget(int route_id,
1356 bool is_fullscreen,
1357 const gfx::Rect& initial_pos) {
1358 if (delegate_)
1359 delegate_->RenderWidgetShowing();
1360
1361 RenderWidgetHostViewPort* widget_host_view =
1362 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1363 if (!widget_host_view)
1364 return;
1365 if (is_fullscreen) {
1366 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1367 } else {
1368 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1369 }
[email protected]89054502012-06-03 10:29:241370
1371 RenderWidgetHostImpl* render_widget_host_impl =
1372 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1373 render_widget_host_impl->Init();
1374 // Only allow privileged mouse lock for fullscreen render widget, which is
1375 // used to implement Pepper Flash fullscreen.
1376 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501377
1378#if defined(OS_MACOSX)
1379 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1380 // properly embedded (or purposefully ignored) we can release the retain we
1381 // took in CreateNewWidget().
1382 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1383#endif
1384}
1385
1386WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1387 PendingContents::iterator iter = pending_contents_.find(route_id);
1388
1389 // Certain systems can block the creation of new windows. If we didn't succeed
1390 // in creating one, just return NULL.
1391 if (iter == pending_contents_.end()) {
1392 return NULL;
1393 }
1394
1395 WebContentsImpl* new_contents = iter->second;
1396 pending_contents_.erase(route_id);
1397
1398 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1399 !new_contents->GetRenderViewHost()->GetView())
1400 return NULL;
1401
1402 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1403 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1404 return new_contents;
1405}
1406
1407RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1408 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1409 if (iter == pending_widget_views_.end()) {
1410 DCHECK(false);
1411 return NULL;
1412 }
1413
1414 RenderWidgetHostView* widget_host_view = iter->second;
1415 pending_widget_views_.erase(route_id);
1416
1417 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1418 if (!widget_host->GetProcess()->HasConnection()) {
1419 // The view has gone away or the renderer crashed. Nothing to do.
1420 return NULL;
1421 }
1422
1423 return widget_host_view;
1424}
1425
1426void WebContentsImpl::ShowContextMenu(
[email protected]ba16e3a2012-09-07 04:14:521427 const content::ContextMenuParams& params,
1428 const content::ContextMenuSourceType& type) {
[email protected]bafe6cd2012-05-23 23:09:501429 // Allow WebContentsDelegates to handle the context menu operation first.
1430 if (delegate_ && delegate_->HandleContextMenu(params))
1431 return;
1432
[email protected]ba16e3a2012-09-07 04:14:521433 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501434}
1435
[email protected]f13b4202012-06-12 23:53:231436void WebContentsImpl::RequestMediaAccessPermission(
1437 const content::MediaStreamRequest* request,
1438 const content::MediaResponseCallback& callback) {
1439 if (delegate_)
1440 delegate_->RequestMediaAccessPermission(this, request, callback);
1441 else
1442 callback.Run(content::MediaStreamDevices());
1443}
1444
[email protected]16383382012-09-05 23:57:261445#if defined(OS_ANDROID)
1446void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1447 if (delegate_)
1448 delegate_->AttachLayer(this, layer);
1449}
1450
1451void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1452 if (delegate_)
1453 delegate_->RemoveLayer(this, layer);
1454}
1455#endif
1456
[email protected]b172aee2012-04-10 17:05:261457void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231458 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331459 if (delegate_)
1460 delegate_->UpdatePreferredSize(this, pref_size);
1461}
1462
[email protected]b172aee2012-04-10 17:05:261463void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341464 if (delegate_)
1465 delegate_->ResizeDueToAutoResize(this, new_size);
1466}
1467
[email protected]b172aee2012-04-10 17:05:261468WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201469 if (!delegate_)
1470 return NULL;
[email protected]00c37fc2011-08-02 00:22:501471
[email protected]e5d549d2011-12-28 01:29:201472 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1473 // Notify observers.
1474 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1475 DidOpenURL(params.url, params.referrer,
1476 params.disposition, params.transition));
1477 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341478}
1479
[email protected]6b618e62012-08-16 12:59:181480bool WebContentsImpl::Send(IPC::Message* message) {
1481 if (!GetRenderViewHost()) {
1482 delete message;
1483 return false;
1484 }
1485
1486 return GetRenderViewHost()->Send(message);
1487}
1488
[email protected]b172aee2012-04-10 17:05:261489bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501490 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251491 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231492 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251493 reload_type);
[email protected]876bc832010-09-07 16:29:541494}
[email protected]96d185d2009-04-24 03:28:541495
[email protected]ba45bfd2012-05-22 21:51:441496void WebContentsImpl::RenderViewForInterstitialPageCreated(
1497 content::RenderViewHost* render_view_host) {
1498 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1499 RenderViewForInterstitialPageCreated(render_view_host));
1500}
1501
[email protected]b172aee2012-04-10 17:05:261502bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231503 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501504 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401505 // The renderer will reject IPC messages with URLs longer than
1506 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511507 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401508 return false;
1509
[email protected]9f76c1e2012-03-05 15:15:581510 RenderViewHostImpl* dest_render_view_host =
1511 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401512 if (!dest_render_view_host)
1513 return false; // Unable to create the desired render view host.
1514
[email protected]80a8fad2011-01-29 04:02:381515 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071516 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581517 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501518 WebUIControllerFactory* factory =
1519 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271520 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501521 bool is_allowed_in_web_ui_renderer =
1522 factory &&
[email protected]24e18252012-04-16 21:26:271523 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1524 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231525 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1526 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271527 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231528 content::GetContentClient()->SetActiveURL(entry.GetURL());
1529 CHECK(0);
1530 }
[email protected]54ec6472010-04-09 19:39:581531
[email protected]96d185d2009-04-24 03:28:541532 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441533 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521534 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441535 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511536 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541537
[email protected]7bb761892012-07-20 09:32:471538 // Notify observers that we will navigate in this RV.
1539 FOR_EACH_OBSERVER(WebContentsObserver,
1540 observers_,
1541 AboutToNavigateRenderView(dest_render_view_host));
1542
[email protected]96d185d2009-04-24 03:28:541543 // Used for page load time metrics.
1544 current_load_start_ = base::TimeTicks::Now();
1545
1546 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241547 std::string embedder_channel_name;
1548 int embedder_container_id;
1549 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1550 &embedder_channel_name,
1551 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341552 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271553 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241554 embedder_channel_name,
1555 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471556 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341557 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541558
[email protected]36fc0392011-12-25 03:59:511559 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541560 // HACK!! This code suppresses javascript: URLs from being added to
1561 // session history, which is what we want to do for javascript: URLs that
1562 // do not generate content. What we really need is a message from the
1563 // renderer telling us that a new page was not created. The same message
1564 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511565 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541566 return false;
1567 }
1568
[email protected]3c9e1872010-11-18 16:17:491569 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251570 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041571 observers_,
[email protected]36fc0392011-12-25 03:59:511572 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541573
[email protected]09b29342011-06-24 19:18:481574 if (delegate_)
1575 delegate_->DidNavigateToPendingEntry(this);
1576
[email protected]d5f942ba2008-09-26 19:30:341577 return true;
1578}
1579
[email protected]b172aee2012-04-10 17:05:261580void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331581 const SiteInstance* site_instance,
1582 int history_length,
1583 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411584 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1585 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191586 if (render_manager_.pending_render_view_host()) {
1587 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141588 return;
[email protected]9e1ad4b2011-08-14 16:49:191589 }
[email protected]9f76c1e2012-03-05 15:15:581590 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191591 if (!rvh) {
1592 NOTREACHED();
1593 return;
1594 }
[email protected]9f76c1e2012-03-05 15:15:581595 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191596 NOTREACHED();
1597 return;
1598 }
[email protected]6b618e62012-08-16 12:59:181599 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1600 history_length,
1601 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141602}
1603
[email protected]b172aee2012-04-10 17:05:261604void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271605 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541606 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1607 return;
1608 }
[email protected]9f76c1e2012-03-05 15:15:581609 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541610}
1611
[email protected]b172aee2012-04-10 17:05:261612bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271613 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541614}
1615
[email protected]b172aee2012-04-10 17:05:261616InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271617 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221618}
1619
[email protected]b172aee2012-04-10 17:05:261620bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161621 // WebKit creates Document object when MIME type is application/xhtml+xml,
1622 // so we also support this MIME type.
1623 return contents_mime_type_ == "text/html" ||
1624 contents_mime_type_ == "text/xml" ||
1625 contents_mime_type_ == "application/xhtml+xml" ||
1626 contents_mime_type_ == "text/plain" ||
1627 contents_mime_type_ == "text/css" ||
1628 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1629}
1630
[email protected]b172aee2012-04-10 17:05:261631void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591632 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161633 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481634 download_stats::RecordDownloadSource(
1635 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461636 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141637 return;
[email protected]c7dd2f62011-07-18 15:57:591638 }
1639
1640 Stop();
1641
1642 // Create the save package and possibly prompt the user for the name to save
1643 // the page as. The user prompt is an asynchronous operation that runs on
1644 // another thread.
1645 save_package_ = new SavePackage(this);
1646 save_package_->GetSaveInfo();
1647}
1648
1649// Used in automated testing to bypass prompting the user for file names.
1650// Instead, the names and paths are hard coded rather than running them through
1651// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261652bool WebContentsImpl::SavePage(const FilePath& main_file,
1653 const FilePath& dir_path,
1654 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591655 // Stop the page from navigating.
1656 Stop();
1657
1658 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271659 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121663 const FilePath& file,
1664 const base::Callback<void(const FilePath&, int64)>& callback) {
1665 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1666}
1667
[email protected]b172aee2012-04-10 17:05:261668bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231669 NavigationEntryImpl* active_entry =
1670 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321671 return (active_entry != NULL &&
1672 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511673 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321674}
1675
[email protected]b172aee2012-04-10 17:05:261676const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271677 return contents_mime_type_;
1678}
1679
[email protected]b172aee2012-04-10 17:05:261680bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271681 return notify_disconnection_;
1682}
1683
[email protected]b172aee2012-04-10 17:05:261684void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311685 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181686 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311690 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181691 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161692}
1693
[email protected]b172aee2012-04-10 17:05:261694content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271695 return &renderer_preferences_;
1696}
1697
[email protected]b172aee2012-04-10 17:05:261698void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271699 new_tab_start_time_ = time;
1700}
1701
[email protected]b172aee2012-04-10 17:05:261702base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271703 return new_tab_start_time_;
1704}
1705
[email protected]e35ccd52012-05-23 16:22:471706void WebContentsImpl::Close() {
1707 Close(GetRenderViewHost());
1708}
1709
[email protected]b172aee2012-04-10 17:05:261710void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151711 if (close_start_time_.is_null())
1712 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011713}
1714
[email protected]b172aee2012-04-10 17:05:261715bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191716#if defined(OS_CHROMEOS)
1717 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1718 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511719 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201720 return false;
1721 return true;
[email protected]46624bf2010-06-09 16:04:191722#else
1723 return true;
1724#endif
1725}
1726
[email protected]b172aee2012-04-10 17:05:261727void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521728 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581729 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511730 if (delegate_)
1731 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341732}
1733
[email protected]e35ccd52012-05-23 16:22:471734void WebContentsImpl::UserGestureDone() {
1735 OnUserGesture();
1736}
1737
[email protected]b172aee2012-04-10 17:05:261738void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271739 closed_by_user_gesture_ = value;
1740}
1741
[email protected]b172aee2012-04-10 17:05:261742bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271743 return closed_by_user_gesture_;
1744}
1745
[email protected]b172aee2012-04-10 17:05:261746double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051747 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561748 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251749 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171750 return 0;
[email protected]b75b8292010-10-01 07:28:251751
1752 double zoom_level;
1753 if (temporary_zoom_settings_) {
1754 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581755 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251756 } else {
[email protected]2ae88d12011-10-14 09:11:191757 GURL url;
[email protected]10f417c52011-12-28 21:04:231758 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191759 // Since zoom map is updated using rewritten URL, use rewritten URL
1760 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511761 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191762 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251763 }
[email protected]d0b8d092010-10-25 04:05:171764 return zoom_level;
1765}
[email protected]b75b8292010-10-01 07:28:251766
[email protected]b172aee2012-04-10 17:05:261767int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1768 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171769 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011770 // Calculate the zoom percent from the factor. Round up to the nearest whole
1771 // number.
[email protected]b75b8292010-10-01 07:28:251772 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011773 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251774 *enable_decrement = percent > minimum_zoom_percent_;
1775 *enable_increment = percent < maximum_zoom_percent_;
1776 return percent;
1777}
1778
[email protected]b172aee2012-04-10 17:05:261779void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501780 if (!delegate_)
1781 return;
1782
[email protected]10f417c52011-12-28 21:04:231783 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501784 if (!active_entry)
1785 return;
1786
[email protected]36fc0392011-12-25 03:59:511787 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121788}
1789
[email protected]b172aee2012-04-10 17:05:261790void WebContentsImpl::ViewFrameSource(const GURL& url,
1791 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271792 if (!delegate_)
1793 return;
1794
1795 delegate_->ViewSourceForFrame(this, url, content_state);
1796}
1797
[email protected]b172aee2012-04-10 17:05:261798int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271799 return minimum_zoom_percent_;
1800}
1801
[email protected]b172aee2012-04-10 17:05:261802int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271803 return maximum_zoom_percent_;
1804}
1805
[email protected]b172aee2012-04-10 17:05:261806gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231807 return preferred_size_;
1808}
1809
[email protected]b172aee2012-04-10 17:05:261810int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271811 return content_restrictions_;
1812}
1813
[email protected]b172aee2012-04-10 17:05:261814WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501815 WebUIControllerFactory* factory =
1816 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1817 if (!factory)
1818 return WebUI::kNoWebUI;
1819 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271820}
1821
[email protected]b172aee2012-04-10 17:05:261822content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271823 // When there is a pending navigation entry, we want to use the pending WebUI
1824 // that goes along with it to control the basic flags. For example, we want to
1825 // show the pending URL in the URL bar, so we want the display_url flag to
1826 // be from the pending entry.
1827 //
1828 // The confusion comes because there are multiple possibilities for the
1829 // initial load in a tab as a side effect of the way the RenderViewHostManager
1830 // works.
1831 //
1832 // - For the very first tab the load looks "normal". The new tab Web UI is
1833 // the pending one, and we want it to apply here.
1834 //
1835 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1836 // get switched to the one previously associated with the new tab pages.
1837 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1838 // have a committed Web UI in this case.
1839 //
1840 // This condition handles all of these cases:
1841 //
1842 // - First load in first tab: no committed nav entry + pending nav entry +
1843 // pending dom ui:
1844 // -> Use pending Web UI if any.
1845 //
1846 // - First load in second tab: no committed nav entry + pending nav entry +
1847 // no pending Web UI:
1848 // -> Use the committed Web UI if any.
1849 //
1850 // - Second navigation in any tab: committed nav entry + pending nav entry:
1851 // -> Use pending Web UI if any.
1852 //
1853 // - Normal state with no load: committed nav entry + no pending nav entry:
1854 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251855 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271856 (controller_.GetLastCommittedEntry() ||
1857 render_manager_.pending_web_ui()))
1858 return render_manager_.pending_web_ui();
1859 return render_manager_.web_ui();
1860}
1861
[email protected]b172aee2012-04-10 17:05:261862bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271863 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581864 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271865}
1866
[email protected]b172aee2012-04-10 17:05:261867bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441868 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501869}
1870
[email protected]b172aee2012-04-10 17:05:261871void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321872 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181873 Send(new ViewMsg_DidChooseColorResponse(
1874 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201875}
1876
[email protected]b172aee2012-04-10 17:05:261877void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181878 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201879 if (delegate_)
1880 delegate_->DidEndColorChooser();
1881 color_chooser_ = NULL;
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471885 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271886 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221887 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231888 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411889 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271890}
1891
[email protected]b172aee2012-04-10 17:05:261892void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271893 if (delegate_)
1894 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211895}
1896
[email protected]3a3b75a2012-06-01 08:38:361897void WebContentsImpl::OnRegisterIntentService(
1898 const webkit_glue::WebIntentServiceData& data,
1899 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431900 if (delegate_)
1901 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301902}
1903
[email protected]b172aee2012-04-10 17:05:261904void WebContentsImpl::OnWebIntentDispatch(
1905 const webkit_glue::WebIntentData& intent,
1906 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431907 if (!delegate_)
1908 return;
1909
[email protected]0d9989d2011-12-21 20:26:001910 WebIntentsDispatcherImpl* intents_dispatcher =
1911 new WebIntentsDispatcherImpl(this, intent, intent_id);
1912 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301913}
1914
[email protected]54047eb52012-05-08 21:45:571915void WebContentsImpl::DidStartProvisionalLoadForFrame(
1916 content::RenderViewHost* render_view_host,
1917 int64 frame_id,
1918 bool is_main_frame,
1919 const GURL& opener_url,
1920 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281921 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181922 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451923 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571924 content::RenderProcessHost* render_process_host =
1925 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541926 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571927 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451928 false,
[email protected]9f76c1e2012-03-05 15:15:581929 &validated_url);
[email protected]ef108e72012-06-20 14:03:541930 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571931 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451932 true,
1933 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181934
[email protected]0d60f0192011-04-14 12:40:101935 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251936 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101937 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571938 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541939
1940 if (is_main_frame) {
1941 // Notify observers about the provisional change in the main frame URL.
1942 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1943 ProvisionalChangeToMainFrameUrl(validated_url,
1944 validated_opener_url,
1945 render_view_host));
1946 }
1947}
1948
1949void WebContentsImpl::DidRedirectProvisionalLoad(
1950 content::RenderViewHost* render_view_host,
1951 int32 page_id,
1952 const GURL& opener_url,
1953 const GURL& source_url,
1954 const GURL& target_url) {
1955 // TODO(creis): Remove this method and have the pre-rendering code listen to
1956 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1957 // instead. See http://crbug.com/78512.
1958 GURL validated_source_url(source_url);
1959 GURL validated_target_url(target_url);
1960 GURL validated_opener_url(opener_url);
1961 content::RenderProcessHost* render_process_host =
1962 render_view_host->GetProcess();
1963 RenderViewHostImpl::FilterURL(
1964 ChildProcessSecurityPolicyImpl::GetInstance(),
1965 render_process_host->GetID(),
1966 false,
1967 &validated_source_url);
1968 RenderViewHostImpl::FilterURL(
1969 ChildProcessSecurityPolicyImpl::GetInstance(),
1970 render_process_host->GetID(),
1971 false,
1972 &validated_target_url);
1973 RenderViewHostImpl::FilterURL(
1974 ChildProcessSecurityPolicyImpl::GetInstance(),
1975 render_process_host->GetID(),
1976 true,
1977 &validated_opener_url);
1978 NavigationEntry* entry;
1979 if (page_id == -1) {
1980 entry = controller_.GetPendingEntry();
1981 } else {
1982 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1983 page_id);
1984 }
1985 if (!entry || entry->GetURL() != validated_source_url)
1986 return;
1987
1988 // Notify observers about the provisional change in the main frame URL.
1989 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1990 ProvisionalChangeToMainFrameUrl(validated_target_url,
1991 validated_opener_url,
1992 render_view_host));
[email protected]724159a2010-12-30 01:11:181993}
1994
[email protected]54047eb52012-05-08 21:45:571995void WebContentsImpl::DidFailProvisionalLoadWithError(
1996 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581997 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1998 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1999 << ", error_code: " << params.error_code
2000 << ", error_description: " << params.error_description
2001 << ", is_main_frame: " << params.is_main_frame
2002 << ", showing_repost_interstitial: " <<
2003 params.showing_repost_interstitial
2004 << ", frame_id: " << params.frame_id;
2005 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:572006 content::RenderProcessHost* render_process_host =
2007 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542008 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572009 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452010 false,
[email protected]9f76c1e2012-03-05 15:15:582011 &validated_url);
[email protected]724159a2010-12-30 01:11:182012
[email protected]d7b175e2011-10-11 15:31:582013 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182014 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2015 // This means that the interstitial won't be torn down properly, which is
2016 // bad. But if we have an interstitial, go back to another tab type, and
2017 // then load the same interstitial again, we could end up getting the first
2018 // interstitial's "failed" message (as a result of the cancel) when we're on
2019 // the second one.
2020 //
2021 // We can't tell this apart, so we think we're tearing down the current page
2022 // which will cause a crash later one. There is also some code in
2023 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2024 // out because of this problem.
2025 //
2026 // http://code.google.com/p/chromium/issues/detail?id=2855
2027 // Because this will not tear down the interstitial properly, if "back" is
2028 // back to another tab type, the interstitial will still be somewhat alive
2029 // in the previous tab type. If you navigate somewhere that activates the
2030 // tab with the interstitial again, you'll see a flash before the new load
2031 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272032 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182033 LOG(WARNING) << "Discarding message during interstitial.";
2034 return;
2035 }
2036
[email protected]a16690732012-07-13 19:22:172037 // Do not clear the pending entry if one exists, so that the user's typed
2038 // URL is not lost when a navigation fails or is aborted. We'll allow
2039 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182040
[email protected]54047eb52012-05-08 21:45:572041 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182042 }
2043
[email protected]d8c660432011-12-22 20:51:252044 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582045 observers_,
2046 DidFailProvisionalLoad(params.frame_id,
2047 params.is_main_frame,
2048 validated_url,
2049 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462050 params.error_description,
2051 render_view_host));
[email protected]724159a2010-12-30 01:11:182052}
2053
[email protected]b172aee2012-04-10 17:05:262054void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182055 const GURL& url,
[email protected]70435962011-08-02 20:13:282056 const std::string& security_info,
2057 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182058 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282059 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192060 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182061 cache.Increment();
2062
2063 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082064 int cert_id = 0;
2065 net::CertStatus cert_status = 0;
2066 int security_bits = -1;
2067 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512068 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2069 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002070 content::LoadFromMemoryCacheDetails details(
2071 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2072 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182073
[email protected]ad50def52011-10-19 23:17:072074 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272075 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502076 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002077 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182078}
2079
[email protected]b172aee2012-04-10 17:05:262080void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382081 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182082 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192083 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182084}
2085
[email protected]b172aee2012-04-10 17:05:262086void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022087 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232088 LOG(INFO) << security_origin << " ran insecure content from "
2089 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382090 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412091 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2092 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182093 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412094 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192095 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182096}
2097
[email protected]b172aee2012-04-10 17:05:262098void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182099 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252100 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472101 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312105 int64 frame_id,
2106 const GURL& validated_url,
2107 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252108 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472109 DidFinishLoad(frame_id, validated_url, is_main_frame,
2110 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312111}
2112
[email protected]b172aee2012-04-10 17:05:262113void WebContentsImpl::OnDidFailLoadWithError(
2114 int64 frame_id,
2115 const GURL& validated_url,
2116 bool is_main_frame,
2117 int error_code,
2118 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252119 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312120 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472121 error_code, error_description,
2122 message_source_));
[email protected]724159a2010-12-30 01:11:182123}
2124
[email protected]b172aee2012-04-10 17:05:262125void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272126 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432127 if (delegate_)
2128 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172129}
2130
[email protected]b172aee2012-04-10 17:05:262131void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262132 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232133 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252134 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262135 if (!entry)
2136 return;
2137 // Note that we don't call NavigationController::GotToOffset() as we don't
2138 // want to create a pending navigation entry (it might end up lingering
2139 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252140 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582141 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512142 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582143 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472144 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572145
2146 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2147 // it in now that we know. This allows us to find the entry when it commits.
2148 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232149 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332150 entry->set_site_instance(
2151 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572152 }
[email protected]216813952011-05-19 22:21:262153 }
2154}
2155
[email protected]b172aee2012-04-10 17:05:262156void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2157 int maximum_percent,
2158 bool remember) {
[email protected]216813952011-05-19 22:21:262159 minimum_zoom_percent_ = minimum_percent;
2160 maximum_zoom_percent_ = maximum_percent;
2161 temporary_zoom_settings_ = !remember;
2162}
2163
[email protected]20b433a2012-05-15 21:23:462164void WebContentsImpl::OnSaveURL(const GURL& url,
2165 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482166 download_stats::RecordDownloadSource(
2167 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262168 // Check if the URL to save matches the URL of the main frame. Since this
2169 // message originates from Pepper plugins, it may not be the case if the
2170 // plugin is an embedded element.
2171 GURL main_frame_url = GetURL();
2172 if (!main_frame_url.is_valid())
2173 return;
2174 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462175 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272176}
2177
[email protected]b172aee2012-04-10 17:05:262178void WebContentsImpl::OnEnumerateDirectory(int request_id,
2179 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432180 if (!delegate_)
2181 return;
2182
[email protected]b9535422012-02-09 01:47:592183 ChildProcessSecurityPolicyImpl* policy =
2184 ChildProcessSecurityPolicyImpl::GetInstance();
2185 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2186 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212187}
2188
[email protected]b172aee2012-04-10 17:05:262189void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432190 if (delegate_)
2191 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202192}
2193
[email protected]b172aee2012-04-10 17:05:262194void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2195 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362196 const string16& title,
2197 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432198 if (!delegate_)
2199 return;
2200
[email protected]b9535422012-02-09 01:47:592201 ChildProcessSecurityPolicyImpl* policy =
2202 ChildProcessSecurityPolicyImpl::GetInstance();
2203 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2204 return;
[email protected]3a3b75a2012-06-01 08:38:362205 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202206}
2207
[email protected]b172aee2012-04-10 17:05:262208void WebContentsImpl::OnFindReply(int request_id,
2209 int number_of_matches,
2210 const gfx::Rect& selection_rect,
2211 int active_match_ordinal,
2212 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432213 if (delegate_) {
2214 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2215 active_match_ordinal, final_update);
2216 }
[email protected]b888919c2011-09-02 00:32:162217}
2218
[email protected]59363fc92012-09-05 03:46:312219#if defined(OS_ANDROID)
2220void WebContentsImpl::OnFindMatchRectsReply(
2221 int version,
2222 const std::vector<gfx::RectF>& rects,
2223 const gfx::RectF& active_rect) {
2224 if (delegate_)
2225 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2226}
2227#endif
2228
[email protected]b172aee2012-04-10 17:05:262229void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442230 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2231 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452232}
2233
[email protected]b172aee2012-04-10 17:05:262234void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2235 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102236 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252237 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102238 AppCacheAccessed(manifest_url, blocked_by_policy));
2239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322242 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432243 color_chooser_ = delegate_ ?
2244 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202245}
2246
[email protected]b172aee2012-04-10 17:05:262247void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202248 if (color_chooser_ &&
2249 color_chooser_id == color_chooser_->identifier())
2250 color_chooser_->End();
2251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322254 SkColor color) {
[email protected]da8543762012-03-20 08:52:202255 if (color_chooser_ &&
2256 color_chooser_id == color_chooser_->identifier())
2257 color_chooser_->SetSelectedColor(color);
2258}
2259
[email protected]9f2a9d72012-04-16 16:02:222260void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2261 const FilePath& path,
2262 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442263 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2264 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292265}
2266
[email protected]d0759f492012-04-19 22:50:502267// This exists for render views that don't have a WebUI, but do have WebUI
2268// bindings enabled.
2269void WebContentsImpl::OnWebUISend(const GURL& source_url,
2270 const std::string& name,
2271 const base::ListValue& args) {
2272 if (delegate_)
2273 delegate_->WebUISend(this, source_url, name, args);
2274}
2275
[email protected]d8415ad92012-08-23 14:40:502276void WebContentsImpl::OnRequestPpapiBrokerPermission(
2277 int request_id,
2278 const GURL& url,
2279 const FilePath& plugin_path) {
2280 base::Callback<void(bool)> callback =
2281 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2282 base::Unretained(this), request_id);
2283 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2284 WebContentsObserver* observer;
2285 while ((observer = it.GetNext()) != NULL) {
2286 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2287 callback))
2288 return;
2289 }
2290
2291 // Fall back to allowing the request if no observer handled it.
2292 OnPpapiBrokerPermissionResult(request_id, true);
2293}
2294
2295void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2296 bool result) {
2297 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2298 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2299 request_id,
2300 result));
2301}
2302
[email protected]96d185d2009-04-24 03:28:542303// Notifies the RenderWidgetHost instance about the fact that the page is
2304// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::SetIsLoading(bool is_loading,
2306 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542307 if (is_loading == is_loading_)
2308 return;
2309
2310 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212311 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542312 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562313 upload_size_ = 0;
2314 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542315 }
2316
2317 render_manager_.SetIsLoading(is_loading);
2318
2319 is_loading_ = is_loading;
2320 waiting_for_response_ = is_loading;
2321
[email protected]6ebdc9b2010-09-27 16:55:572322 if (delegate_)
2323 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462324 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542325
[email protected]432115822011-07-10 15:52:272326 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2327 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072328 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542329 if (details)
[email protected]6c2381d2011-10-19 02:52:532330 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072331 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502332 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542333 det);
2334}
2335
[email protected]b172aee2012-04-10 17:05:262336void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132337 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322338 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562339 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382340 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442341 // that opened the window, as long as both renderers have the same
2342 // privileges.
[email protected]1fd1a502011-03-30 16:55:562343 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562344 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582345 // web_ui might be NULL if the URL refers to a non-existent extension.
2346 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402347 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522348 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442349 }
2350 }
[email protected]1fd1a502011-03-30 16:55:562351 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442352 }
2353
[email protected]4e697b042011-07-08 06:44:562354 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322355 // Clear the status bubble. This is a workaround for a bug where WebKit
2356 // doesn't let us know that the cursor left an element during a
2357 // transition (this is also why the mouse cursor remains as a hand after
2358 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2359 // clear the bubble when a user navigates to a named anchor in the same
2360 // page.
[email protected]36fc0392011-12-25 03:59:512361 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322362 }
2363
[email protected]a6e82fc2010-02-24 22:28:142364 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472365 // Once the main frame is navigated, we're no longer considered to have
2366 // displayed insecure content.
2367 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172368 }
[email protected]ce5c4502009-05-06 16:46:112369
[email protected]3c9e1872010-11-18 16:17:492370 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252371 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042372 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322373}
2374
[email protected]b172aee2012-04-10 17:05:262375void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322376 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132377 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322378 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062379 // If we navigate off the page, reset JavaScript state. This does nothing
2380 // to prevent a malicious script from spamming messages, since the script
2381 // could just reload the page to stop blocking.
2382 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552383 dialog_creator_->ResetJavaScriptState(this);
2384 dialog_creator_ = NULL;
2385 }
[email protected]420ae012009-04-24 05:16:322386
[email protected]3c9e1872010-11-18 16:17:492387 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252388 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042389 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322390}
2391
[email protected]b172aee2012-04-10 17:05:262392void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462393 // If we are creating a RVH for a restored controller, then we need to make
2394 // sure the RenderView starts with a next_page_id_ larger than the number
2395 // of restored entries. This must be called before the RenderView starts
2396 // navigating (to avoid a race between the browser updating max_page_id and
2397 // the renderer updating next_page_id_). Because of this, we only call this
2398 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562399 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582400 if (max_restored_page_id >
2401 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2402 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2403 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322404}
2405
[email protected]b172aee2012-04-10 17:05:262406bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2407 const string16& title) {
[email protected]420ae012009-04-24 05:16:322408 // For file URLs without a title, use the pathname instead. In the case of a
2409 // synthesized title, we don't want the update to count toward the "one set
2410 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512411 string16 final_title;
[email protected]420ae012009-04-24 05:16:322412 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512413 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2414 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322415 explicit_set = false; // Don't count synthetic titles toward the set limit.
2416 } else {
[email protected]acafd272011-07-26 17:35:572417 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322418 explicit_set = true;
2419 }
2420
[email protected]987fc3a2011-05-26 14:18:092421 // If a page is created via window.open and never navigated,
2422 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552423 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092424 if (entry) {
[email protected]36fc0392011-12-25 03:59:512425 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092426 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322427
[email protected]36fc0392011-12-25 03:59:512428 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092429 } else {
2430 if (page_title_when_no_navigation_entry_ == final_title)
2431 return false; // Nothing changed, don't bother.
2432
2433 page_title_when_no_navigation_entry_ = final_title;
2434 }
[email protected]420ae012009-04-24 05:16:322435
[email protected]420ae012009-04-24 05:16:322436 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232437 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322438
[email protected]2bb171882012-03-07 02:09:462439 std::pair<content::NavigationEntry*, bool> details =
2440 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142441
[email protected]ad50def52011-10-19 23:17:072442 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442443 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2444 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462445 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042446
[email protected]420ae012009-04-24 05:16:322447 return true;
2448}
2449
[email protected]b172aee2012-04-10 17:05:262450void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322451 // After sending out a swap notification, we need to send a disconnect
2452 // notification so that clients that pick up a pointer to |this| can NULL the
2453 // pointer. See Bug 1230284.
2454 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072455 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202456 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2457 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072458 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322459}
2460
[email protected]b172aee2012-04-10 17:05:262461void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322462 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072463 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122464 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2465 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072466 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322467}
2468
[email protected]b172aee2012-04-10 17:05:262469void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322470 if (!notify_disconnection_)
2471 return;
2472
2473 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072474 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322475 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2476 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072477 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322478}
2479
[email protected]5a3bdf52012-05-24 15:12:572480RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2481 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322482}
2483
[email protected]8d3347f2009-07-09 22:00:212484RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262485WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212486 return &render_manager_;
2487}
2488
[email protected]b172aee2012-04-10 17:05:262489content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372490 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462491 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512492}
2493
[email protected]b172aee2012-04-10 17:05:262494WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172495 return this;
2496}
2497
[email protected]b172aee2012-04-10 17:05:262498gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172499 if (delegate_)
2500 return delegate_->GetRootWindowResizerRect();
2501 return gfx::Rect();
2502}
2503
[email protected]b172aee2012-04-10 17:05:262504void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442505 // Don't send notifications if we are just creating a swapped-out RVH for
2506 // the opener chain. These won't be used for view-source or WebUI, so it's
2507 // ok to return early.
2508 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2509 return;
2510
[email protected]ad50def52011-10-19 23:17:072511 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302512 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322513 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532514 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232515 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322516 if (!entry)
2517 return;
2518
2519 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352520 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562521 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582522 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322523
2524 if (entry->IsViewSourceMode()) {
2525 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182526 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582527 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322528 }
[email protected]0666aef2009-05-13 19:48:082529
[email protected]d487beefe2011-12-21 05:41:212530 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262531
2532 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252533 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322534}
2535
[email protected]b172aee2012-04-10 17:05:262536void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522537 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322538 // Don't notify the world, since this came from a renderer in the
2539 // background.
2540 return;
2541 }
2542
2543 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312544 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232545 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302546
2547 // Restore the focus to the tab (otherwise the focus will be on the top
2548 // window).
[email protected]484ae5912010-09-29 19:16:142549 if (was_crashed && !FocusLocationBarByDefault() &&
2550 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302551 Focus();
[email protected]484ae5912010-09-29 19:16:142552 }
[email protected]32ded2212011-11-10 18:51:432553
[email protected]d8c660432011-12-22 20:51:252554 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322555}
2556
[email protected]b172aee2012-04-10 17:05:262557void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2558 base::TerminationStatus status,
2559 int error_code) {
[email protected]151a63d2011-12-20 22:32:522560 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322561 // The pending page's RenderViewHost is gone.
2562 return;
2563 }
2564
2565 SetIsLoading(false, NULL);
2566 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232567 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312568 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322569
[email protected]d8c660432011-12-22 20:51:252570 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272571 observers_,
[email protected]be1f56ab2011-12-22 06:55:312572 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482576 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252577 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062578}
2579
[email protected]b172aee2012-04-10 17:05:262580void WebContentsImpl::DidNavigate(
2581 RenderViewHost* rvh,
2582 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582583 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322584 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372585
[email protected]434f69f2012-02-06 21:56:522586 // Update the site of the SiteInstance if it doesn't have one yet, unless
2587 // this is for about:blank. In that case, the SiteInstance can still be
2588 // considered unused until a navigation to a real page.
2589 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2590 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332591 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522592 }
[email protected]420ae012009-04-24 05:16:322593
2594 // Need to update MIME type here because it's referred to in
2595 // UpdateNavigationCommands() called by RendererDidNavigate() to
2596 // determine whether or not to enable the encoding menu.
2597 // It's updated only for the main frame. For a subframe,
2598 // RenderView::UpdateURL does not set params.contents_mime_type.
2599 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2600 // TODO(jungshik): Add a test for the encoding menu to avoid
2601 // regressing it again.
[email protected]2905f742011-10-13 03:51:582602 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322603 contents_mime_type_ = params.contents_mime_type;
2604
[email protected]8286f51a2011-05-31 17:39:132605 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002606 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392607
[email protected]a9c0bfe2010-09-17 08:35:222608 // Send notification about committed provisional loads. This notification is
2609 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2610 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082611 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072612 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2613 // that is not recorded in the navigation history. For the purpose of
2614 // tracking navigation events, we treat this event as a sub frame navigation
2615 // event.
2616 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582617 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222618 // Whether or not a page transition was triggered by going backward or
2619 // forward in the history is only stored in the navigation controller's
2620 // entry list.
2621 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512622 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582623 content::PAGE_TRANSITION_FORWARD_BACK)) {
2624 transition_type = content::PageTransitionFromInt(
2625 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222626 }
[email protected]0d60f0192011-04-14 12:40:102627 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252628 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102629 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462630 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222631 }
2632
[email protected]76543b92009-08-31 17:27:452633 if (!did_navigate)
2634 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322635
2636 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2637 // for the appropriate notification (best) or you can add it to
2638 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2639 // necessary, please).
2640
2641 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002642 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322643 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512644 if (delegate_)
2645 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002646 }
[email protected]420ae012009-04-24 05:16:322647 DidNavigateAnyFramePostCommit(rvh, details, params);
2648}
2649
[email protected]b172aee2012-04-10 17:05:262650void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2651 int32 page_id,
2652 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152653 // Ensure that this state update comes from either the active RVH or one of
2654 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522655 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322656
2657 // We must be prepared to handle state updates for any page, these occur
2658 // when the user is scrolling and entering form data, as well as when we're
2659 // leaving a page, in which case our state may have already been moved to
2660 // the next page. The navigation controller will look up the appropriate
2661 // NavigationEntry and update it when it is notified via the delegate.
2662
2663 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582664 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322665 if (entry_index < 0)
2666 return;
[email protected]10f417c52011-12-28 21:04:232667 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322668
[email protected]36fc0392011-12-25 03:59:512669 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322670 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512671 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322672 controller_.NotifyEntryChanged(entry, entry_index);
2673}
2674
[email protected]b172aee2012-04-10 17:05:262675void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2676 int32 page_id,
2677 const string16& title,
2678 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322679 // If we have a title, that's a pretty good indication that we've started
2680 // getting useful data.
2681 SetNotWaitingForResponse();
2682
[email protected]73eb2602012-02-09 19:50:552683 // Try to find the navigation entry, which might not be the current one.
2684 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232685 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582686 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092687
[email protected]73eb2602012-02-09 19:50:552688 // We can handle title updates when we don't have an entry in
2689 // UpdateTitleForEntry, but only if the update is from the current RVH.
2690 if (!entry && rvh != GetRenderViewHost())
2691 return;
2692
[email protected]a49e10b2011-08-01 23:57:462693 // TODO(evan): make use of title_direction.
2694 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092695 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322696 return;
2697
2698 // Broadcast notifications when the UI should be updated.
2699 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462700 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322701}
2702
[email protected]b172aee2012-04-10 17:05:262703void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2704 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312705 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322706}
2707
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512709 if (delegate_)
2710 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322711}
2712
[email protected]b172aee2012-04-10 17:05:262713void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292714 // The UI may be in an event-tracking loop, such as between the
2715 // mouse-down and mouse-up in text selection or a button click.
2716 // Defer the close until after tracking is complete, so that we
2717 // don't free objects out from under the UI.
2718 // TODO(shess): This could probably be integrated with the
2719 // IsDoingDrag() test below. Punting for now because I need more
2720 // research to understand how this impacts platforms other than Mac.
2721 // TODO(shess): This could get more fine-grained. For instance,
2722 // closing a tab in another window while selecting text in the
2723 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212724 if (GetView()->IsEventTracking()) {
2725 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292726 return;
2727 }
2728
[email protected]24a4d1062009-07-10 23:10:422729 // If we close the tab while we're in the middle of a drag, we'll crash.
2730 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212731 if (GetView()->IsDoingDrag()) {
2732 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422733 return;
2734 }
2735
[email protected]420ae012009-04-24 05:16:322736 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522737 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512738 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322739}
2740
[email protected]b172aee2012-04-10 17:05:262741void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522742 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512743 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572744}
2745
[email protected]b172aee2012-04-10 17:05:262746void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512747 if (delegate_ && delegate_->IsPopupOrPanel(this))
2748 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322749}
2750
[email protected]89793072012-07-23 22:25:292751void WebContentsImpl::DidStartLoading(
2752 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322753 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492754
[email protected]82114f52012-03-20 22:53:412755 if (delegate_ && content_restrictions_)
2756 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492757
2758 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292759 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2760 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322761}
2762
[email protected]89793072012-07-23 22:25:292763void WebContentsImpl::DidStopLoading(
2764 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322765 scoped_ptr<LoadNotificationDetails> details;
2766
[email protected]10f417c52011-12-28 21:04:232767 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322768 // An entry may not exist for a stop when loading an initial blank page or
2769 // if an iframe injected by script into a blank page finishes loading.
2770 if (entry) {
[email protected]420ae012009-04-24 05:16:322771 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2772
2773 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512774 entry->GetVirtualURL(),
2775 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322776 elapsed,
2777 &controller_,
2778 controller_.GetCurrentEntryIndex()));
2779 }
2780
[email protected]420ae012009-04-24 05:16:322781 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492782
2783 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292784 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2785 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322786}
2787
[email protected]b172aee2012-04-10 17:05:262788void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162789 controller_.DiscardNonCommittedEntries();
2790
2791 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462792 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162793}
2794
[email protected]b172aee2012-04-10 17:05:262795void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512796 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132797 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402798}
2799
[email protected]0720b532012-08-28 19:23:372800void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2801 render_manager_.DidUpdateFrameTree(rvh);
2802}
2803
[email protected]87717d0e2012-04-26 02:58:432804void WebContentsImpl::DocumentAvailableInMainFrame(
2805 RenderViewHost* render_view_host) {
2806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2807 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102808}
2809
[email protected]b172aee2012-04-10 17:05:262810void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082811 RenderViewHost* render_view_host,
2812 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072813 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272814 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322815 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532816 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082817}
2818
[email protected]196159d2012-05-04 17:26:542819void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2820 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262821 const content::Referrer& referrer,
2822 WindowOpenDisposition disposition,
2823 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542824 // If this came from a swapped out RenderViewHost, we only allow the request
2825 // if we are still in the same BrowsingInstance.
2826 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2827 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2828 return;
2829 }
2830
[email protected]4ad5d77d2011-12-03 02:00:482831 // Delegate to RequestTransferURL because this is just the generic
2832 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582833 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482834 GlobalRequestID());
2835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::RequestTransferURL(
2838 const GURL& url,
2839 const content::Referrer& referrer,
2840 WindowOpenDisposition disposition,
2841 int64 source_frame_id,
2842 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202843 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582844 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582845 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352846 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322847 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2848 // generated suggestions).
2849 //
[email protected]e0112912011-02-02 22:54:352850 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162851 // want web sites to see a referrer of "chrome://blah" (and some
2852 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322853 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432854 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222855 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482856 false /* is_renderer_initiated */);
2857 params.transferred_global_request_id = old_request_id;
2858 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222859 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322860 } else {
[email protected]6bf6a6b52012-02-03 15:41:432861 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482862 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2863 params.transferred_global_request_id = old_request_id;
2864 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582865 }
2866 if (new_contents) {
2867 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252868 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582869 DidOpenRequestedURL(new_contents,
2870 url,
2871 referrer,
2872 disposition,
2873 transition_type,
2874 source_frame_id));
[email protected]420ae012009-04-24 05:16:322875 }
2876}
2877
[email protected]e1c3a552012-05-04 20:51:322878void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2879 // Tell the active RenderViewHost to run unload handlers and close, as long
2880 // as the request came from a RenderViewHost in the same BrowsingInstance.
2881 // In most cases, we receive this from a swapped out RenderViewHost.
2882 // It is possible to receive it from one that has just been swapped in,
2883 // in which case we might as well deliver the message anyway.
2884 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2885 GetRenderViewHost()->ClosePage();
2886}
2887
[email protected]f546640b2012-05-15 00:03:492888void WebContentsImpl::RouteMessageEvent(
2889 RenderViewHost* rvh,
2890 const ViewMsg_PostMessage_Params& params) {
2891 // Only deliver the message to the active RenderViewHost if the request
2892 // came from a RenderViewHost in the same BrowsingInstance.
2893 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2894 return;
2895
2896 ViewMsg_PostMessage_Params new_params(params);
2897
[email protected]0720b532012-08-28 19:23:372898 // If the renderer has changed while the post message is being routed,
2899 // drop the message, as it will not be delivered to the right target.
2900 if (GetRenderViewHost()->GetProcess()->GetID() != params.target_process_id)
2901 return;
2902 DCHECK(params.target_frame_id != 0);
2903
[email protected]f546640b2012-05-15 00:03:492904 // If there is a source_routing_id, translate it to the routing ID for
2905 // the equivalent swapped out RVH in the target process. If we need
2906 // to create a swapped out RVH for the source tab, we create its opener
2907 // chain as well, since those will also be accessible to the target page.
2908 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2909 // Try to look up the WebContents for the source page.
2910 WebContentsImpl* source_contents = NULL;
2911 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2912 rvh->GetProcess()->GetID(), params.source_routing_id);
2913 if (source_rvh) {
2914 source_contents = static_cast<WebContentsImpl*>(
2915 source_rvh->GetDelegate()->GetAsWebContents());
2916 }
2917
2918 if (source_contents) {
2919 new_params.source_routing_id =
2920 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2921 } else {
2922 // We couldn't find it, so don't pass a source frame.
2923 new_params.source_routing_id = MSG_ROUTING_NONE;
2924 }
2925 }
2926
2927 // In most cases, we receive this from a swapped out RenderViewHost.
2928 // It is possible to receive it from one that has just been swapped in,
2929 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182930 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492931}
2932
[email protected]b172aee2012-04-10 17:05:262933void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342934 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412935 const string16& message,
2936 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322937 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142938 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322939 IPC::Message* reply_msg,
2940 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072941 // Suppress JavaScript dialogs when requested. Also suppress messages when
2942 // showing an interstitial as it's shown over the previous page and we don't
2943 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502944 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582945 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272946 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072947 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522948 delegate_->ShouldSuppressDialogs() ||
2949 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322950
2951 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432952 std::string accept_lang = content::GetContentClient()->browser()->
2953 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552954 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522955 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432956 this,
2957 frame_url.GetOrigin(),
2958 accept_lang,
2959 javascript_message_type,
2960 message,
[email protected]51da7e32012-01-30 19:24:522961 default_prompt,
[email protected]b172aee2012-04-10 17:05:262962 base::Bind(&WebContentsImpl::OnDialogClosed,
2963 base::Unretained(this),
2964 rvh,
2965 reply_msg),
[email protected]51da7e32012-01-30 19:24:522966 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322967 }
[email protected]3ab9cb82011-06-03 18:02:072968
2969 if (suppress_this_message) {
2970 // If we are suppressing messages, just reply as if the user immediately
2971 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342972 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072973 }
2974
2975 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322976}
2977
[email protected]b172aee2012-04-10 17:05:262978void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2979 const string16& message,
2980 bool is_reload,
2981 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582982 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512983 if (delegate_)
2984 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072985
2986 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582987 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072988 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522989 delegate_->ShouldSuppressDialogs() ||
2990 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152991 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342992 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582993 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502994 return;
2995 }
[email protected]3ab9cb82011-06-03 18:02:072996
[email protected]7ab1e7d62009-10-14 23:32:012997 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552998 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522999 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323000 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263001 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523002 reply_msg));
[email protected]420ae012009-04-24 05:16:323003}
3004
[email protected]a796f202012-05-30 14:14:253005bool WebContentsImpl::AddMessageToConsole(int32 level,
3006 const string16& message,
3007 int32 line_no,
3008 const string16& source_id) {
3009 if (!delegate_)
3010 return false;
3011 return delegate_->AddMessageToConsole(this, level, message, line_no,
3012 source_id);
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333016 // We want to base the page config off of the real URL, rather than the
3017 // display URL.
3018 GURL url = controller_.GetActiveEntry()
3019 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3020 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323021}
3022
[email protected]b172aee2012-04-10 17:05:263023void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273024 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253025 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223026
[email protected]ea114722012-03-12 01:11:253027 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173028 if (rdh) // NULL in unittests.
3029 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253030}
3031
[email protected]b172aee2012-04-10 17:05:263032void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443033 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253034 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443035}
3036
[email protected]b172aee2012-04-10 17:05:263037void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3038 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153039 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523040 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153041 return;
3042
[email protected]9f76c1e2012-03-05 15:15:583043 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3044
[email protected]e5fc1632011-08-08 07:51:533045 // Ignore renderer unresponsive event if debugger is attached to the tab
3046 // since the event may be a result of the renderer sitting on a breakpoint.
3047 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443048 DevToolsAgentHost* agent =
3049 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3050 if (agent &&
3051 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533052 return;
3053
[email protected]420ae012009-04-24 05:16:323054 if (is_during_unload) {
3055 // Hang occurred while firing the beforeunload/unload handler.
3056 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583057 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323058
3059 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3060 return;
3061
3062 // If the tab hangs in the beforeunload/unload handler there's really
3063 // nothing we can do to recover. Pretend the unload listeners have
3064 // all fired and close the tab. If the hang is in the beforeunload handler
3065 // then the user will not have the option of cancelling the close.
3066 Close(rvh);
3067 return;
3068 }
3069
[email protected]9f76c1e2012-03-05 15:15:583070 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473071 return;
3072
[email protected]6934a702011-12-20 00:04:513073 if (delegate_)
3074 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323075}
3076
[email protected]b172aee2012-04-10 17:05:263077void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513078 if (delegate_)
3079 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323080}
3081
[email protected]b172aee2012-04-10 17:05:263082void WebContentsImpl::LoadStateChanged(
3083 const GURL& url,
3084 const net::LoadStateWithParam& load_state,
3085 uint64 upload_position,
3086 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323087 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563088 upload_position_ = upload_position;
3089 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503090 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203091 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303092 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213093 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323094 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463095 if (IsLoading()) {
3096 NotifyNavigationStateChanged(
3097 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3098 }
[email protected]420ae012009-04-24 05:16:323099}
3100
[email protected]b172aee2012-04-10 17:05:263101void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513102 if (delegate_)
3103 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253104}
3105
[email protected]b172aee2012-04-10 17:05:263106void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323107 bool proceed,
3108 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513109 if (delegate_)
3110 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543114 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233115 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3116 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543117}
3118
[email protected]b172aee2012-04-10 17:05:263119void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103120 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263121 gfx::Size size = view_->GetContainerSize();
3122 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3123 // here during container initialization and normal window size will be set
3124 // later. In case of tab duplication this resizing to 0x0 prevents setting
3125 // normal size later so just ignore it.
3126 if (!size.IsEmpty())
3127 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323128}
3129
[email protected]b172aee2012-04-10 17:05:263130void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543131 NotifySwapped();
3132}
3133
[email protected]14392a52012-05-02 20:28:443134int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3135 SiteInstance* instance) {
3136 if (!opener_)
3137 return MSG_ROUTING_NONE;
3138
3139 // Recursively create RenderViews for anything else in the opener chain.
3140 return opener_->CreateOpenerRenderViews(instance);
3141}
3142
3143int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3144 int opener_route_id = MSG_ROUTING_NONE;
3145
3146 // If this tab has an opener, ensure it has a RenderView in the given
3147 // SiteInstance as well.
3148 if (opener_)
3149 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3150
[email protected]0720b532012-08-28 19:23:373151 // If any of the renderers for this WebContents has the same SiteInstance,
3152 // use it.
3153 if (render_manager_.current_host()->GetSiteInstance() == instance)
3154 return render_manager_.current_host()->GetRoutingID();
3155
3156 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3157 instance);
3158 if (rvh)
3159 return rvh->GetRoutingID();
3160
[email protected]14392a52012-05-02 20:28:443161 // Create a swapped out RenderView in the given SiteInstance if none exists,
3162 // setting its opener to the given route_id. Return the new view's route_id.
3163 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3164}
3165
[email protected]b172aee2012-04-10 17:05:263166NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193167 return GetController();
[email protected]3a3d47472010-07-15 21:03:543168}
3169
[email protected]b172aee2012-04-10 17:05:263170WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563171 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323172}
3173
[email protected]10f417c52011-12-28 21:04:233174NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263175 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323176 return controller_.GetLastCommittedEntry();
3177}
3178
[email protected]b172aee2012-04-10 17:05:263179bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443180 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443181 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323182 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523183
[email protected]420ae012009-04-24 05:16:323184 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443185 if (rwh_view)
3186 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323187
[email protected]74ce1ad2011-12-16 21:51:463188 // Make sure we use the correct starting page_id in the new RenderView.
3189 UpdateMaxPageIDIfNecessary(render_view_host);
3190 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583191 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463192
[email protected]7900bfdb2012-05-24 19:31:243193 std::string embedder_channel_name;
3194 int embedder_container_id;
3195 GetBrowserPluginEmbedderInfo(render_view_host,
3196 &embedder_channel_name,
3197 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583198 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493199 render_view_host)->CreateRenderView(string16(),
3200 opener_route_id,
3201 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243202 embedder_channel_name,
3203 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523204 return false;
[email protected]14392a52012-05-02 20:28:443205 }
[email protected]a4127722011-04-27 23:13:523206
[email protected]e60c0232011-11-11 19:56:353207#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503208 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3209 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443210 if (rwh_view) {
3211 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3212 render_widget_host->WasResized();
3213 }
[email protected]f8233cc2011-05-31 20:24:503214#endif
3215
[email protected]420ae012009-04-24 05:16:323216 return true;
3217}
3218
[email protected]b172aee2012-04-10 17:05:263219void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3220 IPC::Message* reply_msg,
3221 bool success,
3222 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543223 if (is_showing_before_unload_dialog_ && !success) {
3224 // If a beforeunload dialog is canceled, we need to stop the throbber from
3225 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293226 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353227 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543228
[email protected]3bbacc5b2012-04-17 17:46:153229 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543230 }
3231 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583232 static_cast<RenderViewHostImpl*>(
3233 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543234}
3235
[email protected]b172aee2012-04-10 17:05:263236void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123237 encoding_ = content::GetContentClient()->browser()->
3238 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103239}
[email protected]f45d2a72010-03-08 23:28:353240
[email protected]b172aee2012-04-10 17:05:263241void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463242 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263243 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573244 DownloadManager* dlm =
3245 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143246 if (!dlm)
3247 return;
3248 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263249 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143250 const NavigationEntry* entry = controller_.GetActiveEntry();
3251 if (entry)
3252 post_id = entry->GetPostID();
3253 }
[email protected]29a5ffc82012-03-13 19:35:583254 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143255 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143256 scoped_ptr<DownloadUrlParameters> params(
3257 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493258 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143259 params->set_post_id(post_id);
3260 params->set_prefer_cache(true);
3261 if (post_id >= 0)
3262 params->set_method("POST");
3263 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143264}
3265
[email protected]b172aee2012-04-10 17:05:263266void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213267 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443268 // Can be NULL during tests.
3269 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213270 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363271}
[email protected]9f76c1e2012-03-05 15:15:583272
[email protected]b172aee2012-04-10 17:05:263273RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583274 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3275}
[email protected]7900bfdb2012-05-24 19:31:243276
3277void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3278 content::RenderViewHost* render_view_host,
3279 std::string* embedder_channel_name,
3280 int* embedder_container_id) {
3281 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283282 old_browser_plugin_host()->embedder_render_process_host();
3283 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243284 int embedder_process_id =
3285 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3286 if (embedder_process_id != -1) {
3287 *embedder_channel_name =
3288 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3289 embedder_process_id);
3290 }
3291}