blob: 79ea7ab8605ef7f9dd485124e03e18e465cc277b [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]14cf0f12012-06-18 17:15:5718#include "content/browser/browser_plugin/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]1ea3c792012-04-17 01:25:0421#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4622#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1223#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1624#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3225#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5426#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0527#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0028#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5031#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2532#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5740#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2043#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1746#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1447#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4648#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1549#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0050#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2751#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0052#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3753#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1454#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3255#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3856#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4257#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2558#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1059#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5060#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2161#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4862#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1863#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5464#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0365#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1666#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2967#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5468#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3469#include "net/url_request/url_request_context_getter.h"
[email protected]302fe422012-06-11 14:49:1170#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3771#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5672#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4173#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0174#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4175#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5276#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2477#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3678#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3179#include "webkit/glue/webpreferences.h"
80
[email protected]f66df822012-05-18 16:52:1781#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5082#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5784#endif
[email protected]3e45ba92009-02-20 21:09:0085
[email protected]420ae012009-04-24 05:16:3286// Cross-Site Navigations
87//
[email protected]b172aee2012-04-10 17:05:2688// If a WebContentsImpl is told to navigate to a different web site (as
89// determined by SiteInstance), it will replace its current RenderViewHost with
90// a new RenderViewHost dedicated to the new SiteInstance. This works as
91// follows:
[email protected]420ae012009-04-24 05:16:3292//
93// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4694// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3295// - The pending RVH is "suspended," so that no navigation messages are sent to
96// its renderer until the onbeforeunload JavaScript handler has a chance to
97// run in the current RVH.
98// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
99// that it has a pending cross-site request. ResourceDispatcherHost will
100// check for this when the response arrives.
101// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46102// cancel all the pending logic. Otherwise we allow the pending RVH to send
103// the navigation request to its renderer.
104// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
105// main resource load on the pending RVH. It checks CrossSiteRequestManager
106// to see that it is a cross-site request, and installs a
107// CrossSiteResourceHandler.
108// - When RDH receives a response, the BufferedResourceHandler determines
109// whether it is a download. If so, it sends a message to the new renderer
110// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26111// pending RVH remains until the next DidNavigate event for this
112// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32113// - After RDH receives a response and determines that it is safe and not a
114// download, it pauses the response to first run the old page's onunload
115// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26116// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32117// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15118// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32119// the ResourceDispatcherHost, who unpauses the response. Data is then sent
120// to the pending RVH.
121// - The pending renderer sends a FrameNavigate message that invokes the
122// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46123// pending RVH.
[email protected]992db4c2011-05-12 15:37:15124// - The previous renderer is kept swapped out in RenderViewHostManager in case
125// the user goes back. The process only stays live if another tab is using
126// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32127
[email protected]b441a8492012-06-06 14:55:57128using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44129using content::DevToolsAgentHost;
130using content::DevToolsAgentHostRegistry;
131using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17132using content::DownloadItem;
133using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14134using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20135using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56136using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13137using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27138using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54139using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50140using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23141using content::NavigationEntry;
142using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20143using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57145using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57146using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27147using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11148using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50149using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58150using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04151using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25152using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14153using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43154using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33155using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38156using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09157using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25158using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56159using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22160using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50161using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25162using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44163
[email protected]420ae012009-04-24 05:16:32164namespace {
165
166// Amount of time we wait between when a key event is received and the renderer
167// is queried for its state and pushed to the NavigationEntry.
168const int kQueryStateDelay = 5000;
169
[email protected]6ebdc9b2010-09-27 16:55:57170const int kSyncWaitDelay = 40;
171
[email protected]82114f52012-03-20 22:53:41172const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05173
[email protected]420ae012009-04-24 05:16:32174#if defined(OS_WIN)
175
176BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
177 // Note: erase is required to properly paint some widgets borders. This can
178 // be seen with textfields.
179 InvalidateRect(hwnd, NULL, TRUE);
180 return TRUE;
181}
182#endif
183
[email protected]2c5569662011-03-22 20:45:02184ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23185 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50186 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16187 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47190 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47192 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16193 break; // Fall through to rest of function.
194 }
[email protected]5e369672009-11-03 23:48:30195
[email protected]59246c572012-02-10 13:32:13196 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
197 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23198 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13199 browser_context->DidLastSessionExitCleanly()) {
200 if (entry.GetHasPostData())
201 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02202 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13203 }
[email protected]5e369672009-11-03 23:48:30204
[email protected]2c5569662011-03-22 20:45:02205 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30206}
207
[email protected]10f417c52011-12-28 21:04:23208void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47209 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42210 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50211 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24212 const std::string& embedder_channel_name,
213 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16214 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51215 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54216 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55217 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
218 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51219 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36220 if (!entry.GetBaseURLForDataURL().is_empty()) {
221 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
222 params->history_url_for_data_url = entry.GetVirtualURL();
223 }
[email protected]36fc0392011-12-25 03:59:51224 params->referrer = entry.GetReferrer();
225 params->transition = entry.GetTransitionType();
226 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00227 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55228 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34229 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47230 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48231 params->transferred_request_child_id =
232 entry.transferred_global_request_id().child_id;
233 params->transferred_request_request_id =
234 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22235 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00236 // Avoid downloading when in view-source mode.
237 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24238 params->embedder_channel_name = embedder_channel_name;
239 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44240 params->is_post = entry.GetHasPostData();
241 if(entry.GetBrowserInitiatedPostData()) {
242 params->browser_initiated_post_data.assign(
243 entry.GetBrowserInitiatedPostData()->front(),
244 entry.GetBrowserInitiatedPostData()->front() +
245 entry.GetBrowserInitiatedPostData()->size());
246
247 }
[email protected]6c6b02d2011-09-02 03:36:47248
249 if (delegate)
250 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34251}
252
[email protected]f98f5092012-05-19 00:08:14253int GetSwitchValueAsInt(
254 const CommandLine& command_line,
255 const std::string& switch_string,
256 int min_value) {
257 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
258 int int_value;
259 if (base::StringToInt(string_value, &int_value))
260 return std::max(min_value, int_value);
261 else
262 return min_value;
263}
264
[email protected]420ae012009-04-24 05:16:32265} // namespace
266
[email protected]a81343d232011-12-27 07:39:20267namespace content {
268
269WebContents* WebContents::Create(
270 BrowserContext* browser_context,
271 SiteInstance* site_instance,
272 int routing_id,
[email protected]b172aee2012-04-10 17:05:26273 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20274 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26275 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43276 browser_context,
277 site_instance,
278 routing_id,
[email protected]b172aee2012-04-10 17:05:26279 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44280 NULL,
[email protected]adbfb8df2012-02-24 01:19:43281 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20282}
[email protected]746d3052012-05-22 15:15:47283
[email protected]299d7f12012-05-23 05:31:15284WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47285 return rvh->GetDelegate()->GetAsWebContents();
286}
287
[email protected]a81343d232011-12-27 07:39:20288}
[email protected]f4f50ef2011-01-21 19:01:19289
[email protected]b172aee2012-04-10 17:05:26290// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32291
[email protected]b172aee2012-04-10 17:05:26292WebContentsImpl::WebContentsImpl(
293 content::BrowserContext* browser_context,
294 SiteInstance* site_instance,
295 int routing_id,
296 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44297 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26298 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42299 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07300 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37301 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57302 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44303 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05304 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34305 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23306 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
307 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34308 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21309 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56310 upload_size_(0),
311 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47312 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57313 capturing_contents_(false),
314 is_being_destroyed_(false),
315 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55316 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57317#if defined(OS_WIN)
318 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
319#endif
[email protected]7ab1e7d62009-10-14 23:32:01320 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56321 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38322 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25323 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01324 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25325 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01326 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00327 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43328 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20329 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37330 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32331
[email protected]38b098f2012-03-14 21:11:57332 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57333 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
334 if (view_.get()) {
335 CHECK(render_view_host_delegate_view_);
336 } else {
[email protected]38b098f2012-03-14 21:11:57337 content::WebContentsViewDelegate* delegate =
338 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
339 this);
[email protected]5a3bdf52012-05-24 15:12:57340 view_.reset(CreateWebContentsView(
341 this, delegate, &render_view_host_delegate_view_));
342 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57343 }
344 CHECK(view_.get());
345
[email protected]ca13a442012-04-17 14:00:12346 // We have the initial size of the view be based on the size of the view of
347 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26348 view_->CreateView(base_web_contents ?
349 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00350
[email protected]14392a52012-05-02 20:28:44351 // Listen for whether our opener gets destroyed.
352 if (opener_) {
353 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
354 content::Source<WebContents>(opener_));
355 }
356
[email protected]bafe6cd2012-05-23 23:09:50357 registrar_.Add(this,
358 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
359 content::NotificationService::AllBrowserContextsAndSources());
360
[email protected]483623eb2011-10-25 09:30:00361#if defined(ENABLE_JAVA_BRIDGE)
362 java_bridge_dispatcher_host_manager_.reset(
363 new JavaBridgeDispatcherHostManager(this));
364#endif
[email protected]172cf712012-05-23 15:07:39365
366 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35367}
initial.commit09911bf2008-07-26 23:55:29368
[email protected]b172aee2012-04-10 17:05:26369WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32370 is_being_destroyed_ = true;
371
[email protected]3ab9cb82011-06-03 18:02:07372 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55373 if (dialog_creator_)
374 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07375
[email protected]da8543762012-03-20 08:52:20376 if (color_chooser_)
377 color_chooser_->End();
378
[email protected]420ae012009-04-24 05:16:32379 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32380
[email protected]ca13a442012-04-17 14:00:12381 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07382 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09383 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
384 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07385 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32386
387 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07388#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32389 // If we still have a window handle, destroy it. GetNativeView can return
390 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42391 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52392 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58393 if (host && host->GetView())
394 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42395 }
[email protected]420ae012009-04-24 05:16:32396#endif
[email protected]7ab1e7d62009-10-14 23:32:01397
398 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15399 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01400 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15401 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01402 }
[email protected]b5a1d11c2011-02-17 03:09:42403
[email protected]2db9bd72012-04-13 20:20:56404 FOR_EACH_OBSERVER(WebContentsObserver,
405 observers_,
406 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08407
[email protected]6934a702011-12-20 00:04:51408 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42409}
410
[email protected]b172aee2012-04-10 17:05:26411WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
412 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54413 WebPreferences prefs;
414
415 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
416
417 prefs.developer_extras_enabled = true;
418 prefs.javascript_enabled =
419 !command_line.HasSwitch(switches::kDisableJavaScript);
420 prefs.web_security_enabled =
421 !command_line.HasSwitch(switches::kDisableWebSecurity);
422 prefs.plugins_enabled =
423 !command_line.HasSwitch(switches::kDisablePlugins);
424 prefs.java_enabled =
425 !command_line.HasSwitch(switches::kDisableJava);
426
427 prefs.uses_page_cache =
428 command_line.HasSwitch(switches::kEnableFastback);
429 prefs.remote_fonts_enabled =
430 !command_line.HasSwitch(switches::kDisableRemoteFonts);
431 prefs.xss_auditor_enabled =
432 !command_line.HasSwitch(switches::kDisableXSSAuditor);
433 prefs.application_cache_enabled =
434 !command_line.HasSwitch(switches::kDisableApplicationCache);
435
436 prefs.local_storage_enabled =
437 !command_line.HasSwitch(switches::kDisableLocalStorage);
438 prefs.databases_enabled =
439 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01440#if defined(OS_ANDROID)
441 prefs.webaudio_enabled =
442 command_line.HasSwitch(switches::kEnableWebAudio);
443#else
[email protected]64d69de42012-02-06 00:19:54444 prefs.webaudio_enabled =
445 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01446#endif
[email protected]64d69de42012-02-06 00:19:54447
448 prefs.experimental_webgl_enabled =
449 GpuProcessHost::gpu_enabled() &&
450 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07451#if defined(OS_ANDROID)
452 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
453#else
[email protected]64d69de42012-02-06 00:19:54454 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07455#endif
[email protected]64d69de42012-02-06 00:19:54456
[email protected]5a073092012-06-08 00:42:51457 prefs.flash_3d_enabled =
458 GpuProcessHost::gpu_enabled() &&
459 !command_line.HasSwitch(switches::kDisableFlash3d);
460 prefs.flash_stage3d_enabled =
461 GpuProcessHost::gpu_enabled() &&
462 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19463
[email protected]64d69de42012-02-06 00:19:54464 prefs.gl_multisampling_enabled =
465 !command_line.HasSwitch(switches::kDisableGLMultisampling);
466 prefs.privileged_webgl_extensions_enabled =
467 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
468 prefs.site_specific_quirks_enabled =
469 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
470 prefs.allow_file_access_from_file_urls =
471 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
472 prefs.show_composited_layer_borders =
473 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
474 prefs.show_composited_layer_tree =
475 command_line.HasSwitch(switches::kShowCompositedLayerTree);
476 prefs.show_fps_counter =
477 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19478 prefs.show_paint_rects =
479 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52480 prefs.render_vsync_enabled =
481 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54482 prefs.accelerated_compositing_enabled =
483 GpuProcessHost::gpu_enabled() &&
484 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54485 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23486 command_line.HasSwitch(switches::kForceCompositingMode) &&
487 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54488 prefs.fixed_position_compositing_enabled =
489 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
490 prefs.accelerated_2d_canvas_enabled =
491 GpuProcessHost::gpu_enabled() &&
492 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58493 prefs.deferred_2d_canvas_enabled =
[email protected]7aca2362012-07-10 20:17:08494 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54495 prefs.accelerated_painting_enabled =
496 GpuProcessHost::gpu_enabled() &&
497 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
498 prefs.accelerated_filters_enabled =
499 GpuProcessHost::gpu_enabled() &&
500 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
501 prefs.accelerated_layers_enabled =
502 prefs.accelerated_animation_enabled =
503 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54504 prefs.accelerated_plugins_enabled =
505 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
506 prefs.accelerated_video_enabled =
507 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54508 prefs.fullscreen_enabled =
509 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16510 prefs.css_regions_enabled =
511 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29512 prefs.css_shaders_enabled =
513 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01514 prefs.css_variables_enabled =
515 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56516 prefs.device_supports_touch =
517 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]d849b122012-07-18 07:35:26518#if defined(OS_ANDROID)
519 prefs.device_supports_mouse = false;
520#endif
[email protected]64d69de42012-02-06 00:19:54521
522#if defined(OS_MACOSX)
523 bool default_enable_scroll_animator = true;
524#else
525 // On CrOS, the launcher always passes in the --enable flag.
526 bool default_enable_scroll_animator = false;
527#endif
528 prefs.enable_scroll_animator = default_enable_scroll_animator;
529 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
530 prefs.enable_scroll_animator = true;
531 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
532 prefs.enable_scroll_animator = false;
533
534 prefs.visual_word_movement_enabled =
535 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54536
537 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32538 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54539 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11540 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
541 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54542 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11543 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54544 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19545 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
546 prefs.flash_3d_enabled = false;
547 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
548 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11549 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54550 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11551 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54552 prefs.gl_multisampling_enabled = false;
553
554 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45555 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32556 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54557 prefs.accelerated_video_enabled = false;
558 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45559 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09560 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54561 }
562 }
563
[email protected]b9535422012-02-09 01:47:59564 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58565 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54566 prefs.loads_images_automatically = true;
567 prefs.javascript_enabled = true;
568 }
569
570 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
571
572 // Force accelerated compositing and 2d canvas off for chrome:, about: and
573 // chrome-devtools: pages (unless it's specifically allowed).
574 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54575 url.SchemeIs(chrome::kChromeUIScheme) ||
576 (url.SchemeIs(chrome::kAboutScheme) &&
577 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25578 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54579 prefs.accelerated_compositing_enabled = false;
580 prefs.accelerated_2d_canvas_enabled = false;
581 }
[email protected]43d9d782012-03-01 15:40:09582
[email protected]302fe422012-06-11 14:49:11583#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
584 prefs.threaded_animation_enabled =
585 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
586 prefs.per_tile_painting_enabled =
587 command_line.HasSwitch(switches::kEnablePerTilePainting);
588 prefs.partial_swap_enabled =
589 command_line.HasSwitch(switches::kEnablePartialSwap);
590#endif
591
[email protected]f98f5092012-05-19 00:08:14592 if (command_line.HasSwitch(switches::kDefaultTileWidth))
593 prefs.default_tile_width =
594 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
595 if (command_line.HasSwitch(switches::kDefaultTileHeight))
596 prefs.default_tile_height =
597 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
598 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
599 prefs.max_untiled_layer_width =
600 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
601 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
602 prefs.max_untiled_layer_height =
603 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
604
[email protected]2486dce2012-05-23 17:18:19605 if (gfx::Screen::IsDIPEnabled()) {
606 // Only apply when using DIP coordinate system as this setting interferes
607 // with fixed layout mode.
608 prefs.apply_default_device_scale_factor_in_compositor = true;
609 }
610
[email protected]de023762012-07-26 17:10:17611 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
612 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10613
[email protected]6b4dcb072012-06-18 22:26:51614 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
615
[email protected]2e21fe292012-03-02 22:52:32616 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54617
618 return prefs;
619}
620
[email protected]b172aee2012-04-10 17:05:26621NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20622 return controller_;
623}
624
[email protected]b172aee2012-04-10 17:05:26625RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28626 return &render_manager_;
627}
628
[email protected]7bb761892012-07-20 09:32:47629bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
630 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56631 if (GetWebUI() &&
632 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17633 return true;
[email protected]d2353452012-01-19 19:53:56634 }
[email protected]f82d57b52011-04-27 19:13:17635
[email protected]d8c660432011-12-22 20:51:25636 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
637 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10638 while ((observer = it.GetNext()) != NULL)
639 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53640 return true;
[email protected]403415a2011-01-10 18:57:53641
[email protected]7bb761892012-07-20 09:32:47642 // Message handlers should be aware of which RenderViewHost sent the
643 // message, which is temporarily stored in message_source_.
644 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18645 bool handled = true;
646 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26647 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58648 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
649 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24650 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
651 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18652 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
653 OnDidLoadResourceFromMemoryCache)
654 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
655 OnDidDisplayInsecureContent)
656 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
657 OnDidRunInsecureContent)
658 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
659 OnDocumentLoadedInFrame)
660 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26661 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
662 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17663 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
664 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25665 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26666 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59667 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21668 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20669 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
670 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
671 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16672 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45673 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10674 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20675 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
676 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
677 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
678 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29679 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50680 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18681 IPC_MESSAGE_UNHANDLED(handled = false)
682 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47683 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18684
685 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38686 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18687 GetRenderProcessHost()->ReceivedBadMessage();
688 }
689
690 return handled;
691}
692
[email protected]b172aee2012-04-10 17:05:26693void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18694 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23695 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43696 if (delegate_)
697 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18698}
699
[email protected]b172aee2012-04-10 17:05:26700NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56701 return controller_;
702}
703
[email protected]b172aee2012-04-10 17:05:26704const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56705 return controller_;
706}
707
[email protected]b172aee2012-04-10 17:05:26708content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55709 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30710}
711
[email protected]b172aee2012-04-10 17:05:26712const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31713 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23714 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51715 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31716}
717
718
[email protected]b172aee2012-04-10 17:05:26719const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31720 return &property_bag_;
721}
722
[email protected]b172aee2012-04-10 17:05:26723base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31724 return &property_bag_;
725}
726
[email protected]b172aee2012-04-10 17:05:26727content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31728 return delegate_;
729}
730
[email protected]b172aee2012-04-10 17:05:26731void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31732 // TODO(cbentzel): remove this debugging code?
733 if (delegate == delegate_)
734 return;
735 if (delegate_)
736 delegate_->Detach(this);
737 delegate_ = delegate;
738 if (delegate_)
739 delegate_->Attach(this);
740}
741
[email protected]b172aee2012-04-10 17:05:26742content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41743 RenderViewHostImpl* host = render_manager_.current_host();
744 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16745}
746
[email protected]b172aee2012-04-10 17:05:26747RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31748 return render_manager_.current_host();
749}
750
[email protected]b172aee2012-04-10 17:05:26751RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31752 return render_manager_.GetRenderWidgetHostView();
753}
754
[email protected]b172aee2012-04-10 17:05:26755content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31756 return view_.get();
757}
758
[email protected]b172aee2012-04-10 17:05:26759content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50760 WebUIControllerFactory* factory =
761 content::GetContentClient()->browser()->GetWebUIControllerFactory();
762 if (!factory)
763 return NULL;
[email protected]d2353452012-01-19 19:53:56764 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22765 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50766 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22767 if (controller) {
768 web_ui->SetController(controller);
769 return web_ui;
770 }
771
772 delete web_ui;
773 return NULL;
774}
775
[email protected]b172aee2012-04-10 17:05:26776content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31777 return render_manager_.web_ui() ? render_manager_.web_ui()
778 : render_manager_.pending_web_ui();
779}
780
[email protected]b172aee2012-04-10 17:05:26781content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31782 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34783}
784
[email protected]86ef6a392012-05-11 22:03:11785void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22786 if (GetUserAgentOverride() == override)
787 return;
788
789 renderer_preferences_.user_agent_override = override;
790
791 // Send the new override string to the renderer.
792 RenderViewHost* host = GetRenderViewHost();
793 if (host)
794 host->SyncRendererPrefs();
795
796 // Reload the page if a load is currently in progress to avoid having
797 // different parts of the page loaded using different user agents.
798 NavigationEntry* entry = controller_.GetActiveEntry();
799 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
800 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11801}
802
803const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22804 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11805}
806
[email protected]b172aee2012-04-10 17:05:26807const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55808 // Transient entries take precedence. They are used for interstitial pages
809 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23810 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08811 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20812 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30813 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23814 if (entry) {
[email protected]b5cca982011-05-26 04:42:08815 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23816 }
[email protected]7ade2732011-02-10 00:13:58817 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
818 render_manager_.pending_web_ui() : render_manager_.web_ui();
819 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54820 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55821 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54822 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35823 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22824 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54825 if (!title.empty())
826 return title;
827 }
828 }
829
830 // We use the title for the last committed entry rather than a pending
831 // navigation entry. For example, when the user types in a URL, we want to
832 // keep the old page's title until the new load has committed and we get a new
833 // title.
[email protected]96d185d2009-04-24 03:28:54834 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23835 if (entry) {
[email protected]b5cca982011-05-26 04:42:08836 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23837 }
[email protected]987fc3a2011-05-26 14:18:09838
839 // |page_title_when_no_navigation_entry_| is finally used
840 // if no title cannot be retrieved.
841 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54842}
843
[email protected]b172aee2012-04-10 17:05:26844int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46845 return GetMaxPageIDForSiteInstance(GetSiteInstance());
846}
847
[email protected]b172aee2012-04-10 17:05:26848int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
849 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33850 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
851 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46852
[email protected]b6583592012-01-25 19:52:33853 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34854}
855
[email protected]b172aee2012-04-10 17:05:26856void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46857 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
858}
859
[email protected]b172aee2012-04-10 17:05:26860void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33861 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46862 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33863 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34864}
865
[email protected]b172aee2012-04-10 17:05:26866void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
867 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57868}
869
[email protected]b172aee2012-04-10 17:05:26870SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58871 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54872}
873
[email protected]b172aee2012-04-10 17:05:26874SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38875 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
876 render_manager_.pending_render_view_host() :
877 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58878 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38879}
880
[email protected]b172aee2012-04-10 17:05:26881bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return waiting_for_response_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return load_state_;
891}
892
[email protected]b172aee2012-04-10 17:05:26893const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return load_state_host_;
895}
896
[email protected]b172aee2012-04-10 17:05:26897uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return upload_size_;
899}
900
[email protected]b172aee2012-04-10 17:05:26901uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return upload_position_;
903}
904
[email protected]b172aee2012-04-10 17:05:26905const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return encoding_;
907}
908
[email protected]b172aee2012-04-10 17:05:26909bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31910 return displayed_insecure_content_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31914 capturing_contents_ = cap;
915}
916
[email protected]b172aee2012-04-10 17:05:26917bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
919 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
920 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49921}
922
[email protected]b172aee2012-04-10 17:05:26923void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
924 int error_code) {
[email protected]443b80e2010-12-14 00:42:23925 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34926 return;
927
[email protected]443b80e2010-12-14 00:42:23928 crashed_status_ = status;
929 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46930 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34931}
932
[email protected]b172aee2012-04-10 17:05:26933base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31934 return crashed_status_;
935}
936
[email protected]b172aee2012-04-10 17:05:26937bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31938 return is_being_destroyed_;
939}
940
[email protected]b172aee2012-04-10 17:05:26941void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34942 if (delegate_)
943 delegate_->NavigationStateChanged(this, changed_flags);
944}
945
[email protected]3e324142012-06-25 18:26:33946base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
947 return last_selected_time_;
948}
949
[email protected]9e2e4632012-07-27 16:38:41950void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54951 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04952 RenderWidgetHostViewPort* rwhv =
953 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16954 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41955 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43956#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16957 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43958#endif
959 }
[email protected]96d185d2009-04-24 03:28:54960
[email protected]5ac20162010-11-24 23:33:11961 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38962
[email protected]9e2e4632012-07-27 16:38:41963 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59964
965 // The resize rect might have changed while this was inactive -- send the new
966 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58967 RenderViewHostImpl* rvh =
968 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59969 if (rvh) {
970 rvh->ResizeRectChanged(GetRootWindowResizerRect());
971 }
[email protected]96d185d2009-04-24 03:28:54972
[email protected]3e324142012-06-25 18:26:33973 bool is_visible = true;
974 content::NotificationService::current()->Notify(
975 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
976 content::Source<WebContents>(this),
977 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31978}
979
[email protected]b172aee2012-04-10 17:05:26980void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31981 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52982 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
983 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26984 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52985 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33986 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52987 // calls us).
[email protected]c30585c2012-02-16 15:02:04988 RenderWidgetHostViewPort* rwhv =
989 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16990 if (rwhv)
991 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54992 }
993
[email protected]375fa1b2012-05-22 22:05:37994 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07995 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37996 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09997 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37998 content::Details<bool>(&is_visible));
999}
1000
[email protected]b172aee2012-04-10 17:05:261001bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311002 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271003 return WillNotifyDisconnection() &&
1004 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581005 !static_cast<RenderViewHostImpl*>(
1006 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271010 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251011 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271012}
1013
[email protected]b172aee2012-04-10 17:05:261014WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441015 // We use our current SiteInstance since the cloned entry will use it anyway.
1016 // We pass |this| for the |base_web_contents| to size the view correctly, and
1017 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:261018 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:441019 GetBrowserContext(), GetSiteInstance(),
1020 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:201021 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271022 return tc;
1023}
1024
[email protected]b172aee2012-04-10 17:05:261025void WebContentsImpl::AddNewContents(WebContents* new_contents,
1026 WindowOpenDisposition disposition,
1027 const gfx::Rect& initial_pos,
1028 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271029 if (!delegate_)
1030 return;
1031
1032 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1033 user_gesture);
1034}
1035
[email protected]b172aee2012-04-10 17:05:261036gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271037 return view_->GetContentNativeView();
1038}
1039
[email protected]b172aee2012-04-10 17:05:261040gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271041 return view_->GetNativeView();
1042}
1043
[email protected]b172aee2012-04-10 17:05:261044void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271045 view_->GetContainerBounds(out);
1046}
1047
[email protected]b172aee2012-04-10 17:05:261048void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271049 view_->Focus();
1050}
1051
[email protected]14392a52012-05-02 20:28:441052void WebContentsImpl::Observe(int type,
1053 const content::NotificationSource& source,
1054 const content::NotificationDetails& details) {
1055 switch (type) {
1056 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1057 OnWebContentsDestroyed(
1058 content::Source<content::WebContents>(source).ptr());
1059 break;
[email protected]bafe6cd2012-05-23 23:09:501060 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1061 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1062 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1063 i != pending_widget_views_.end(); ++i) {
1064 if (host->GetView() == i->second) {
1065 pending_widget_views_.erase(i);
1066 break;
1067 }
1068 }
1069 break;
1070 }
[email protected]14392a52012-05-02 20:28:441071 default:
1072 NOTREACHED();
1073 }
1074}
1075
1076void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1077 // Clear the opener if it has been closed.
1078 if (web_contents == opener_) {
1079 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1080 content::Source<WebContents>(opener_));
1081 opener_ = NULL;
1082 }
1083}
1084
[email protected]b172aee2012-04-10 17:05:261085void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311086 observers_.AddObserver(observer);
1087}
1088
[email protected]b172aee2012-04-10 17:05:261089void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311090 observers_.RemoveObserver(observer);
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341094 if (delegate_)
1095 delegate_->ActivateContents(this);
1096}
1097
[email protected]b172aee2012-04-10 17:05:261098void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121099 if (delegate_)
1100 delegate_->DeactivateContents(this);
1101}
1102
[email protected]b172aee2012-04-10 17:05:261103void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481104 if (delegate_)
1105 delegate_->LostCapture();
1106}
1107
[email protected]b172aee2012-04-10 17:05:261108bool WebContentsImpl::PreHandleKeyboardEvent(
1109 const NativeWebKeyboardEvent& event,
1110 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481111 return delegate_ &&
1112 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1113}
1114
[email protected]b172aee2012-04-10 17:05:261115void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481116 if (delegate_)
1117 delegate_->HandleKeyboardEvent(event);
1118}
1119
[email protected]b172aee2012-04-10 17:05:261120void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431121 if (delegate_)
1122 delegate_->HandleMouseDown();
1123}
1124
[email protected]b172aee2012-04-10 17:05:261125void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481126 if (delegate_)
1127 delegate_->HandleMouseUp();
1128}
1129
[email protected]590a634e2012-07-19 16:38:231130void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481131 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231132 delegate_->HandlePointerActivate();
1133}
1134
1135void WebContentsImpl::HandleGestureBegin() {
1136 if (delegate_)
1137 delegate_->HandleGestureBegin();
1138}
1139
1140void WebContentsImpl::HandleGestureEnd() {
1141 if (delegate_)
1142 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481143}
1144
[email protected]b172aee2012-04-10 17:05:261145void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471146 if (delegate_)
1147 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1148}
1149
[email protected]b172aee2012-04-10 17:05:261150bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381151 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121152}
1153
[email protected]a9c81f02012-06-01 00:15:441154void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1155 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371156 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441157 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371158 } else {
1159 GotResponseToLockMouseRequest(false);
1160 }
1161}
1162
[email protected]b172aee2012-04-10 17:05:261163void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371164 if (delegate_)
1165 delegate_->LostMouseLock();
1166}
1167
[email protected]bafe6cd2012-05-23 23:09:501168void WebContentsImpl::CreateNewWindow(
1169 int route_id,
[email protected]97714c82012-06-06 10:15:131170 const ViewHostMsg_CreateWindow_Params& params,
1171 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501172 if (delegate_ && !delegate_->ShouldCreateWebContents(
1173 this, route_id, params.window_container_type, params.frame_name,
1174 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091175 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501176 return;
1177 }
1178
1179 // We usually create the new window in the same BrowsingInstance (group of
1180 // script-related windows), by passing in the current SiteInstance. However,
1181 // if the opener is being suppressed, we create a new SiteInstance in its own
1182 // BrowsingInstance.
1183 scoped_refptr<SiteInstance> site_instance =
1184 params.opener_suppressed ?
1185 SiteInstance::Create(GetBrowserContext()) :
1186 GetSiteInstance();
1187
1188 // Create the new web contents. This will automatically create the new
1189 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131190 WebContentsImpl* new_contents = new WebContentsImpl(
1191 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571192 site_instance,
1193 route_id,
1194 this,
1195 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131196 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501197 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1198
1199 if (!params.opener_suppressed) {
1200 content::WebContentsView* new_view = new_contents->GetView();
1201
1202 // TODO(brettw): It seems bogus that we have to call this function on the
1203 // newly created object and give it one of its own member variables.
1204 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1205
1206 // Save the created window associated with the route so we can show it
1207 // later.
1208 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1209 pending_contents_[route_id] = new_contents;
1210 }
1211
1212 if (delegate_) {
1213 delegate_->WebContentsCreated(
1214 this, params.opener_frame_id, params.target_url, new_contents);
1215 }
1216
1217 if (params.opener_suppressed) {
1218 // When the opener is suppressed, the original renderer cannot access the
1219 // new window. As a result, we need to show and navigate the window here.
1220 gfx::Rect initial_pos;
1221 AddNewContents(
1222 new_contents, params.disposition, initial_pos, params.user_gesture);
1223
1224 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1225 CURRENT_TAB,
1226 content::PAGE_TRANSITION_LINK,
1227 true /* is_renderer_initiated */);
1228 new_contents->OpenURL(open_params);
1229 }
1230}
1231
1232void WebContentsImpl::CreateNewWidget(int route_id,
1233 WebKit::WebPopupType popup_type) {
1234 CreateNewWidget(route_id, false, popup_type);
1235}
1236
1237void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1238 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1239}
1240
1241void WebContentsImpl::CreateNewWidget(int route_id,
1242 bool is_fullscreen,
1243 WebKit::WebPopupType popup_type) {
1244 content::RenderProcessHost* process = GetRenderProcessHost();
1245 RenderWidgetHostImpl* widget_host =
1246 new RenderWidgetHostImpl(this, process, route_id);
1247 RenderWidgetHostViewPort* widget_view =
1248 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1249 if (!is_fullscreen) {
1250 // Popups should not get activated.
1251 widget_view->SetPopupType(popup_type);
1252 }
1253 // Save the created widget associated with the route so we can show it later.
1254 pending_widget_views_[route_id] = widget_view;
1255
1256#if defined(OS_MACOSX)
1257 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1258 // to allow it to survive the trip without being hosted.
1259 base::mac::NSObjectRetain(widget_view->GetNativeView());
1260#endif
1261}
1262
1263void WebContentsImpl::ShowCreatedWindow(int route_id,
1264 WindowOpenDisposition disposition,
1265 const gfx::Rect& initial_pos,
1266 bool user_gesture) {
1267 WebContentsImpl* contents = GetCreatedWindow(route_id);
1268 if (contents)
1269 AddNewContents(contents, disposition, initial_pos, user_gesture);
1270}
1271
1272void WebContentsImpl::ShowCreatedWidget(int route_id,
1273 const gfx::Rect& initial_pos) {
1274 ShowCreatedWidget(route_id, false, initial_pos);
1275}
1276
1277void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1278 ShowCreatedWidget(route_id, true, gfx::Rect());
1279}
1280
1281void WebContentsImpl::ShowCreatedWidget(int route_id,
1282 bool is_fullscreen,
1283 const gfx::Rect& initial_pos) {
1284 if (delegate_)
1285 delegate_->RenderWidgetShowing();
1286
1287 RenderWidgetHostViewPort* widget_host_view =
1288 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1289 if (!widget_host_view)
1290 return;
1291 if (is_fullscreen) {
1292 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1293 } else {
1294 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1295 }
[email protected]89054502012-06-03 10:29:241296
1297 RenderWidgetHostImpl* render_widget_host_impl =
1298 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1299 render_widget_host_impl->Init();
1300 // Only allow privileged mouse lock for fullscreen render widget, which is
1301 // used to implement Pepper Flash fullscreen.
1302 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501303
1304#if defined(OS_MACOSX)
1305 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1306 // properly embedded (or purposefully ignored) we can release the retain we
1307 // took in CreateNewWidget().
1308 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1309#endif
1310}
1311
1312WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1313 PendingContents::iterator iter = pending_contents_.find(route_id);
1314
1315 // Certain systems can block the creation of new windows. If we didn't succeed
1316 // in creating one, just return NULL.
1317 if (iter == pending_contents_.end()) {
1318 return NULL;
1319 }
1320
1321 WebContentsImpl* new_contents = iter->second;
1322 pending_contents_.erase(route_id);
1323
1324 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1325 !new_contents->GetRenderViewHost()->GetView())
1326 return NULL;
1327
1328 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1329 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1330 return new_contents;
1331}
1332
1333RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1334 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1335 if (iter == pending_widget_views_.end()) {
1336 DCHECK(false);
1337 return NULL;
1338 }
1339
1340 RenderWidgetHostView* widget_host_view = iter->second;
1341 pending_widget_views_.erase(route_id);
1342
1343 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1344 if (!widget_host->GetProcess()->HasConnection()) {
1345 // The view has gone away or the renderer crashed. Nothing to do.
1346 return NULL;
1347 }
1348
1349 return widget_host_view;
1350}
1351
1352void WebContentsImpl::ShowContextMenu(
1353 const content::ContextMenuParams& params) {
1354 // Allow WebContentsDelegates to handle the context menu operation first.
1355 if (delegate_ && delegate_->HandleContextMenu(params))
1356 return;
1357
[email protected]5a3bdf52012-05-24 15:12:571358 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501359}
1360
[email protected]f13b4202012-06-12 23:53:231361void WebContentsImpl::RequestMediaAccessPermission(
1362 const content::MediaStreamRequest* request,
1363 const content::MediaResponseCallback& callback) {
1364 if (delegate_)
1365 delegate_->RequestMediaAccessPermission(this, request, callback);
1366 else
1367 callback.Run(content::MediaStreamDevices());
1368}
1369
[email protected]b172aee2012-04-10 17:05:261370void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231371 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331372 if (delegate_)
1373 delegate_->UpdatePreferredSize(this, pref_size);
1374}
1375
[email protected]b172aee2012-04-10 17:05:261376void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341377 if (delegate_)
1378 delegate_->ResizeDueToAutoResize(this, new_size);
1379}
1380
[email protected]b172aee2012-04-10 17:05:261381WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201382 if (!delegate_)
1383 return NULL;
[email protected]00c37fc2011-08-02 00:22:501384
[email protected]e5d549d2011-12-28 01:29:201385 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1386 // Notify observers.
1387 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1388 DidOpenURL(params.url, params.referrer,
1389 params.disposition, params.transition));
1390 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341391}
1392
[email protected]b172aee2012-04-10 17:05:261393bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501394 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251395 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231396 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251397 reload_type);
[email protected]876bc832010-09-07 16:29:541398}
[email protected]96d185d2009-04-24 03:28:541399
[email protected]ba45bfd2012-05-22 21:51:441400void WebContentsImpl::RenderViewForInterstitialPageCreated(
1401 content::RenderViewHost* render_view_host) {
1402 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1403 RenderViewForInterstitialPageCreated(render_view_host));
1404}
1405
[email protected]b172aee2012-04-10 17:05:261406bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231407 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501408 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401409 // The renderer will reject IPC messages with URLs longer than
1410 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511411 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401412 return false;
1413
[email protected]9f76c1e2012-03-05 15:15:581414 RenderViewHostImpl* dest_render_view_host =
1415 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401416 if (!dest_render_view_host)
1417 return false; // Unable to create the desired render view host.
1418
[email protected]80a8fad2011-01-29 04:02:381419 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071420 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581421 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501422 WebUIControllerFactory* factory =
1423 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271424 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501425 bool is_allowed_in_web_ui_renderer =
1426 factory &&
[email protected]24e18252012-04-16 21:26:271427 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1428 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231429 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1430 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271431 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231432 content::GetContentClient()->SetActiveURL(entry.GetURL());
1433 CHECK(0);
1434 }
[email protected]54ec6472010-04-09 19:39:581435
[email protected]96d185d2009-04-24 03:28:541436 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441437 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521438 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441439 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511440 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541441
[email protected]7bb761892012-07-20 09:32:471442 // Notify observers that we will navigate in this RV.
1443 FOR_EACH_OBSERVER(WebContentsObserver,
1444 observers_,
1445 AboutToNavigateRenderView(dest_render_view_host));
1446
[email protected]96d185d2009-04-24 03:28:541447 // Used for page load time metrics.
1448 current_load_start_ = base::TimeTicks::Now();
1449
1450 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241451 std::string embedder_channel_name;
1452 int embedder_container_id;
1453 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1454 &embedder_channel_name,
1455 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341456 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271457 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241458 embedder_channel_name,
1459 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471460 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341461 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541462
[email protected]36fc0392011-12-25 03:59:511463 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541464 // HACK!! This code suppresses javascript: URLs from being added to
1465 // session history, which is what we want to do for javascript: URLs that
1466 // do not generate content. What we really need is a message from the
1467 // renderer telling us that a new page was not created. The same message
1468 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511469 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541470 return false;
1471 }
1472
[email protected]3c9e1872010-11-18 16:17:491473 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251474 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041475 observers_,
[email protected]36fc0392011-12-25 03:59:511476 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541477
[email protected]09b29342011-06-24 19:18:481478 if (delegate_)
1479 delegate_->DidNavigateToPendingEntry(this);
1480
[email protected]d5f942ba2008-09-26 19:30:341481 return true;
1482}
1483
[email protected]b172aee2012-04-10 17:05:261484void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331485 const SiteInstance* site_instance,
1486 int history_length,
1487 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411488 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1489 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191490 if (render_manager_.pending_render_view_host()) {
1491 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141492 return;
[email protected]9e1ad4b2011-08-14 16:49:191493 }
[email protected]9f76c1e2012-03-05 15:15:581494 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191495 if (!rvh) {
1496 NOTREACHED();
1497 return;
1498 }
[email protected]9f76c1e2012-03-05 15:15:581499 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191500 NOTREACHED();
1501 return;
1502 }
[email protected]9f76c1e2012-03-05 15:15:581503 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191504 history_length,
1505 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141506}
1507
[email protected]b172aee2012-04-10 17:05:261508void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271509 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541510 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1511 return;
1512 }
[email protected]9f76c1e2012-03-05 15:15:581513 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541514}
1515
[email protected]b172aee2012-04-10 17:05:261516bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271517 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541518}
1519
[email protected]b172aee2012-04-10 17:05:261520InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271521 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221522}
1523
[email protected]b172aee2012-04-10 17:05:261524bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161525 // WebKit creates Document object when MIME type is application/xhtml+xml,
1526 // so we also support this MIME type.
1527 return contents_mime_type_ == "text/html" ||
1528 contents_mime_type_ == "text/xml" ||
1529 contents_mime_type_ == "application/xhtml+xml" ||
1530 contents_mime_type_ == "text/plain" ||
1531 contents_mime_type_ == "text/css" ||
1532 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1533}
1534
[email protected]b172aee2012-04-10 17:05:261535void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591536 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161537 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481538 download_stats::RecordDownloadSource(
1539 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461540 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141541 return;
[email protected]c7dd2f62011-07-18 15:57:591542 }
1543
1544 Stop();
1545
1546 // Create the save package and possibly prompt the user for the name to save
1547 // the page as. The user prompt is an asynchronous operation that runs on
1548 // another thread.
1549 save_package_ = new SavePackage(this);
1550 save_package_->GetSaveInfo();
1551}
1552
1553// Used in automated testing to bypass prompting the user for file names.
1554// Instead, the names and paths are hard coded rather than running them through
1555// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261556bool WebContentsImpl::SavePage(const FilePath& main_file,
1557 const FilePath& dir_path,
1558 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591559 // Stop the page from navigating.
1560 Stop();
1561
1562 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271563 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591564}
1565
[email protected]b172aee2012-04-10 17:05:261566void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121567 const FilePath& file,
1568 const base::Callback<void(const FilePath&, int64)>& callback) {
1569 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1570}
1571
[email protected]b172aee2012-04-10 17:05:261572bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231573 NavigationEntryImpl* active_entry =
1574 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321575 return (active_entry != NULL &&
1576 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511577 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321578}
1579
[email protected]b172aee2012-04-10 17:05:261580const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271581 return contents_mime_type_;
1582}
1583
[email protected]b172aee2012-04-10 17:05:261584bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271585 return notify_disconnection_;
1586}
1587
[email protected]b172aee2012-04-10 17:05:261588void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311589 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581590 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1591 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161592}
1593
[email protected]b172aee2012-04-10 17:05:261594void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311595 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581596 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1597 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161598}
1599
[email protected]b172aee2012-04-10 17:05:261600content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271601 return &renderer_preferences_;
1602}
1603
[email protected]b172aee2012-04-10 17:05:261604void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271605 new_tab_start_time_ = time;
1606}
1607
[email protected]b172aee2012-04-10 17:05:261608base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271609 return new_tab_start_time_;
1610}
1611
[email protected]e35ccd52012-05-23 16:22:471612void WebContentsImpl::Close() {
1613 Close(GetRenderViewHost());
1614}
1615
[email protected]b172aee2012-04-10 17:05:261616void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151617 if (close_start_time_.is_null())
1618 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011619}
1620
[email protected]b172aee2012-04-10 17:05:261621bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191622#if defined(OS_CHROMEOS)
1623 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1624 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511625 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201626 return false;
1627 return true;
[email protected]46624bf2010-06-09 16:04:191628#else
1629 return true;
1630#endif
1631}
1632
[email protected]b172aee2012-04-10 17:05:261633void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521634 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581635 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511636 if (delegate_)
1637 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341638}
1639
[email protected]e35ccd52012-05-23 16:22:471640void WebContentsImpl::UserGestureDone() {
1641 OnUserGesture();
1642}
1643
[email protected]b172aee2012-04-10 17:05:261644void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271645 closed_by_user_gesture_ = value;
1646}
1647
[email protected]b172aee2012-04-10 17:05:261648bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271649 return closed_by_user_gesture_;
1650}
1651
[email protected]b172aee2012-04-10 17:05:261652double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051653 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561654 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251655 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171656 return 0;
[email protected]b75b8292010-10-01 07:28:251657
1658 double zoom_level;
1659 if (temporary_zoom_settings_) {
1660 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581661 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251662 } else {
[email protected]2ae88d12011-10-14 09:11:191663 GURL url;
[email protected]10f417c52011-12-28 21:04:231664 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191665 // Since zoom map is updated using rewritten URL, use rewritten URL
1666 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511667 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191668 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251669 }
[email protected]d0b8d092010-10-25 04:05:171670 return zoom_level;
1671}
[email protected]b75b8292010-10-01 07:28:251672
[email protected]b172aee2012-04-10 17:05:261673int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1674 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171675 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011676 // Calculate the zoom percent from the factor. Round up to the nearest whole
1677 // number.
[email protected]b75b8292010-10-01 07:28:251678 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011679 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251680 *enable_decrement = percent > minimum_zoom_percent_;
1681 *enable_increment = percent < maximum_zoom_percent_;
1682 return percent;
1683}
1684
[email protected]b172aee2012-04-10 17:05:261685void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501686 if (!delegate_)
1687 return;
1688
[email protected]10f417c52011-12-28 21:04:231689 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501690 if (!active_entry)
1691 return;
1692
[email protected]36fc0392011-12-25 03:59:511693 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121694}
1695
[email protected]b172aee2012-04-10 17:05:261696void WebContentsImpl::ViewFrameSource(const GURL& url,
1697 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271698 if (!delegate_)
1699 return;
1700
1701 delegate_->ViewSourceForFrame(this, url, content_state);
1702}
1703
[email protected]b172aee2012-04-10 17:05:261704int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271705 return minimum_zoom_percent_;
1706}
1707
[email protected]b172aee2012-04-10 17:05:261708int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271709 return maximum_zoom_percent_;
1710}
1711
[email protected]b172aee2012-04-10 17:05:261712gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231713 return preferred_size_;
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271717 return content_restrictions_;
1718}
1719
[email protected]b172aee2012-04-10 17:05:261720WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501721 WebUIControllerFactory* factory =
1722 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1723 if (!factory)
1724 return WebUI::kNoWebUI;
1725 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271726}
1727
[email protected]b172aee2012-04-10 17:05:261728content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271729 // When there is a pending navigation entry, we want to use the pending WebUI
1730 // that goes along with it to control the basic flags. For example, we want to
1731 // show the pending URL in the URL bar, so we want the display_url flag to
1732 // be from the pending entry.
1733 //
1734 // The confusion comes because there are multiple possibilities for the
1735 // initial load in a tab as a side effect of the way the RenderViewHostManager
1736 // works.
1737 //
1738 // - For the very first tab the load looks "normal". The new tab Web UI is
1739 // the pending one, and we want it to apply here.
1740 //
1741 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1742 // get switched to the one previously associated with the new tab pages.
1743 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1744 // have a committed Web UI in this case.
1745 //
1746 // This condition handles all of these cases:
1747 //
1748 // - First load in first tab: no committed nav entry + pending nav entry +
1749 // pending dom ui:
1750 // -> Use pending Web UI if any.
1751 //
1752 // - First load in second tab: no committed nav entry + pending nav entry +
1753 // no pending Web UI:
1754 // -> Use the committed Web UI if any.
1755 //
1756 // - Second navigation in any tab: committed nav entry + pending nav entry:
1757 // -> Use pending Web UI if any.
1758 //
1759 // - Normal state with no load: committed nav entry + no pending nav entry:
1760 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251761 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271762 (controller_.GetLastCommittedEntry() ||
1763 render_manager_.pending_web_ui()))
1764 return render_manager_.pending_web_ui();
1765 return render_manager_.web_ui();
1766}
1767
[email protected]b172aee2012-04-10 17:05:261768bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271769 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581770 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271771}
1772
[email protected]b172aee2012-04-10 17:05:261773bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441774 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501775}
1776
[email protected]b172aee2012-04-10 17:05:261777void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321778 SkColor color) {
[email protected]da8543762012-03-20 08:52:201779 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1780 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1781}
1782
[email protected]b172aee2012-04-10 17:05:261783void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201784 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1785 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1786 if (delegate_)
1787 delegate_->DidEndColorChooser();
1788 color_chooser_ = NULL;
1789}
1790
[email protected]b172aee2012-04-10 17:05:261791bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471792 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271793 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221794 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231795 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411796 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271797}
1798
[email protected]b172aee2012-04-10 17:05:261799void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271800 if (delegate_)
1801 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211802}
1803
[email protected]3a3b75a2012-06-01 08:38:361804void WebContentsImpl::OnRegisterIntentService(
1805 const webkit_glue::WebIntentServiceData& data,
1806 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431807 if (delegate_)
1808 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301809}
1810
[email protected]b172aee2012-04-10 17:05:261811void WebContentsImpl::OnWebIntentDispatch(
1812 const webkit_glue::WebIntentData& intent,
1813 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431814 if (!delegate_)
1815 return;
1816
[email protected]0d9989d2011-12-21 20:26:001817 WebIntentsDispatcherImpl* intents_dispatcher =
1818 new WebIntentsDispatcherImpl(this, intent, intent_id);
1819 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301820}
1821
[email protected]54047eb52012-05-08 21:45:571822void WebContentsImpl::DidStartProvisionalLoadForFrame(
1823 content::RenderViewHost* render_view_host,
1824 int64 frame_id,
1825 bool is_main_frame,
1826 const GURL& opener_url,
1827 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281828 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181829 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451830 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571831 content::RenderProcessHost* render_process_host =
1832 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541833 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571834 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451835 false,
[email protected]9f76c1e2012-03-05 15:15:581836 &validated_url);
[email protected]ef108e72012-06-20 14:03:541837 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571838 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451839 true,
1840 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181841
[email protected]0d60f0192011-04-14 12:40:101842 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251843 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101844 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571845 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541846
1847 if (is_main_frame) {
1848 // Notify observers about the provisional change in the main frame URL.
1849 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1850 ProvisionalChangeToMainFrameUrl(validated_url,
1851 validated_opener_url,
1852 render_view_host));
1853 }
1854}
1855
1856void WebContentsImpl::DidRedirectProvisionalLoad(
1857 content::RenderViewHost* render_view_host,
1858 int32 page_id,
1859 const GURL& opener_url,
1860 const GURL& source_url,
1861 const GURL& target_url) {
1862 // TODO(creis): Remove this method and have the pre-rendering code listen to
1863 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1864 // instead. See http://crbug.com/78512.
1865 GURL validated_source_url(source_url);
1866 GURL validated_target_url(target_url);
1867 GURL validated_opener_url(opener_url);
1868 content::RenderProcessHost* render_process_host =
1869 render_view_host->GetProcess();
1870 RenderViewHostImpl::FilterURL(
1871 ChildProcessSecurityPolicyImpl::GetInstance(),
1872 render_process_host->GetID(),
1873 false,
1874 &validated_source_url);
1875 RenderViewHostImpl::FilterURL(
1876 ChildProcessSecurityPolicyImpl::GetInstance(),
1877 render_process_host->GetID(),
1878 false,
1879 &validated_target_url);
1880 RenderViewHostImpl::FilterURL(
1881 ChildProcessSecurityPolicyImpl::GetInstance(),
1882 render_process_host->GetID(),
1883 true,
1884 &validated_opener_url);
1885 NavigationEntry* entry;
1886 if (page_id == -1) {
1887 entry = controller_.GetPendingEntry();
1888 } else {
1889 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1890 page_id);
1891 }
1892 if (!entry || entry->GetURL() != validated_source_url)
1893 return;
1894
1895 // Notify observers about the provisional change in the main frame URL.
1896 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1897 ProvisionalChangeToMainFrameUrl(validated_target_url,
1898 validated_opener_url,
1899 render_view_host));
[email protected]724159a2010-12-30 01:11:181900}
1901
[email protected]54047eb52012-05-08 21:45:571902void WebContentsImpl::DidFailProvisionalLoadWithError(
1903 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581904 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1905 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1906 << ", error_code: " << params.error_code
1907 << ", error_description: " << params.error_description
1908 << ", is_main_frame: " << params.is_main_frame
1909 << ", showing_repost_interstitial: " <<
1910 params.showing_repost_interstitial
1911 << ", frame_id: " << params.frame_id;
1912 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571913 content::RenderProcessHost* render_process_host =
1914 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541915 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571916 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451917 false,
[email protected]9f76c1e2012-03-05 15:15:581918 &validated_url);
[email protected]724159a2010-12-30 01:11:181919
[email protected]d7b175e2011-10-11 15:31:581920 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181921 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1922 // This means that the interstitial won't be torn down properly, which is
1923 // bad. But if we have an interstitial, go back to another tab type, and
1924 // then load the same interstitial again, we could end up getting the first
1925 // interstitial's "failed" message (as a result of the cancel) when we're on
1926 // the second one.
1927 //
1928 // We can't tell this apart, so we think we're tearing down the current page
1929 // which will cause a crash later one. There is also some code in
1930 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1931 // out because of this problem.
1932 //
1933 // http://code.google.com/p/chromium/issues/detail?id=2855
1934 // Because this will not tear down the interstitial properly, if "back" is
1935 // back to another tab type, the interstitial will still be somewhat alive
1936 // in the previous tab type. If you navigate somewhere that activates the
1937 // tab with the interstitial again, you'll see a flash before the new load
1938 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271939 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181940 LOG(WARNING) << "Discarding message during interstitial.";
1941 return;
1942 }
1943
[email protected]a16690732012-07-13 19:22:171944 // Do not clear the pending entry if one exists, so that the user's typed
1945 // URL is not lost when a navigation fails or is aborted. We'll allow
1946 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181947
[email protected]54047eb52012-05-08 21:45:571948 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181949 }
1950
[email protected]d8c660432011-12-22 20:51:251951 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581952 observers_,
1953 DidFailProvisionalLoad(params.frame_id,
1954 params.is_main_frame,
1955 validated_url,
1956 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461957 params.error_description,
1958 render_view_host));
[email protected]724159a2010-12-30 01:11:181959}
1960
[email protected]b172aee2012-04-10 17:05:261961void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181962 const GURL& url,
[email protected]70435962011-08-02 20:13:281963 const std::string& security_info,
1964 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181965 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281966 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191967 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181968 cache.Increment();
1969
1970 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081971 int cert_id = 0;
1972 net::CertStatus cert_status = 0;
1973 int security_bits = -1;
1974 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511975 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1976 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001977 content::LoadFromMemoryCacheDetails details(
1978 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1979 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181980
[email protected]ad50def52011-10-19 23:17:071981 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271982 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501983 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001984 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181985}
1986
[email protected]b172aee2012-04-10 17:05:261987void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381988 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181989 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201990 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181991}
1992
[email protected]b172aee2012-04-10 17:05:261993void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021994 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231995 LOG(INFO) << security_origin << " ran insecure content from "
1996 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381997 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411998 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1999 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182000 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412001 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:202002 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:182003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182006 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252007 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472008 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182009}
2010
[email protected]b172aee2012-04-10 17:05:262011void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312012 int64 frame_id,
2013 const GURL& validated_url,
2014 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472016 DidFinishLoad(frame_id, validated_url, is_main_frame,
2017 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312018}
2019
[email protected]b172aee2012-04-10 17:05:262020void WebContentsImpl::OnDidFailLoadWithError(
2021 int64 frame_id,
2022 const GURL& validated_url,
2023 bool is_main_frame,
2024 int error_code,
2025 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252026 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312027 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472028 error_code, error_description,
2029 message_source_));
[email protected]724159a2010-12-30 01:11:182030}
2031
[email protected]b172aee2012-04-10 17:05:262032void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272033 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432034 if (delegate_)
2035 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262039 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232040 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252041 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262042 if (!entry)
2043 return;
2044 // Note that we don't call NavigationController::GotToOffset() as we don't
2045 // want to create a pending navigation entry (it might end up lingering
2046 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252047 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582048 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512049 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582050 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472051 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572052
2053 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2054 // it in now that we know. This allows us to find the entry when it commits.
2055 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232056 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332057 entry->set_site_instance(
2058 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572059 }
[email protected]216813952011-05-19 22:21:262060 }
2061}
2062
[email protected]b172aee2012-04-10 17:05:262063void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2064 int maximum_percent,
2065 bool remember) {
[email protected]216813952011-05-19 22:21:262066 minimum_zoom_percent_ = minimum_percent;
2067 maximum_zoom_percent_ = maximum_percent;
2068 temporary_zoom_settings_ = !remember;
2069}
2070
[email protected]20b433a2012-05-15 21:23:462071void WebContentsImpl::OnSaveURL(const GURL& url,
2072 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482073 download_stats::RecordDownloadSource(
2074 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262075 // Check if the URL to save matches the URL of the main frame. Since this
2076 // message originates from Pepper plugins, it may not be the case if the
2077 // plugin is an embedded element.
2078 GURL main_frame_url = GetURL();
2079 if (!main_frame_url.is_valid())
2080 return;
2081 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462082 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::OnEnumerateDirectory(int request_id,
2086 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432087 if (!delegate_)
2088 return;
2089
[email protected]b9535422012-02-09 01:47:592090 ChildProcessSecurityPolicyImpl* policy =
2091 ChildProcessSecurityPolicyImpl::GetInstance();
2092 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2093 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212094}
2095
[email protected]b172aee2012-04-10 17:05:262096void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432097 if (delegate_)
2098 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202099}
2100
[email protected]b172aee2012-04-10 17:05:262101void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2102 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362103 const string16& title,
2104 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432105 if (!delegate_)
2106 return;
2107
[email protected]b9535422012-02-09 01:47:592108 ChildProcessSecurityPolicyImpl* policy =
2109 ChildProcessSecurityPolicyImpl::GetInstance();
2110 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2111 return;
[email protected]3a3b75a2012-06-01 08:38:362112 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202113}
2114
[email protected]b172aee2012-04-10 17:05:262115void WebContentsImpl::OnFindReply(int request_id,
2116 int number_of_matches,
2117 const gfx::Rect& selection_rect,
2118 int active_match_ordinal,
2119 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432120 if (delegate_) {
2121 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2122 active_match_ordinal, final_update);
2123 }
2124
[email protected]4e6239c2011-09-23 00:11:002125 // Send a notification to the renderer that we are ready to receive more
2126 // results from the scoping effort of the Find operation. The FindInPage
2127 // scoping is asynchronous and periodically sends results back up to the
2128 // browser using IPC. In an effort to not spam the browser we have the
2129 // browser send an ACK for each FindReply message and have the renderer
2130 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582131 GetRenderViewHostImpl()->Send(
2132 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442136 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2137 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2141 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102142 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252143 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102144 AppCacheAccessed(manifest_url, blocked_by_policy));
2145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322148 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432149 color_chooser_ = delegate_ ?
2150 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202151}
2152
[email protected]b172aee2012-04-10 17:05:262153void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202154 if (color_chooser_ &&
2155 color_chooser_id == color_chooser_->identifier())
2156 color_chooser_->End();
2157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322160 SkColor color) {
[email protected]da8543762012-03-20 08:52:202161 if (color_chooser_ &&
2162 color_chooser_id == color_chooser_->identifier())
2163 color_chooser_->SetSelectedColor(color);
2164}
2165
[email protected]9f2a9d72012-04-16 16:02:222166void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2167 const FilePath& path,
2168 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442169 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2170 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292171}
2172
[email protected]d0759f492012-04-19 22:50:502173// This exists for render views that don't have a WebUI, but do have WebUI
2174// bindings enabled.
2175void WebContentsImpl::OnWebUISend(const GURL& source_url,
2176 const std::string& name,
2177 const base::ListValue& args) {
2178 if (delegate_)
2179 delegate_->WebUISend(this, source_url, name, args);
2180}
2181
[email protected]96d185d2009-04-24 03:28:542182// Notifies the RenderWidgetHost instance about the fact that the page is
2183// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262184void WebContentsImpl::SetIsLoading(bool is_loading,
2185 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542186 if (is_loading == is_loading_)
2187 return;
2188
2189 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212190 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542191 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562192 upload_size_ = 0;
2193 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542194 }
2195
2196 render_manager_.SetIsLoading(is_loading);
2197
2198 is_loading_ = is_loading;
2199 waiting_for_response_ = is_loading;
2200
[email protected]6ebdc9b2010-09-27 16:55:572201 if (delegate_)
2202 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462203 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542204
[email protected]432115822011-07-10 15:52:272205 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2206 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072207 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542208 if (details)
[email protected]6c2381d2011-10-19 02:52:532209 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072210 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502211 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542212 det);
2213}
2214
[email protected]b172aee2012-04-10 17:05:262215void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132216 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322217 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562218 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382219 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442220 // that opened the window, as long as both renderers have the same
2221 // privileges.
[email protected]1fd1a502011-03-30 16:55:562222 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562223 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582224 // web_ui might be NULL if the URL refers to a non-existent extension.
2225 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402226 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522227 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442228 }
2229 }
[email protected]1fd1a502011-03-30 16:55:562230 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442231 }
2232
[email protected]4e697b042011-07-08 06:44:562233 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322234 // Clear the status bubble. This is a workaround for a bug where WebKit
2235 // doesn't let us know that the cursor left an element during a
2236 // transition (this is also why the mouse cursor remains as a hand after
2237 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2238 // clear the bubble when a user navigates to a named anchor in the same
2239 // page.
[email protected]36fc0392011-12-25 03:59:512240 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322241 }
2242
[email protected]a6e82fc2010-02-24 22:28:142243 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472244 // Once the main frame is navigated, we're no longer considered to have
2245 // displayed insecure content.
2246 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172247 }
[email protected]ce5c4502009-05-06 16:46:112248
[email protected]3c9e1872010-11-18 16:17:492249 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252250 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042251 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322252}
2253
[email protected]b172aee2012-04-10 17:05:262254void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322255 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132256 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322257 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062258 // If we navigate off the page, reset JavaScript state. This does nothing
2259 // to prevent a malicious script from spamming messages, since the script
2260 // could just reload the page to stop blocking.
2261 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552262 dialog_creator_->ResetJavaScriptState(this);
2263 dialog_creator_ = NULL;
2264 }
[email protected]420ae012009-04-24 05:16:322265
[email protected]3c9e1872010-11-18 16:17:492266 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252267 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042268 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322269}
2270
[email protected]b172aee2012-04-10 17:05:262271void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462272 // If we are creating a RVH for a restored controller, then we need to make
2273 // sure the RenderView starts with a next_page_id_ larger than the number
2274 // of restored entries. This must be called before the RenderView starts
2275 // navigating (to avoid a race between the browser updating max_page_id and
2276 // the renderer updating next_page_id_). Because of this, we only call this
2277 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562278 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582279 if (max_restored_page_id >
2280 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2281 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2282 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322283}
2284
[email protected]b172aee2012-04-10 17:05:262285bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2286 const string16& title) {
[email protected]420ae012009-04-24 05:16:322287 // For file URLs without a title, use the pathname instead. In the case of a
2288 // synthesized title, we don't want the update to count toward the "one set
2289 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512290 string16 final_title;
[email protected]420ae012009-04-24 05:16:322291 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512292 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2293 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322294 explicit_set = false; // Don't count synthetic titles toward the set limit.
2295 } else {
[email protected]acafd272011-07-26 17:35:572296 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322297 explicit_set = true;
2298 }
2299
[email protected]987fc3a2011-05-26 14:18:092300 // If a page is created via window.open and never navigated,
2301 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552302 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092303 if (entry) {
[email protected]36fc0392011-12-25 03:59:512304 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092305 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322306
[email protected]36fc0392011-12-25 03:59:512307 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092308 } else {
2309 if (page_title_when_no_navigation_entry_ == final_title)
2310 return false; // Nothing changed, don't bother.
2311
2312 page_title_when_no_navigation_entry_ = final_title;
2313 }
[email protected]420ae012009-04-24 05:16:322314
[email protected]420ae012009-04-24 05:16:322315 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232316 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322317
[email protected]2bb171882012-03-07 02:09:462318 std::pair<content::NavigationEntry*, bool> details =
2319 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142320
[email protected]ad50def52011-10-19 23:17:072321 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442322 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2323 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462324 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042325
[email protected]420ae012009-04-24 05:16:322326 return true;
2327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322330 // After sending out a swap notification, we need to send a disconnect
2331 // notification so that clients that pick up a pointer to |this| can NULL the
2332 // pointer. See Bug 1230284.
2333 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072334 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202335 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2336 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072337 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322338}
2339
[email protected]b172aee2012-04-10 17:05:262340void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322341 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072342 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122343 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2344 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072345 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322346}
2347
[email protected]b172aee2012-04-10 17:05:262348void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322349 if (!notify_disconnection_)
2350 return;
2351
2352 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072353 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322354 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2355 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072356 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322357}
2358
[email protected]5a3bdf52012-05-24 15:12:572359RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2360 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322361}
2362
[email protected]8d3347f2009-07-09 22:00:212363RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262364WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212365 return &render_manager_;
2366}
2367
[email protected]b172aee2012-04-10 17:05:262368content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372369 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462370 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512371}
2372
[email protected]b172aee2012-04-10 17:05:262373WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172374 return this;
2375}
2376
[email protected]b172aee2012-04-10 17:05:262377gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172378 if (delegate_)
2379 return delegate_->GetRootWindowResizerRect();
2380 return gfx::Rect();
2381}
2382
[email protected]b172aee2012-04-10 17:05:262383void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442384 // Don't send notifications if we are just creating a swapped-out RVH for
2385 // the opener chain. These won't be used for view-source or WebUI, so it's
2386 // ok to return early.
2387 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2388 return;
2389
[email protected]ad50def52011-10-19 23:17:072390 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302391 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322392 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532393 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232394 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322395 if (!entry)
2396 return;
2397
2398 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352399 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562400 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582401 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322402
2403 if (entry->IsViewSourceMode()) {
2404 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582405 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2406 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322407 }
[email protected]0666aef2009-05-13 19:48:082408
[email protected]d487beefe2011-12-21 05:41:212409 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262410
2411 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252412 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322413}
2414
[email protected]b172aee2012-04-10 17:05:262415void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522416 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322417 // Don't notify the world, since this came from a renderer in the
2418 // background.
2419 return;
2420 }
2421
2422 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312423 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232424 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302425
2426 // Restore the focus to the tab (otherwise the focus will be on the top
2427 // window).
[email protected]484ae5912010-09-29 19:16:142428 if (was_crashed && !FocusLocationBarByDefault() &&
2429 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302430 Focus();
[email protected]484ae5912010-09-29 19:16:142431 }
[email protected]32ded2212011-11-10 18:51:432432
[email protected]d8c660432011-12-22 20:51:252433 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322434}
2435
[email protected]b172aee2012-04-10 17:05:262436void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2437 base::TerminationStatus status,
2438 int error_code) {
[email protected]151a63d2011-12-20 22:32:522439 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322440 // The pending page's RenderViewHost is gone.
2441 return;
2442 }
2443
2444 SetIsLoading(false, NULL);
2445 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232446 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312447 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322448
[email protected]d8c660432011-12-22 20:51:252449 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272450 observers_,
[email protected]be1f56ab2011-12-22 06:55:312451 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322452}
2453
[email protected]b172aee2012-04-10 17:05:262454void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482455 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252456 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062457}
2458
[email protected]b172aee2012-04-10 17:05:262459void WebContentsImpl::DidNavigate(
2460 RenderViewHost* rvh,
2461 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582462 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322463 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372464
[email protected]434f69f2012-02-06 21:56:522465 // Update the site of the SiteInstance if it doesn't have one yet, unless
2466 // this is for about:blank. In that case, the SiteInstance can still be
2467 // considered unused until a navigation to a real page.
2468 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2469 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332470 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522471 }
[email protected]420ae012009-04-24 05:16:322472
2473 // Need to update MIME type here because it's referred to in
2474 // UpdateNavigationCommands() called by RendererDidNavigate() to
2475 // determine whether or not to enable the encoding menu.
2476 // It's updated only for the main frame. For a subframe,
2477 // RenderView::UpdateURL does not set params.contents_mime_type.
2478 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2479 // TODO(jungshik): Add a test for the encoding menu to avoid
2480 // regressing it again.
[email protected]2905f742011-10-13 03:51:582481 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322482 contents_mime_type_ = params.contents_mime_type;
2483
[email protected]8286f51a2011-05-31 17:39:132484 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002485 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392486
[email protected]a9c0bfe2010-09-17 08:35:222487 // Send notification about committed provisional loads. This notification is
2488 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2489 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082490 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072491 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2492 // that is not recorded in the navigation history. For the purpose of
2493 // tracking navigation events, we treat this event as a sub frame navigation
2494 // event.
2495 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582496 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222497 // Whether or not a page transition was triggered by going backward or
2498 // forward in the history is only stored in the navigation controller's
2499 // entry list.
2500 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512501 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582502 content::PAGE_TRANSITION_FORWARD_BACK)) {
2503 transition_type = content::PageTransitionFromInt(
2504 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222505 }
[email protected]0d60f0192011-04-14 12:40:102506 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252507 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102508 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462509 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222510 }
2511
[email protected]76543b92009-08-31 17:27:452512 if (!did_navigate)
2513 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322514
2515 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2516 // for the appropriate notification (best) or you can add it to
2517 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2518 // necessary, please).
2519
2520 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002521 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322522 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512523 if (delegate_)
2524 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002525 }
[email protected]420ae012009-04-24 05:16:322526 DidNavigateAnyFramePostCommit(rvh, details, params);
2527}
2528
[email protected]b172aee2012-04-10 17:05:262529void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2530 int32 page_id,
2531 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152532 // Ensure that this state update comes from either the active RVH or one of
2533 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522534 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322535
2536 // We must be prepared to handle state updates for any page, these occur
2537 // when the user is scrolling and entering form data, as well as when we're
2538 // leaving a page, in which case our state may have already been moved to
2539 // the next page. The navigation controller will look up the appropriate
2540 // NavigationEntry and update it when it is notified via the delegate.
2541
2542 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582543 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322544 if (entry_index < 0)
2545 return;
[email protected]10f417c52011-12-28 21:04:232546 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322547
[email protected]36fc0392011-12-25 03:59:512548 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322549 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512550 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322551 controller_.NotifyEntryChanged(entry, entry_index);
2552}
2553
[email protected]b172aee2012-04-10 17:05:262554void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2555 int32 page_id,
2556 const string16& title,
2557 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322558 // If we have a title, that's a pretty good indication that we've started
2559 // getting useful data.
2560 SetNotWaitingForResponse();
2561
[email protected]73eb2602012-02-09 19:50:552562 // Try to find the navigation entry, which might not be the current one.
2563 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232564 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582565 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092566
[email protected]73eb2602012-02-09 19:50:552567 // We can handle title updates when we don't have an entry in
2568 // UpdateTitleForEntry, but only if the update is from the current RVH.
2569 if (!entry && rvh != GetRenderViewHost())
2570 return;
2571
[email protected]a49e10b2011-08-01 23:57:462572 // TODO(evan): make use of title_direction.
2573 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092574 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322575 return;
2576
2577 // Broadcast notifications when the UI should be updated.
2578 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462579 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322580}
2581
[email protected]b172aee2012-04-10 17:05:262582void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2583 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312584 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322585}
2586
[email protected]b172aee2012-04-10 17:05:262587void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512588 if (delegate_)
2589 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322590}
2591
[email protected]b172aee2012-04-10 17:05:262592void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292593 // The UI may be in an event-tracking loop, such as between the
2594 // mouse-down and mouse-up in text selection or a button click.
2595 // Defer the close until after tracking is complete, so that we
2596 // don't free objects out from under the UI.
2597 // TODO(shess): This could probably be integrated with the
2598 // IsDoingDrag() test below. Punting for now because I need more
2599 // research to understand how this impacts platforms other than Mac.
2600 // TODO(shess): This could get more fine-grained. For instance,
2601 // closing a tab in another window while selecting text in the
2602 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212603 if (GetView()->IsEventTracking()) {
2604 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292605 return;
2606 }
2607
[email protected]24a4d1062009-07-10 23:10:422608 // If we close the tab while we're in the middle of a drag, we'll crash.
2609 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212610 if (GetView()->IsDoingDrag()) {
2611 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422612 return;
2613 }
2614
[email protected]420ae012009-04-24 05:16:322615 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522616 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512617 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322618}
2619
[email protected]b172aee2012-04-10 17:05:262620void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522621 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512622 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572623}
2624
[email protected]b172aee2012-04-10 17:05:262625void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512626 if (delegate_ && delegate_->IsPopupOrPanel(this))
2627 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322628}
2629
[email protected]89793072012-07-23 22:25:292630void WebContentsImpl::DidStartLoading(
2631 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322632 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492633
[email protected]82114f52012-03-20 22:53:412634 if (delegate_ && content_restrictions_)
2635 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492636
2637 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2639 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322640}
2641
[email protected]89793072012-07-23 22:25:292642void WebContentsImpl::DidStopLoading(
2643 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322644 scoped_ptr<LoadNotificationDetails> details;
2645
[email protected]10f417c52011-12-28 21:04:232646 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322647 // An entry may not exist for a stop when loading an initial blank page or
2648 // if an iframe injected by script into a blank page finishes loading.
2649 if (entry) {
[email protected]420ae012009-04-24 05:16:322650 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2651
2652 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512653 entry->GetVirtualURL(),
2654 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322655 elapsed,
2656 &controller_,
2657 controller_.GetCurrentEntryIndex()));
2658 }
2659
[email protected]420ae012009-04-24 05:16:322660 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492661
2662 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292663 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2664 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322665}
2666
[email protected]b172aee2012-04-10 17:05:262667void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162668 controller_.DiscardNonCommittedEntries();
2669
2670 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462671 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162672}
2673
[email protected]b172aee2012-04-10 17:05:262674void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512675 if (delegate_)
2676 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402677}
2678
[email protected]87717d0e2012-04-26 02:58:432679void WebContentsImpl::DocumentAvailableInMainFrame(
2680 RenderViewHost* render_view_host) {
2681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2682 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102683}
2684
[email protected]b172aee2012-04-10 17:05:262685void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082686 RenderViewHost* render_view_host,
2687 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072688 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272689 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322690 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532691 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082692}
2693
[email protected]196159d2012-05-04 17:26:542694void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2695 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262696 const content::Referrer& referrer,
2697 WindowOpenDisposition disposition,
2698 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542699 // If this came from a swapped out RenderViewHost, we only allow the request
2700 // if we are still in the same BrowsingInstance.
2701 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2702 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2703 return;
2704 }
2705
[email protected]4ad5d77d2011-12-03 02:00:482706 // Delegate to RequestTransferURL because this is just the generic
2707 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582708 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482709 GlobalRequestID());
2710}
2711
[email protected]b172aee2012-04-10 17:05:262712void WebContentsImpl::RequestTransferURL(
2713 const GURL& url,
2714 const content::Referrer& referrer,
2715 WindowOpenDisposition disposition,
2716 int64 source_frame_id,
2717 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202718 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582719 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582720 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352721 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322722 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2723 // generated suggestions).
2724 //
[email protected]e0112912011-02-02 22:54:352725 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162726 // want web sites to see a referrer of "chrome://blah" (and some
2727 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322728 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432729 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222730 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482731 false /* is_renderer_initiated */);
2732 params.transferred_global_request_id = old_request_id;
2733 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222734 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322735 } else {
[email protected]6bf6a6b52012-02-03 15:41:432736 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482737 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2738 params.transferred_global_request_id = old_request_id;
2739 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582740 }
2741 if (new_contents) {
2742 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252743 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582744 DidOpenRequestedURL(new_contents,
2745 url,
2746 referrer,
2747 disposition,
2748 transition_type,
2749 source_frame_id));
[email protected]420ae012009-04-24 05:16:322750 }
2751}
2752
[email protected]e1c3a552012-05-04 20:51:322753void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2754 // Tell the active RenderViewHost to run unload handlers and close, as long
2755 // as the request came from a RenderViewHost in the same BrowsingInstance.
2756 // In most cases, we receive this from a swapped out RenderViewHost.
2757 // It is possible to receive it from one that has just been swapped in,
2758 // in which case we might as well deliver the message anyway.
2759 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2760 GetRenderViewHost()->ClosePage();
2761}
2762
[email protected]f546640b2012-05-15 00:03:492763void WebContentsImpl::RouteMessageEvent(
2764 RenderViewHost* rvh,
2765 const ViewMsg_PostMessage_Params& params) {
2766 // Only deliver the message to the active RenderViewHost if the request
2767 // came from a RenderViewHost in the same BrowsingInstance.
2768 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2769 return;
2770
2771 ViewMsg_PostMessage_Params new_params(params);
2772
2773 // If there is a source_routing_id, translate it to the routing ID for
2774 // the equivalent swapped out RVH in the target process. If we need
2775 // to create a swapped out RVH for the source tab, we create its opener
2776 // chain as well, since those will also be accessible to the target page.
2777 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2778 // Try to look up the WebContents for the source page.
2779 WebContentsImpl* source_contents = NULL;
2780 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2781 rvh->GetProcess()->GetID(), params.source_routing_id);
2782 if (source_rvh) {
2783 source_contents = static_cast<WebContentsImpl*>(
2784 source_rvh->GetDelegate()->GetAsWebContents());
2785 }
2786
2787 if (source_contents) {
2788 new_params.source_routing_id =
2789 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2790 } else {
2791 // We couldn't find it, so don't pass a source frame.
2792 new_params.source_routing_id = MSG_ROUTING_NONE;
2793 }
2794 }
2795
2796 // In most cases, we receive this from a swapped out RenderViewHost.
2797 // It is possible to receive it from one that has just been swapped in,
2798 // in which case we might as well deliver the message anyway.
2799 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2800 GetRenderViewHost()->GetRoutingID(), new_params));
2801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342804 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412805 const string16& message,
2806 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322807 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142808 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322809 IPC::Message* reply_msg,
2810 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072811 // Suppress JavaScript dialogs when requested. Also suppress messages when
2812 // showing an interstitial as it's shown over the previous page and we don't
2813 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502814 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582815 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272816 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072817 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522818 delegate_->ShouldSuppressDialogs() ||
2819 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322820
2821 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432822 std::string accept_lang = content::GetContentClient()->browser()->
2823 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552824 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522825 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432826 this,
2827 frame_url.GetOrigin(),
2828 accept_lang,
2829 javascript_message_type,
2830 message,
[email protected]51da7e32012-01-30 19:24:522831 default_prompt,
[email protected]b172aee2012-04-10 17:05:262832 base::Bind(&WebContentsImpl::OnDialogClosed,
2833 base::Unretained(this),
2834 rvh,
2835 reply_msg),
[email protected]51da7e32012-01-30 19:24:522836 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322837 }
[email protected]3ab9cb82011-06-03 18:02:072838
2839 if (suppress_this_message) {
2840 // If we are suppressing messages, just reply as if the user immediately
2841 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342842 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072843 }
2844
2845 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322846}
2847
[email protected]b172aee2012-04-10 17:05:262848void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2849 const string16& message,
2850 bool is_reload,
2851 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582852 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512853 if (delegate_)
2854 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072855
2856 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582857 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072858 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522859 delegate_->ShouldSuppressDialogs() ||
2860 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152861 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342862 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582863 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502864 return;
2865 }
[email protected]3ab9cb82011-06-03 18:02:072866
[email protected]7ab1e7d62009-10-14 23:32:012867 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552868 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522869 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322870 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262871 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522872 reply_msg));
[email protected]420ae012009-04-24 05:16:322873}
2874
[email protected]a796f202012-05-30 14:14:252875bool WebContentsImpl::AddMessageToConsole(int32 level,
2876 const string16& message,
2877 int32 line_no,
2878 const string16& source_id) {
2879 if (!delegate_)
2880 return false;
2881 return delegate_->AddMessageToConsole(this, level, message, line_no,
2882 source_id);
2883}
2884
[email protected]b172aee2012-04-10 17:05:262885WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332886 // We want to base the page config off of the real URL, rather than the
2887 // display URL.
2888 GURL url = controller_.GetActiveEntry()
2889 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2890 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322891}
2892
[email protected]b172aee2012-04-10 17:05:262893void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272894 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252895 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222896
[email protected]ea114722012-03-12 01:11:252897 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172898 if (rdh) // NULL in unittests.
2899 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252900}
2901
[email protected]b172aee2012-04-10 17:05:262902void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442903 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252904 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442905}
2906
[email protected]b172aee2012-04-10 17:05:262907void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2908 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152909 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522910 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152911 return;
2912
[email protected]9f76c1e2012-03-05 15:15:582913 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2914
[email protected]e5fc1632011-08-08 07:51:532915 // Ignore renderer unresponsive event if debugger is attached to the tab
2916 // since the event may be a result of the renderer sitting on a breakpoint.
2917 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442918 DevToolsAgentHost* agent =
2919 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2920 if (agent &&
2921 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532922 return;
2923
[email protected]420ae012009-04-24 05:16:322924 if (is_during_unload) {
2925 // Hang occurred while firing the beforeunload/unload handler.
2926 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582927 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322928
2929 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2930 return;
2931
2932 // If the tab hangs in the beforeunload/unload handler there's really
2933 // nothing we can do to recover. Pretend the unload listeners have
2934 // all fired and close the tab. If the hang is in the beforeunload handler
2935 // then the user will not have the option of cancelling the close.
2936 Close(rvh);
2937 return;
2938 }
2939
[email protected]9f76c1e2012-03-05 15:15:582940 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472941 return;
2942
[email protected]6934a702011-12-20 00:04:512943 if (delegate_)
2944 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322945}
2946
[email protected]b172aee2012-04-10 17:05:262947void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512948 if (delegate_)
2949 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322950}
2951
[email protected]b172aee2012-04-10 17:05:262952void WebContentsImpl::LoadStateChanged(
2953 const GURL& url,
2954 const net::LoadStateWithParam& load_state,
2955 uint64 upload_position,
2956 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322957 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562958 upload_position_ = upload_position;
2959 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502960 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202961 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302962 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212963 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322964 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462965 if (IsLoading()) {
2966 NotifyNavigationStateChanged(
2967 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2968 }
[email protected]420ae012009-04-24 05:16:322969}
2970
[email protected]b172aee2012-04-10 17:05:262971void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512972 if (delegate_)
2973 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252974}
2975
[email protected]b172aee2012-04-10 17:05:262976void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322977 bool proceed,
2978 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512979 if (delegate_)
2980 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322981}
2982
[email protected]b172aee2012-04-10 17:05:262983void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542984 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232985 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2986 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542987}
2988
[email protected]b172aee2012-04-10 17:05:262989void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102990 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262991 gfx::Size size = view_->GetContainerSize();
2992 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2993 // here during container initialization and normal window size will be set
2994 // later. In case of tab duplication this resizing to 0x0 prevents setting
2995 // normal size later so just ignore it.
2996 if (!size.IsEmpty())
2997 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322998}
2999
[email protected]b172aee2012-04-10 17:05:263000void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543001 NotifySwapped();
3002}
3003
[email protected]14392a52012-05-02 20:28:443004int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3005 SiteInstance* instance) {
3006 if (!opener_)
3007 return MSG_ROUTING_NONE;
3008
3009 // Recursively create RenderViews for anything else in the opener chain.
3010 return opener_->CreateOpenerRenderViews(instance);
3011}
3012
3013int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3014 int opener_route_id = MSG_ROUTING_NONE;
3015
3016 // If this tab has an opener, ensure it has a RenderView in the given
3017 // SiteInstance as well.
3018 if (opener_)
3019 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3020
3021 // Create a swapped out RenderView in the given SiteInstance if none exists,
3022 // setting its opener to the given route_id. Return the new view's route_id.
3023 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3024}
3025
[email protected]b172aee2012-04-10 17:05:263026NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:203027 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:543028}
3029
[email protected]b172aee2012-04-10 17:05:263030WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563031 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323032}
3033
[email protected]10f417c52011-12-28 21:04:233034NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263035 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323036 return controller_.GetLastCommittedEntry();
3037}
3038
[email protected]b172aee2012-04-10 17:05:263039bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443040 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443041 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323042 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523043
[email protected]420ae012009-04-24 05:16:323044 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443045 if (rwh_view)
3046 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323047
[email protected]74ce1ad2011-12-16 21:51:463048 // Make sure we use the correct starting page_id in the new RenderView.
3049 UpdateMaxPageIDIfNecessary(render_view_host);
3050 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583051 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463052
[email protected]7900bfdb2012-05-24 19:31:243053 std::string embedder_channel_name;
3054 int embedder_container_id;
3055 GetBrowserPluginEmbedderInfo(render_view_host,
3056 &embedder_channel_name,
3057 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583058 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493059 render_view_host)->CreateRenderView(string16(),
3060 opener_route_id,
3061 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243062 embedder_channel_name,
3063 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523064 return false;
[email protected]14392a52012-05-02 20:28:443065 }
[email protected]a4127722011-04-27 23:13:523066
[email protected]e60c0232011-11-11 19:56:353067#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503068 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3069 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443070 if (rwh_view) {
3071 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3072 render_widget_host->WasResized();
3073 }
[email protected]f8233cc2011-05-31 20:24:503074#endif
3075
[email protected]420ae012009-04-24 05:16:323076 return true;
3077}
3078
[email protected]b172aee2012-04-10 17:05:263079void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3080 IPC::Message* reply_msg,
3081 bool success,
3082 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543083 if (is_showing_before_unload_dialog_ && !success) {
3084 // If a beforeunload dialog is canceled, we need to stop the throbber from
3085 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293086 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353087 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543088
[email protected]3bbacc5b2012-04-17 17:46:153089 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543090 }
3091 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583092 static_cast<RenderViewHostImpl*>(
3093 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543094}
3095
[email protected]b172aee2012-04-10 17:05:263096void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123097 encoding_ = content::GetContentClient()->browser()->
3098 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103099}
[email protected]f45d2a72010-03-08 23:28:353100
[email protected]b172aee2012-04-10 17:05:263101void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463102 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263103 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573104 DownloadManager* dlm =
3105 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143106 if (!dlm)
3107 return;
3108 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263109 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143110 const NavigationEntry* entry = controller_.GetActiveEntry();
3111 if (entry)
3112 post_id = entry->GetPostID();
3113 }
[email protected]29a5ffc82012-03-13 19:35:583114 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143115 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143116 scoped_ptr<DownloadUrlParameters> params(
3117 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493118 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143119 params->set_post_id(post_id);
3120 params->set_prefer_cache(true);
3121 if (post_id >= 0)
3122 params->set_method("POST");
3123 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143124}
3125
[email protected]b172aee2012-04-10 17:05:263126void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213127 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443128 // Can be NULL during tests.
3129 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213130 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363131}
[email protected]9f76c1e2012-03-05 15:15:583132
[email protected]b172aee2012-04-10 17:05:263133RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583134 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3135}
[email protected]7900bfdb2012-05-24 19:31:243136
3137void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3138 content::RenderViewHost* render_view_host,
3139 std::string* embedder_channel_name,
3140 int* embedder_container_id) {
3141 content::RenderProcessHost* embedder_render_process_host =
3142 browser_plugin_host()->embedder_render_process_host();
3143 *embedder_container_id = browser_plugin_host()->instance_id();
3144 int embedder_process_id =
3145 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3146 if (embedder_process_id != -1) {
3147 *embedder_channel_name =
3148 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3149 embedder_process_id);
3150 }
3151}