blob: 5b5d4bde5fc4e9945f8d3fc8fbb449c4a776fa6b [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]ce9751942011-09-21 01:57:2476#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3677#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3178#include "webkit/glue/webpreferences.h"
79
[email protected]f66df822012-05-18 16:52:1780#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5081#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5783#endif
[email protected]3e45ba92009-02-20 21:09:0084
[email protected]420ae012009-04-24 05:16:3285// Cross-Site Navigations
86//
[email protected]b172aee2012-04-10 17:05:2687// If a WebContentsImpl is told to navigate to a different web site (as
88// determined by SiteInstance), it will replace its current RenderViewHost with
89// a new RenderViewHost dedicated to the new SiteInstance. This works as
90// follows:
[email protected]420ae012009-04-24 05:16:3291//
92// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4693// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3294// - The pending RVH is "suspended," so that no navigation messages are sent to
95// its renderer until the onbeforeunload JavaScript handler has a chance to
96// run in the current RVH.
97// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
98// that it has a pending cross-site request. ResourceDispatcherHost will
99// check for this when the response arrives.
100// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46101// cancel all the pending logic. Otherwise we allow the pending RVH to send
102// the navigation request to its renderer.
103// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
104// main resource load on the pending RVH. It checks CrossSiteRequestManager
105// to see that it is a cross-site request, and installs a
106// CrossSiteResourceHandler.
107// - When RDH receives a response, the BufferedResourceHandler determines
108// whether it is a download. If so, it sends a message to the new renderer
109// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26110// pending RVH remains until the next DidNavigate event for this
111// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32112// - After RDH receives a response and determines that it is safe and not a
113// download, it pauses the response to first run the old page's onunload
114// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26115// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32116// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15117// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32118// the ResourceDispatcherHost, who unpauses the response. Data is then sent
119// to the pending RVH.
120// - The pending renderer sends a FrameNavigate message that invokes the
121// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46122// pending RVH.
[email protected]992db4c2011-05-12 15:37:15123// - The previous renderer is kept swapped out in RenderViewHostManager in case
124// the user goes back. The process only stays live if another tab is using
125// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32126
[email protected]b441a8492012-06-06 14:55:57127using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44128using content::DevToolsAgentHost;
129using content::DevToolsAgentHostRegistry;
130using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17131using content::DownloadItem;
132using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14133using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20134using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56135using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13136using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27137using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54138using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50139using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23140using content::NavigationEntry;
141using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20142using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11143using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57144using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57145using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27146using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11147using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50148using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58149using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04150using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25151using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14152using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43153using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33154using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38155using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09156using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25157using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56158using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22159using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50160using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25161using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44162
[email protected]420ae012009-04-24 05:16:32163namespace {
164
165// Amount of time we wait between when a key event is received and the renderer
166// is queried for its state and pushed to the NavigationEntry.
167const int kQueryStateDelay = 5000;
168
[email protected]6ebdc9b2010-09-27 16:55:57169const int kSyncWaitDelay = 40;
170
[email protected]82114f52012-03-20 22:53:41171const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05172
[email protected]420ae012009-04-24 05:16:32173#if defined(OS_WIN)
174
175BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
176 // Note: erase is required to properly paint some widgets borders. This can
177 // be seen with textfields.
178 InvalidateRect(hwnd, NULL, TRUE);
179 return TRUE;
180}
181#endif
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23184 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16186 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47189 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47191 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16192 break; // Fall through to rest of function.
193 }
[email protected]5e369672009-11-03 23:48:30194
[email protected]59246c572012-02-10 13:32:13195 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
196 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23197 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13198 browser_context->DidLastSessionExitCleanly()) {
199 if (entry.GetHasPostData())
200 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13202 }
[email protected]5e369672009-11-03 23:48:30203
[email protected]2c5569662011-03-22 20:45:02204 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30205}
206
[email protected]10f417c52011-12-28 21:04:23207void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47208 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42209 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50210 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24211 const std::string& embedder_channel_name,
212 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16213 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51214 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54215 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55216 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
217 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51218 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36219 if (!entry.GetBaseURLForDataURL().is_empty()) {
220 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
221 params->history_url_for_data_url = entry.GetVirtualURL();
222 }
[email protected]36fc0392011-12-25 03:59:51223 params->referrer = entry.GetReferrer();
224 params->transition = entry.GetTransitionType();
225 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00226 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55227 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34228 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47229 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48230 params->transferred_request_child_id =
231 entry.transferred_global_request_id().child_id;
232 params->transferred_request_request_id =
233 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22234 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00235 // Avoid downloading when in view-source mode.
236 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24237 params->embedder_channel_name = embedder_channel_name;
238 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47239
240 if (delegate)
241 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34242}
243
[email protected]f98f5092012-05-19 00:08:14244int GetSwitchValueAsInt(
245 const CommandLine& command_line,
246 const std::string& switch_string,
247 int min_value) {
248 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
249 int int_value;
250 if (base::StringToInt(string_value, &int_value))
251 return std::max(min_value, int_value);
252 else
253 return min_value;
254}
255
[email protected]420ae012009-04-24 05:16:32256} // namespace
257
[email protected]a81343d232011-12-27 07:39:20258namespace content {
259
260WebContents* WebContents::Create(
261 BrowserContext* browser_context,
262 SiteInstance* site_instance,
263 int routing_id,
[email protected]b172aee2012-04-10 17:05:26264 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20265 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26266 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43267 browser_context,
268 site_instance,
269 routing_id,
[email protected]b172aee2012-04-10 17:05:26270 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44271 NULL,
[email protected]adbfb8df2012-02-24 01:19:43272 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20273}
[email protected]746d3052012-05-22 15:15:47274
[email protected]299d7f12012-05-23 05:31:15275WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47276 return rvh->GetDelegate()->GetAsWebContents();
277}
278
[email protected]a81343d232011-12-27 07:39:20279}
[email protected]f4f50ef2011-01-21 19:01:19280
[email protected]b172aee2012-04-10 17:05:26281// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32282
[email protected]b172aee2012-04-10 17:05:26283WebContentsImpl::WebContentsImpl(
284 content::BrowserContext* browser_context,
285 SiteInstance* site_instance,
286 int routing_id,
287 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44288 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26289 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42290 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07291 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37292 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57293 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44294 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05295 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34296 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23297 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
298 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34299 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21300 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56301 upload_size_(0),
302 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47303 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57304 capturing_contents_(false),
305 is_being_destroyed_(false),
306 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55307 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57308#if defined(OS_WIN)
309 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
310#endif
[email protected]7ab1e7d62009-10-14 23:32:01311 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56312 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38313 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25314 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01315 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25316 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01317 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00318 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43319 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20320 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37321 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32322
[email protected]38b098f2012-03-14 21:11:57323 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57324 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
325 if (view_.get()) {
326 CHECK(render_view_host_delegate_view_);
327 } else {
[email protected]38b098f2012-03-14 21:11:57328 content::WebContentsViewDelegate* delegate =
329 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
330 this);
[email protected]5a3bdf52012-05-24 15:12:57331 view_.reset(CreateWebContentsView(
332 this, delegate, &render_view_host_delegate_view_));
333 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57334 }
335 CHECK(view_.get());
336
[email protected]ca13a442012-04-17 14:00:12337 // We have the initial size of the view be based on the size of the view of
338 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26339 view_->CreateView(base_web_contents ?
340 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00341
[email protected]14392a52012-05-02 20:28:44342 // Listen for whether our opener gets destroyed.
343 if (opener_) {
344 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
345 content::Source<WebContents>(opener_));
346 }
347
[email protected]bafe6cd2012-05-23 23:09:50348 registrar_.Add(this,
349 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
350 content::NotificationService::AllBrowserContextsAndSources());
351
[email protected]483623eb2011-10-25 09:30:00352#if defined(ENABLE_JAVA_BRIDGE)
353 java_bridge_dispatcher_host_manager_.reset(
354 new JavaBridgeDispatcherHostManager(this));
355#endif
[email protected]172cf712012-05-23 15:07:39356
357 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35358}
initial.commit09911bf2008-07-26 23:55:29359
[email protected]b172aee2012-04-10 17:05:26360WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32361 is_being_destroyed_ = true;
362
[email protected]3ab9cb82011-06-03 18:02:07363 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55364 if (dialog_creator_)
365 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07366
[email protected]da8543762012-03-20 08:52:20367 if (color_chooser_)
368 color_chooser_->End();
369
[email protected]420ae012009-04-24 05:16:32370 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32371
[email protected]ca13a442012-04-17 14:00:12372 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07373 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09374 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
375 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32377
378 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07379#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32380 // If we still have a window handle, destroy it. GetNativeView can return
381 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42382 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52383 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58384 if (host && host->GetView())
385 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42386 }
[email protected]420ae012009-04-24 05:16:32387#endif
[email protected]7ab1e7d62009-10-14 23:32:01388
389 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15390 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01391 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15392 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01393 }
[email protected]b5a1d11c2011-02-17 03:09:42394
[email protected]2db9bd72012-04-13 20:20:56395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
397 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08398
[email protected]6934a702011-12-20 00:04:51399 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42400}
401
[email protected]b172aee2012-04-10 17:05:26402WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
403 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54404 WebPreferences prefs;
405
406 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
407
408 prefs.developer_extras_enabled = true;
409 prefs.javascript_enabled =
410 !command_line.HasSwitch(switches::kDisableJavaScript);
411 prefs.web_security_enabled =
412 !command_line.HasSwitch(switches::kDisableWebSecurity);
413 prefs.plugins_enabled =
414 !command_line.HasSwitch(switches::kDisablePlugins);
415 prefs.java_enabled =
416 !command_line.HasSwitch(switches::kDisableJava);
417
418 prefs.uses_page_cache =
419 command_line.HasSwitch(switches::kEnableFastback);
420 prefs.remote_fonts_enabled =
421 !command_line.HasSwitch(switches::kDisableRemoteFonts);
422 prefs.xss_auditor_enabled =
423 !command_line.HasSwitch(switches::kDisableXSSAuditor);
424 prefs.application_cache_enabled =
425 !command_line.HasSwitch(switches::kDisableApplicationCache);
426
427 prefs.local_storage_enabled =
428 !command_line.HasSwitch(switches::kDisableLocalStorage);
429 prefs.databases_enabled =
430 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01431#if defined(OS_ANDROID)
432 prefs.webaudio_enabled =
433 command_line.HasSwitch(switches::kEnableWebAudio);
434#else
[email protected]64d69de42012-02-06 00:19:54435 prefs.webaudio_enabled =
436 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01437#endif
[email protected]64d69de42012-02-06 00:19:54438
439 prefs.experimental_webgl_enabled =
440 GpuProcessHost::gpu_enabled() &&
441 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07442#if defined(OS_ANDROID)
443 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
444#else
[email protected]64d69de42012-02-06 00:19:54445 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07446#endif
[email protected]64d69de42012-02-06 00:19:54447
[email protected]5a073092012-06-08 00:42:51448 prefs.flash_3d_enabled =
449 GpuProcessHost::gpu_enabled() &&
450 !command_line.HasSwitch(switches::kDisableFlash3d);
451 prefs.flash_stage3d_enabled =
452 GpuProcessHost::gpu_enabled() &&
453 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19454
[email protected]64d69de42012-02-06 00:19:54455 prefs.gl_multisampling_enabled =
456 !command_line.HasSwitch(switches::kDisableGLMultisampling);
457 prefs.privileged_webgl_extensions_enabled =
458 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
459 prefs.site_specific_quirks_enabled =
460 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
461 prefs.allow_file_access_from_file_urls =
462 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
463 prefs.show_composited_layer_borders =
464 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
465 prefs.show_composited_layer_tree =
466 command_line.HasSwitch(switches::kShowCompositedLayerTree);
467 prefs.show_fps_counter =
468 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19469 prefs.show_paint_rects =
470 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54471 prefs.accelerated_compositing_enabled =
472 GpuProcessHost::gpu_enabled() &&
473 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54474 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23475 command_line.HasSwitch(switches::kForceCompositingMode) &&
476 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54477 prefs.fixed_position_compositing_enabled =
478 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
479 prefs.accelerated_2d_canvas_enabled =
480 GpuProcessHost::gpu_enabled() &&
481 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58482 prefs.deferred_2d_canvas_enabled =
[email protected]7aca2362012-07-10 20:17:08483 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54484 prefs.accelerated_painting_enabled =
485 GpuProcessHost::gpu_enabled() &&
486 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
487 prefs.accelerated_filters_enabled =
488 GpuProcessHost::gpu_enabled() &&
489 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
490 prefs.accelerated_layers_enabled =
491 prefs.accelerated_animation_enabled =
492 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54493 prefs.accelerated_plugins_enabled =
494 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
495 prefs.accelerated_video_enabled =
496 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54497 prefs.fullscreen_enabled =
498 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16499 prefs.css_regions_enabled =
500 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29501 prefs.css_shaders_enabled =
502 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01503 prefs.css_variables_enabled =
504 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56505 prefs.device_supports_touch =
506 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]d849b122012-07-18 07:35:26507#if defined(OS_ANDROID)
508 prefs.device_supports_mouse = false;
509#endif
[email protected]64d69de42012-02-06 00:19:54510
511#if defined(OS_MACOSX)
512 bool default_enable_scroll_animator = true;
513#else
514 // On CrOS, the launcher always passes in the --enable flag.
515 bool default_enable_scroll_animator = false;
516#endif
517 prefs.enable_scroll_animator = default_enable_scroll_animator;
518 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
519 prefs.enable_scroll_animator = true;
520 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
521 prefs.enable_scroll_animator = false;
522
523 prefs.visual_word_movement_enabled =
524 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54525
526 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32527 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54528 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11529 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
530 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54531 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11532 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54533 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19534 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
535 prefs.flash_3d_enabled = false;
536 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
537 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11538 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54539 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11540 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54541 prefs.gl_multisampling_enabled = false;
542
543 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45544 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32545 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54546 prefs.accelerated_video_enabled = false;
547 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45548 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09549 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54550 }
551 }
552
[email protected]b9535422012-02-09 01:47:59553 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58554 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54555 prefs.loads_images_automatically = true;
556 prefs.javascript_enabled = true;
557 }
558
559 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
560
561 // Force accelerated compositing and 2d canvas off for chrome:, about: and
562 // chrome-devtools: pages (unless it's specifically allowed).
563 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54564 url.SchemeIs(chrome::kChromeUIScheme) ||
565 (url.SchemeIs(chrome::kAboutScheme) &&
566 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25567 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54568 prefs.accelerated_compositing_enabled = false;
569 prefs.accelerated_2d_canvas_enabled = false;
570 }
[email protected]43d9d782012-03-01 15:40:09571
[email protected]302fe422012-06-11 14:49:11572#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
573 prefs.threaded_animation_enabled =
574 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
575 prefs.per_tile_painting_enabled =
576 command_line.HasSwitch(switches::kEnablePerTilePainting);
577 prefs.partial_swap_enabled =
578 command_line.HasSwitch(switches::kEnablePartialSwap);
579#endif
580
[email protected]f98f5092012-05-19 00:08:14581 if (command_line.HasSwitch(switches::kDefaultTileWidth))
582 prefs.default_tile_width =
583 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
584 if (command_line.HasSwitch(switches::kDefaultTileHeight))
585 prefs.default_tile_height =
586 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
587 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
588 prefs.max_untiled_layer_width =
589 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
590 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
591 prefs.max_untiled_layer_height =
592 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
593
[email protected]2486dce2012-05-23 17:18:19594 if (gfx::Screen::IsDIPEnabled()) {
595 // Only apply when using DIP coordinate system as this setting interferes
596 // with fixed layout mode.
597 prefs.apply_default_device_scale_factor_in_compositor = true;
598 }
599
[email protected]de023762012-07-26 17:10:17600 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
601 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10602
[email protected]6b4dcb072012-06-18 22:26:51603 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
604
[email protected]2e21fe292012-03-02 22:52:32605 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54606
607 return prefs;
608}
609
[email protected]b172aee2012-04-10 17:05:26610NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20611 return controller_;
612}
613
[email protected]b172aee2012-04-10 17:05:26614RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28615 return &render_manager_;
616}
617
[email protected]7bb761892012-07-20 09:32:47618bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
619 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56620 if (GetWebUI() &&
621 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17622 return true;
[email protected]d2353452012-01-19 19:53:56623 }
[email protected]f82d57b52011-04-27 19:13:17624
[email protected]d8c660432011-12-22 20:51:25625 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
626 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10627 while ((observer = it.GetNext()) != NULL)
628 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53629 return true;
[email protected]403415a2011-01-10 18:57:53630
[email protected]7bb761892012-07-20 09:32:47631 // Message handlers should be aware of which RenderViewHost sent the
632 // message, which is temporarily stored in message_source_.
633 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18634 bool handled = true;
635 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26636 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58637 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
638 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24639 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
640 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18641 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
642 OnDidLoadResourceFromMemoryCache)
643 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
644 OnDidDisplayInsecureContent)
645 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
646 OnDidRunInsecureContent)
647 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
648 OnDocumentLoadedInFrame)
649 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26650 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
651 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17652 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
653 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25654 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26655 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59656 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21657 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20658 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
659 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
660 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16661 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45662 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10663 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20664 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
665 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
666 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
667 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29668 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50669 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18670 IPC_MESSAGE_UNHANDLED(handled = false)
671 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47672 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18673
674 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38675 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18676 GetRenderProcessHost()->ReceivedBadMessage();
677 }
678
679 return handled;
680}
681
[email protected]b172aee2012-04-10 17:05:26682void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18683 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23684 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43685 if (delegate_)
686 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18687}
688
[email protected]b172aee2012-04-10 17:05:26689NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56690 return controller_;
691}
692
[email protected]b172aee2012-04-10 17:05:26693const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56694 return controller_;
695}
696
[email protected]b172aee2012-04-10 17:05:26697content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55698 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30699}
700
[email protected]b172aee2012-04-10 17:05:26701const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31702 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23703 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51704 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31705}
706
707
[email protected]b172aee2012-04-10 17:05:26708const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31709 return &property_bag_;
710}
711
[email protected]b172aee2012-04-10 17:05:26712base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31713 return &property_bag_;
714}
715
[email protected]b172aee2012-04-10 17:05:26716content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31717 return delegate_;
718}
719
[email protected]b172aee2012-04-10 17:05:26720void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31721 // TODO(cbentzel): remove this debugging code?
722 if (delegate == delegate_)
723 return;
724 if (delegate_)
725 delegate_->Detach(this);
726 delegate_ = delegate;
727 if (delegate_)
728 delegate_->Attach(this);
729}
730
[email protected]b172aee2012-04-10 17:05:26731content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41732 RenderViewHostImpl* host = render_manager_.current_host();
733 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16734}
735
[email protected]b172aee2012-04-10 17:05:26736RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31737 return render_manager_.current_host();
738}
739
[email protected]b172aee2012-04-10 17:05:26740RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31741 return render_manager_.GetRenderWidgetHostView();
742}
743
[email protected]b172aee2012-04-10 17:05:26744content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31745 return view_.get();
746}
747
[email protected]b172aee2012-04-10 17:05:26748content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50749 WebUIControllerFactory* factory =
750 content::GetContentClient()->browser()->GetWebUIControllerFactory();
751 if (!factory)
752 return NULL;
[email protected]d2353452012-01-19 19:53:56753 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22754 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50755 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22756 if (controller) {
757 web_ui->SetController(controller);
758 return web_ui;
759 }
760
761 delete web_ui;
762 return NULL;
763}
764
[email protected]b172aee2012-04-10 17:05:26765content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31766 return render_manager_.web_ui() ? render_manager_.web_ui()
767 : render_manager_.pending_web_ui();
768}
769
[email protected]b172aee2012-04-10 17:05:26770content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31771 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34772}
773
[email protected]86ef6a392012-05-11 22:03:11774void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22775 if (GetUserAgentOverride() == override)
776 return;
777
778 renderer_preferences_.user_agent_override = override;
779
780 // Send the new override string to the renderer.
781 RenderViewHost* host = GetRenderViewHost();
782 if (host)
783 host->SyncRendererPrefs();
784
785 // Reload the page if a load is currently in progress to avoid having
786 // different parts of the page loaded using different user agents.
787 NavigationEntry* entry = controller_.GetActiveEntry();
788 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
789 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11790}
791
792const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22793 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11794}
795
[email protected]b172aee2012-04-10 17:05:26796const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55797 // Transient entries take precedence. They are used for interstitial pages
798 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23799 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08800 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20801 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30802 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23803 if (entry) {
[email protected]b5cca982011-05-26 04:42:08804 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23805 }
[email protected]7ade2732011-02-10 00:13:58806 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
807 render_manager_.pending_web_ui() : render_manager_.web_ui();
808 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54809 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55810 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54811 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35812 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22813 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54814 if (!title.empty())
815 return title;
816 }
817 }
818
819 // We use the title for the last committed entry rather than a pending
820 // navigation entry. For example, when the user types in a URL, we want to
821 // keep the old page's title until the new load has committed and we get a new
822 // title.
[email protected]96d185d2009-04-24 03:28:54823 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23824 if (entry) {
[email protected]b5cca982011-05-26 04:42:08825 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23826 }
[email protected]987fc3a2011-05-26 14:18:09827
828 // |page_title_when_no_navigation_entry_| is finally used
829 // if no title cannot be retrieved.
830 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54831}
832
[email protected]b172aee2012-04-10 17:05:26833int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46834 return GetMaxPageIDForSiteInstance(GetSiteInstance());
835}
836
[email protected]b172aee2012-04-10 17:05:26837int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
838 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33839 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
840 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46841
[email protected]b6583592012-01-25 19:52:33842 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34843}
844
[email protected]b172aee2012-04-10 17:05:26845void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46846 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
847}
848
[email protected]b172aee2012-04-10 17:05:26849void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33850 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46851 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33852 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34853}
854
[email protected]b172aee2012-04-10 17:05:26855void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
856 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57857}
858
[email protected]b172aee2012-04-10 17:05:26859SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58860 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54861}
862
[email protected]b172aee2012-04-10 17:05:26863SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38864 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
865 render_manager_.pending_render_view_host() :
866 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58867 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38868}
869
[email protected]b172aee2012-04-10 17:05:26870bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return waiting_for_response_;
876}
877
[email protected]b172aee2012-04-10 17:05:26878const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return load_state_;
880}
881
[email protected]b172aee2012-04-10 17:05:26882const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return load_state_host_;
884}
885
[email protected]b172aee2012-04-10 17:05:26886uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31887 return upload_size_;
888}
889
[email protected]b172aee2012-04-10 17:05:26890uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31891 return upload_position_;
892}
893
[email protected]b172aee2012-04-10 17:05:26894const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31895 return encoding_;
896}
897
[email protected]b172aee2012-04-10 17:05:26898bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31899 return displayed_insecure_content_;
900}
901
[email protected]b172aee2012-04-10 17:05:26902void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31903 capturing_contents_ = cap;
904}
905
[email protected]b172aee2012-04-10 17:05:26906bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31907 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
908 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
909 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49910}
911
[email protected]b172aee2012-04-10 17:05:26912void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
913 int error_code) {
[email protected]443b80e2010-12-14 00:42:23914 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34915 return;
916
[email protected]443b80e2010-12-14 00:42:23917 crashed_status_ = status;
918 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46919 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34920}
921
[email protected]b172aee2012-04-10 17:05:26922base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31923 return crashed_status_;
924}
925
[email protected]b172aee2012-04-10 17:05:26926bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return is_being_destroyed_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34931 if (delegate_)
932 delegate_->NavigationStateChanged(this, changed_flags);
933}
934
[email protected]3e324142012-06-25 18:26:33935base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
936 return last_selected_time_;
937}
938
939void WebContentsImpl::WasRestored() {
[email protected]96d185d2009-04-24 03:28:54940 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04941 RenderWidgetHostViewPort* rwhv =
942 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16943 if (rwhv) {
[email protected]3e324142012-06-25 18:26:33944 rwhv->WasRestored();
[email protected]789e9152009-08-04 21:59:43945#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16946 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43947#endif
948 }
[email protected]96d185d2009-04-24 03:28:54949
[email protected]5ac20162010-11-24 23:33:11950 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38951
[email protected]3e324142012-06-25 18:26:33952 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasRestored());
[email protected]b9769d82012-02-10 00:23:59953
954 // The resize rect might have changed while this was inactive -- send the new
955 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58956 RenderViewHostImpl* rvh =
957 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59958 if (rvh) {
959 rvh->ResizeRectChanged(GetRootWindowResizerRect());
960 }
[email protected]96d185d2009-04-24 03:28:54961
[email protected]3e324142012-06-25 18:26:33962 bool is_visible = true;
963 content::NotificationService::current()->Notify(
964 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
965 content::Source<WebContents>(this),
966 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31967}
968
[email protected]b172aee2012-04-10 17:05:26969void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31970 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52971 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
972 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26973 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52974 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33975 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52976 // calls us).
[email protected]c30585c2012-02-16 15:02:04977 RenderWidgetHostViewPort* rwhv =
978 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16979 if (rwhv)
980 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54981 }
982
[email protected]375fa1b2012-05-22 22:05:37983 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07984 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37985 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09986 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37987 content::Details<bool>(&is_visible));
988}
989
[email protected]b172aee2012-04-10 17:05:26990bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31991 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27992 return WillNotifyDisconnection() &&
993 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58994 !static_cast<RenderViewHostImpl*>(
995 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27999 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251000 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271001}
1002
[email protected]b172aee2012-04-10 17:05:261003WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441004 // We use our current SiteInstance since the cloned entry will use it anyway.
1005 // We pass |this| for the |base_web_contents| to size the view correctly, and
1006 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:261007 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:441008 GetBrowserContext(), GetSiteInstance(),
1009 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:201010 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271011 return tc;
1012}
1013
[email protected]b172aee2012-04-10 17:05:261014void WebContentsImpl::AddNewContents(WebContents* new_contents,
1015 WindowOpenDisposition disposition,
1016 const gfx::Rect& initial_pos,
1017 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271018 if (!delegate_)
1019 return;
1020
1021 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1022 user_gesture);
1023}
1024
[email protected]b172aee2012-04-10 17:05:261025gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271026 return view_->GetContentNativeView();
1027}
1028
[email protected]b172aee2012-04-10 17:05:261029gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271030 return view_->GetNativeView();
1031}
1032
[email protected]b172aee2012-04-10 17:05:261033void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271034 view_->GetContainerBounds(out);
1035}
1036
[email protected]b172aee2012-04-10 17:05:261037void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271038 view_->Focus();
1039}
1040
[email protected]14392a52012-05-02 20:28:441041void WebContentsImpl::Observe(int type,
1042 const content::NotificationSource& source,
1043 const content::NotificationDetails& details) {
1044 switch (type) {
1045 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1046 OnWebContentsDestroyed(
1047 content::Source<content::WebContents>(source).ptr());
1048 break;
[email protected]bafe6cd2012-05-23 23:09:501049 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1050 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1051 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1052 i != pending_widget_views_.end(); ++i) {
1053 if (host->GetView() == i->second) {
1054 pending_widget_views_.erase(i);
1055 break;
1056 }
1057 }
1058 break;
1059 }
[email protected]14392a52012-05-02 20:28:441060 default:
1061 NOTREACHED();
1062 }
1063}
1064
1065void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1066 // Clear the opener if it has been closed.
1067 if (web_contents == opener_) {
1068 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1069 content::Source<WebContents>(opener_));
1070 opener_ = NULL;
1071 }
1072}
1073
[email protected]b172aee2012-04-10 17:05:261074void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311075 observers_.AddObserver(observer);
1076}
1077
[email protected]b172aee2012-04-10 17:05:261078void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311079 observers_.RemoveObserver(observer);
1080}
1081
[email protected]b172aee2012-04-10 17:05:261082void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341083 if (delegate_)
1084 delegate_->ActivateContents(this);
1085}
1086
[email protected]b172aee2012-04-10 17:05:261087void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121088 if (delegate_)
1089 delegate_->DeactivateContents(this);
1090}
1091
[email protected]b172aee2012-04-10 17:05:261092void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481093 if (delegate_)
1094 delegate_->LostCapture();
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097bool WebContentsImpl::PreHandleKeyboardEvent(
1098 const NativeWebKeyboardEvent& event,
1099 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481100 return delegate_ &&
1101 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1102}
1103
[email protected]b172aee2012-04-10 17:05:261104void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481105 if (delegate_)
1106 delegate_->HandleKeyboardEvent(event);
1107}
1108
[email protected]b172aee2012-04-10 17:05:261109void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431110 if (delegate_)
1111 delegate_->HandleMouseDown();
1112}
1113
[email protected]b172aee2012-04-10 17:05:261114void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481115 if (delegate_)
1116 delegate_->HandleMouseUp();
1117}
1118
[email protected]590a634e2012-07-19 16:38:231119void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481120 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231121 delegate_->HandlePointerActivate();
1122}
1123
1124void WebContentsImpl::HandleGestureBegin() {
1125 if (delegate_)
1126 delegate_->HandleGestureBegin();
1127}
1128
1129void WebContentsImpl::HandleGestureEnd() {
1130 if (delegate_)
1131 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481132}
1133
[email protected]b172aee2012-04-10 17:05:261134void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471135 if (delegate_)
1136 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381140 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121141}
1142
[email protected]a9c81f02012-06-01 00:15:441143void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1144 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371145 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441146 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371147 } else {
1148 GotResponseToLockMouseRequest(false);
1149 }
1150}
1151
[email protected]b172aee2012-04-10 17:05:261152void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371153 if (delegate_)
1154 delegate_->LostMouseLock();
1155}
1156
[email protected]bafe6cd2012-05-23 23:09:501157void WebContentsImpl::CreateNewWindow(
1158 int route_id,
[email protected]97714c82012-06-06 10:15:131159 const ViewHostMsg_CreateWindow_Params& params,
1160 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501161 if (delegate_ && !delegate_->ShouldCreateWebContents(
1162 this, route_id, params.window_container_type, params.frame_name,
1163 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091164 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501165 return;
1166 }
1167
1168 // We usually create the new window in the same BrowsingInstance (group of
1169 // script-related windows), by passing in the current SiteInstance. However,
1170 // if the opener is being suppressed, we create a new SiteInstance in its own
1171 // BrowsingInstance.
1172 scoped_refptr<SiteInstance> site_instance =
1173 params.opener_suppressed ?
1174 SiteInstance::Create(GetBrowserContext()) :
1175 GetSiteInstance();
1176
1177 // Create the new web contents. This will automatically create the new
1178 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131179 WebContentsImpl* new_contents = new WebContentsImpl(
1180 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571181 site_instance,
1182 route_id,
1183 this,
1184 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131185 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501186 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1187
1188 if (!params.opener_suppressed) {
1189 content::WebContentsView* new_view = new_contents->GetView();
1190
1191 // TODO(brettw): It seems bogus that we have to call this function on the
1192 // newly created object and give it one of its own member variables.
1193 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1194
1195 // Save the created window associated with the route so we can show it
1196 // later.
1197 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1198 pending_contents_[route_id] = new_contents;
1199 }
1200
1201 if (delegate_) {
1202 delegate_->WebContentsCreated(
1203 this, params.opener_frame_id, params.target_url, new_contents);
1204 }
1205
1206 if (params.opener_suppressed) {
1207 // When the opener is suppressed, the original renderer cannot access the
1208 // new window. As a result, we need to show and navigate the window here.
1209 gfx::Rect initial_pos;
1210 AddNewContents(
1211 new_contents, params.disposition, initial_pos, params.user_gesture);
1212
1213 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1214 CURRENT_TAB,
1215 content::PAGE_TRANSITION_LINK,
1216 true /* is_renderer_initiated */);
1217 new_contents->OpenURL(open_params);
1218 }
1219}
1220
1221void WebContentsImpl::CreateNewWidget(int route_id,
1222 WebKit::WebPopupType popup_type) {
1223 CreateNewWidget(route_id, false, popup_type);
1224}
1225
1226void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1227 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1228}
1229
1230void WebContentsImpl::CreateNewWidget(int route_id,
1231 bool is_fullscreen,
1232 WebKit::WebPopupType popup_type) {
1233 content::RenderProcessHost* process = GetRenderProcessHost();
1234 RenderWidgetHostImpl* widget_host =
1235 new RenderWidgetHostImpl(this, process, route_id);
1236 RenderWidgetHostViewPort* widget_view =
1237 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1238 if (!is_fullscreen) {
1239 // Popups should not get activated.
1240 widget_view->SetPopupType(popup_type);
1241 }
1242 // Save the created widget associated with the route so we can show it later.
1243 pending_widget_views_[route_id] = widget_view;
1244
1245#if defined(OS_MACOSX)
1246 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1247 // to allow it to survive the trip without being hosted.
1248 base::mac::NSObjectRetain(widget_view->GetNativeView());
1249#endif
1250}
1251
1252void WebContentsImpl::ShowCreatedWindow(int route_id,
1253 WindowOpenDisposition disposition,
1254 const gfx::Rect& initial_pos,
1255 bool user_gesture) {
1256 WebContentsImpl* contents = GetCreatedWindow(route_id);
1257 if (contents)
1258 AddNewContents(contents, disposition, initial_pos, user_gesture);
1259}
1260
1261void WebContentsImpl::ShowCreatedWidget(int route_id,
1262 const gfx::Rect& initial_pos) {
1263 ShowCreatedWidget(route_id, false, initial_pos);
1264}
1265
1266void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1267 ShowCreatedWidget(route_id, true, gfx::Rect());
1268}
1269
1270void WebContentsImpl::ShowCreatedWidget(int route_id,
1271 bool is_fullscreen,
1272 const gfx::Rect& initial_pos) {
1273 if (delegate_)
1274 delegate_->RenderWidgetShowing();
1275
1276 RenderWidgetHostViewPort* widget_host_view =
1277 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1278 if (!widget_host_view)
1279 return;
1280 if (is_fullscreen) {
1281 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1282 } else {
1283 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1284 }
[email protected]89054502012-06-03 10:29:241285
1286 RenderWidgetHostImpl* render_widget_host_impl =
1287 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1288 render_widget_host_impl->Init();
1289 // Only allow privileged mouse lock for fullscreen render widget, which is
1290 // used to implement Pepper Flash fullscreen.
1291 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501292
1293#if defined(OS_MACOSX)
1294 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1295 // properly embedded (or purposefully ignored) we can release the retain we
1296 // took in CreateNewWidget().
1297 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1298#endif
1299}
1300
1301WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1302 PendingContents::iterator iter = pending_contents_.find(route_id);
1303
1304 // Certain systems can block the creation of new windows. If we didn't succeed
1305 // in creating one, just return NULL.
1306 if (iter == pending_contents_.end()) {
1307 return NULL;
1308 }
1309
1310 WebContentsImpl* new_contents = iter->second;
1311 pending_contents_.erase(route_id);
1312
1313 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1314 !new_contents->GetRenderViewHost()->GetView())
1315 return NULL;
1316
1317 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1318 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1319 return new_contents;
1320}
1321
1322RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1323 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1324 if (iter == pending_widget_views_.end()) {
1325 DCHECK(false);
1326 return NULL;
1327 }
1328
1329 RenderWidgetHostView* widget_host_view = iter->second;
1330 pending_widget_views_.erase(route_id);
1331
1332 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1333 if (!widget_host->GetProcess()->HasConnection()) {
1334 // The view has gone away or the renderer crashed. Nothing to do.
1335 return NULL;
1336 }
1337
1338 return widget_host_view;
1339}
1340
1341void WebContentsImpl::ShowContextMenu(
1342 const content::ContextMenuParams& params) {
1343 // Allow WebContentsDelegates to handle the context menu operation first.
1344 if (delegate_ && delegate_->HandleContextMenu(params))
1345 return;
1346
[email protected]5a3bdf52012-05-24 15:12:571347 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501348}
1349
[email protected]f13b4202012-06-12 23:53:231350void WebContentsImpl::RequestMediaAccessPermission(
1351 const content::MediaStreamRequest* request,
1352 const content::MediaResponseCallback& callback) {
1353 if (delegate_)
1354 delegate_->RequestMediaAccessPermission(this, request, callback);
1355 else
1356 callback.Run(content::MediaStreamDevices());
1357}
1358
[email protected]b172aee2012-04-10 17:05:261359void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231360 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331361 if (delegate_)
1362 delegate_->UpdatePreferredSize(this, pref_size);
1363}
1364
[email protected]b172aee2012-04-10 17:05:261365void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341366 if (delegate_)
1367 delegate_->ResizeDueToAutoResize(this, new_size);
1368}
1369
[email protected]b172aee2012-04-10 17:05:261370WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201371 if (!delegate_)
1372 return NULL;
[email protected]00c37fc2011-08-02 00:22:501373
[email protected]e5d549d2011-12-28 01:29:201374 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1375 // Notify observers.
1376 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1377 DidOpenURL(params.url, params.referrer,
1378 params.disposition, params.transition));
1379 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341380}
1381
[email protected]b172aee2012-04-10 17:05:261382bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501383 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251384 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231385 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251386 reload_type);
[email protected]876bc832010-09-07 16:29:541387}
[email protected]96d185d2009-04-24 03:28:541388
[email protected]ba45bfd2012-05-22 21:51:441389void WebContentsImpl::RenderViewForInterstitialPageCreated(
1390 content::RenderViewHost* render_view_host) {
1391 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1392 RenderViewForInterstitialPageCreated(render_view_host));
1393}
1394
[email protected]b172aee2012-04-10 17:05:261395bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231396 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501397 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401398 // The renderer will reject IPC messages with URLs longer than
1399 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511400 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401401 return false;
1402
[email protected]9f76c1e2012-03-05 15:15:581403 RenderViewHostImpl* dest_render_view_host =
1404 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401405 if (!dest_render_view_host)
1406 return false; // Unable to create the desired render view host.
1407
[email protected]80a8fad2011-01-29 04:02:381408 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071409 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581410 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501411 WebUIControllerFactory* factory =
1412 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271413 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501414 bool is_allowed_in_web_ui_renderer =
1415 factory &&
[email protected]24e18252012-04-16 21:26:271416 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1417 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231418 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1419 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271420 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231421 content::GetContentClient()->SetActiveURL(entry.GetURL());
1422 CHECK(0);
1423 }
[email protected]54ec6472010-04-09 19:39:581424
[email protected]96d185d2009-04-24 03:28:541425 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441426 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521427 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441428 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511429 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541430
[email protected]7bb761892012-07-20 09:32:471431 // Notify observers that we will navigate in this RV.
1432 FOR_EACH_OBSERVER(WebContentsObserver,
1433 observers_,
1434 AboutToNavigateRenderView(dest_render_view_host));
1435
[email protected]96d185d2009-04-24 03:28:541436 // Used for page load time metrics.
1437 current_load_start_ = base::TimeTicks::Now();
1438
1439 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241440 std::string embedder_channel_name;
1441 int embedder_container_id;
1442 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1443 &embedder_channel_name,
1444 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341445 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271446 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241447 embedder_channel_name,
1448 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471449 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341450 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541451
[email protected]36fc0392011-12-25 03:59:511452 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541453 // HACK!! This code suppresses javascript: URLs from being added to
1454 // session history, which is what we want to do for javascript: URLs that
1455 // do not generate content. What we really need is a message from the
1456 // renderer telling us that a new page was not created. The same message
1457 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511458 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541459 return false;
1460 }
1461
[email protected]3c9e1872010-11-18 16:17:491462 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251463 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041464 observers_,
[email protected]36fc0392011-12-25 03:59:511465 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541466
[email protected]09b29342011-06-24 19:18:481467 if (delegate_)
1468 delegate_->DidNavigateToPendingEntry(this);
1469
[email protected]d5f942ba2008-09-26 19:30:341470 return true;
1471}
1472
[email protected]b172aee2012-04-10 17:05:261473void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331474 const SiteInstance* site_instance,
1475 int history_length,
1476 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411477 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1478 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191479 if (render_manager_.pending_render_view_host()) {
1480 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141481 return;
[email protected]9e1ad4b2011-08-14 16:49:191482 }
[email protected]9f76c1e2012-03-05 15:15:581483 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191484 if (!rvh) {
1485 NOTREACHED();
1486 return;
1487 }
[email protected]9f76c1e2012-03-05 15:15:581488 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191489 NOTREACHED();
1490 return;
1491 }
[email protected]9f76c1e2012-03-05 15:15:581492 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191493 history_length,
1494 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141495}
1496
[email protected]b172aee2012-04-10 17:05:261497void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271498 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541499 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1500 return;
1501 }
[email protected]9f76c1e2012-03-05 15:15:581502 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541503}
1504
[email protected]b172aee2012-04-10 17:05:261505bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271506 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541507}
1508
[email protected]b172aee2012-04-10 17:05:261509InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271510 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221511}
1512
[email protected]b172aee2012-04-10 17:05:261513bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161514 // WebKit creates Document object when MIME type is application/xhtml+xml,
1515 // so we also support this MIME type.
1516 return contents_mime_type_ == "text/html" ||
1517 contents_mime_type_ == "text/xml" ||
1518 contents_mime_type_ == "application/xhtml+xml" ||
1519 contents_mime_type_ == "text/plain" ||
1520 contents_mime_type_ == "text/css" ||
1521 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1522}
1523
[email protected]b172aee2012-04-10 17:05:261524void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591525 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161526 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481527 download_stats::RecordDownloadSource(
1528 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461529 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141530 return;
[email protected]c7dd2f62011-07-18 15:57:591531 }
1532
1533 Stop();
1534
1535 // Create the save package and possibly prompt the user for the name to save
1536 // the page as. The user prompt is an asynchronous operation that runs on
1537 // another thread.
1538 save_package_ = new SavePackage(this);
1539 save_package_->GetSaveInfo();
1540}
1541
1542// Used in automated testing to bypass prompting the user for file names.
1543// Instead, the names and paths are hard coded rather than running them through
1544// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261545bool WebContentsImpl::SavePage(const FilePath& main_file,
1546 const FilePath& dir_path,
1547 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591548 // Stop the page from navigating.
1549 Stop();
1550
1551 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271552 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591553}
1554
[email protected]b172aee2012-04-10 17:05:261555void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121556 const FilePath& file,
1557 const base::Callback<void(const FilePath&, int64)>& callback) {
1558 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1559}
1560
[email protected]b172aee2012-04-10 17:05:261561bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231562 NavigationEntryImpl* active_entry =
1563 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321564 return (active_entry != NULL &&
1565 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511566 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321567}
1568
[email protected]b172aee2012-04-10 17:05:261569const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271570 return contents_mime_type_;
1571}
1572
[email protected]b172aee2012-04-10 17:05:261573bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271574 return notify_disconnection_;
1575}
1576
[email protected]b172aee2012-04-10 17:05:261577void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311578 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581579 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1580 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311584 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581585 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1586 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161587}
1588
[email protected]b172aee2012-04-10 17:05:261589content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271590 return &renderer_preferences_;
1591}
1592
[email protected]b172aee2012-04-10 17:05:261593void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271594 new_tab_start_time_ = time;
1595}
1596
[email protected]b172aee2012-04-10 17:05:261597base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271598 return new_tab_start_time_;
1599}
1600
[email protected]e35ccd52012-05-23 16:22:471601void WebContentsImpl::Close() {
1602 Close(GetRenderViewHost());
1603}
1604
[email protected]b172aee2012-04-10 17:05:261605void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151606 if (close_start_time_.is_null())
1607 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011608}
1609
[email protected]b172aee2012-04-10 17:05:261610bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191611#if defined(OS_CHROMEOS)
1612 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1613 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511614 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201615 return false;
1616 return true;
[email protected]46624bf2010-06-09 16:04:191617#else
1618 return true;
1619#endif
1620}
1621
[email protected]b172aee2012-04-10 17:05:261622void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521623 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581624 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511625 if (delegate_)
1626 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341627}
1628
[email protected]e35ccd52012-05-23 16:22:471629void WebContentsImpl::UserGestureDone() {
1630 OnUserGesture();
1631}
1632
[email protected]b172aee2012-04-10 17:05:261633void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271634 closed_by_user_gesture_ = value;
1635}
1636
[email protected]b172aee2012-04-10 17:05:261637bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271638 return closed_by_user_gesture_;
1639}
1640
[email protected]b172aee2012-04-10 17:05:261641double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051642 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561643 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251644 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171645 return 0;
[email protected]b75b8292010-10-01 07:28:251646
1647 double zoom_level;
1648 if (temporary_zoom_settings_) {
1649 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581650 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251651 } else {
[email protected]2ae88d12011-10-14 09:11:191652 GURL url;
[email protected]10f417c52011-12-28 21:04:231653 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191654 // Since zoom map is updated using rewritten URL, use rewritten URL
1655 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511656 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191657 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251658 }
[email protected]d0b8d092010-10-25 04:05:171659 return zoom_level;
1660}
[email protected]b75b8292010-10-01 07:28:251661
[email protected]b172aee2012-04-10 17:05:261662int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1663 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171664 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011665 // Calculate the zoom percent from the factor. Round up to the nearest whole
1666 // number.
[email protected]b75b8292010-10-01 07:28:251667 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011668 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251669 *enable_decrement = percent > minimum_zoom_percent_;
1670 *enable_increment = percent < maximum_zoom_percent_;
1671 return percent;
1672}
1673
[email protected]b172aee2012-04-10 17:05:261674void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501675 if (!delegate_)
1676 return;
1677
[email protected]10f417c52011-12-28 21:04:231678 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501679 if (!active_entry)
1680 return;
1681
[email protected]36fc0392011-12-25 03:59:511682 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121683}
1684
[email protected]b172aee2012-04-10 17:05:261685void WebContentsImpl::ViewFrameSource(const GURL& url,
1686 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271687 if (!delegate_)
1688 return;
1689
1690 delegate_->ViewSourceForFrame(this, url, content_state);
1691}
1692
[email protected]b172aee2012-04-10 17:05:261693int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271694 return minimum_zoom_percent_;
1695}
1696
[email protected]b172aee2012-04-10 17:05:261697int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271698 return maximum_zoom_percent_;
1699}
1700
[email protected]b172aee2012-04-10 17:05:261701gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231702 return preferred_size_;
1703}
1704
[email protected]b172aee2012-04-10 17:05:261705int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271706 return content_restrictions_;
1707}
1708
[email protected]b172aee2012-04-10 17:05:261709WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501710 WebUIControllerFactory* factory =
1711 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1712 if (!factory)
1713 return WebUI::kNoWebUI;
1714 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271715}
1716
[email protected]b172aee2012-04-10 17:05:261717content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271718 // When there is a pending navigation entry, we want to use the pending WebUI
1719 // that goes along with it to control the basic flags. For example, we want to
1720 // show the pending URL in the URL bar, so we want the display_url flag to
1721 // be from the pending entry.
1722 //
1723 // The confusion comes because there are multiple possibilities for the
1724 // initial load in a tab as a side effect of the way the RenderViewHostManager
1725 // works.
1726 //
1727 // - For the very first tab the load looks "normal". The new tab Web UI is
1728 // the pending one, and we want it to apply here.
1729 //
1730 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1731 // get switched to the one previously associated with the new tab pages.
1732 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1733 // have a committed Web UI in this case.
1734 //
1735 // This condition handles all of these cases:
1736 //
1737 // - First load in first tab: no committed nav entry + pending nav entry +
1738 // pending dom ui:
1739 // -> Use pending Web UI if any.
1740 //
1741 // - First load in second tab: no committed nav entry + pending nav entry +
1742 // no pending Web UI:
1743 // -> Use the committed Web UI if any.
1744 //
1745 // - Second navigation in any tab: committed nav entry + pending nav entry:
1746 // -> Use pending Web UI if any.
1747 //
1748 // - Normal state with no load: committed nav entry + no pending nav entry:
1749 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251750 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271751 (controller_.GetLastCommittedEntry() ||
1752 render_manager_.pending_web_ui()))
1753 return render_manager_.pending_web_ui();
1754 return render_manager_.web_ui();
1755}
1756
[email protected]b172aee2012-04-10 17:05:261757bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271758 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581759 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271760}
1761
[email protected]b172aee2012-04-10 17:05:261762bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441763 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501764}
1765
[email protected]b172aee2012-04-10 17:05:261766void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321767 SkColor color) {
[email protected]da8543762012-03-20 08:52:201768 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1769 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1770}
1771
[email protected]b172aee2012-04-10 17:05:261772void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201773 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1774 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1775 if (delegate_)
1776 delegate_->DidEndColorChooser();
1777 color_chooser_ = NULL;
1778}
1779
[email protected]b172aee2012-04-10 17:05:261780bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471781 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271782 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221783 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231784 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411785 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271786}
1787
[email protected]b172aee2012-04-10 17:05:261788void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271789 if (delegate_)
1790 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211791}
1792
[email protected]3a3b75a2012-06-01 08:38:361793void WebContentsImpl::OnRegisterIntentService(
1794 const webkit_glue::WebIntentServiceData& data,
1795 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431796 if (delegate_)
1797 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301798}
1799
[email protected]b172aee2012-04-10 17:05:261800void WebContentsImpl::OnWebIntentDispatch(
1801 const webkit_glue::WebIntentData& intent,
1802 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431803 if (!delegate_)
1804 return;
1805
[email protected]0d9989d2011-12-21 20:26:001806 WebIntentsDispatcherImpl* intents_dispatcher =
1807 new WebIntentsDispatcherImpl(this, intent, intent_id);
1808 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301809}
1810
[email protected]54047eb52012-05-08 21:45:571811void WebContentsImpl::DidStartProvisionalLoadForFrame(
1812 content::RenderViewHost* render_view_host,
1813 int64 frame_id,
1814 bool is_main_frame,
1815 const GURL& opener_url,
1816 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281817 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181818 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451819 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571820 content::RenderProcessHost* render_process_host =
1821 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541822 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571823 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451824 false,
[email protected]9f76c1e2012-03-05 15:15:581825 &validated_url);
[email protected]ef108e72012-06-20 14:03:541826 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571827 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451828 true,
1829 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181830
[email protected]0d60f0192011-04-14 12:40:101831 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251832 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101833 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571834 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541835
1836 if (is_main_frame) {
1837 // Notify observers about the provisional change in the main frame URL.
1838 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1839 ProvisionalChangeToMainFrameUrl(validated_url,
1840 validated_opener_url,
1841 render_view_host));
1842 }
1843}
1844
1845void WebContentsImpl::DidRedirectProvisionalLoad(
1846 content::RenderViewHost* render_view_host,
1847 int32 page_id,
1848 const GURL& opener_url,
1849 const GURL& source_url,
1850 const GURL& target_url) {
1851 // TODO(creis): Remove this method and have the pre-rendering code listen to
1852 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1853 // instead. See http://crbug.com/78512.
1854 GURL validated_source_url(source_url);
1855 GURL validated_target_url(target_url);
1856 GURL validated_opener_url(opener_url);
1857 content::RenderProcessHost* render_process_host =
1858 render_view_host->GetProcess();
1859 RenderViewHostImpl::FilterURL(
1860 ChildProcessSecurityPolicyImpl::GetInstance(),
1861 render_process_host->GetID(),
1862 false,
1863 &validated_source_url);
1864 RenderViewHostImpl::FilterURL(
1865 ChildProcessSecurityPolicyImpl::GetInstance(),
1866 render_process_host->GetID(),
1867 false,
1868 &validated_target_url);
1869 RenderViewHostImpl::FilterURL(
1870 ChildProcessSecurityPolicyImpl::GetInstance(),
1871 render_process_host->GetID(),
1872 true,
1873 &validated_opener_url);
1874 NavigationEntry* entry;
1875 if (page_id == -1) {
1876 entry = controller_.GetPendingEntry();
1877 } else {
1878 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1879 page_id);
1880 }
1881 if (!entry || entry->GetURL() != validated_source_url)
1882 return;
1883
1884 // Notify observers about the provisional change in the main frame URL.
1885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1886 ProvisionalChangeToMainFrameUrl(validated_target_url,
1887 validated_opener_url,
1888 render_view_host));
[email protected]724159a2010-12-30 01:11:181889}
1890
[email protected]54047eb52012-05-08 21:45:571891void WebContentsImpl::DidFailProvisionalLoadWithError(
1892 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581893 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1894 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1895 << ", error_code: " << params.error_code
1896 << ", error_description: " << params.error_description
1897 << ", is_main_frame: " << params.is_main_frame
1898 << ", showing_repost_interstitial: " <<
1899 params.showing_repost_interstitial
1900 << ", frame_id: " << params.frame_id;
1901 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571902 content::RenderProcessHost* render_process_host =
1903 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541904 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571905 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451906 false,
[email protected]9f76c1e2012-03-05 15:15:581907 &validated_url);
[email protected]724159a2010-12-30 01:11:181908
[email protected]d7b175e2011-10-11 15:31:581909 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181910 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1911 // This means that the interstitial won't be torn down properly, which is
1912 // bad. But if we have an interstitial, go back to another tab type, and
1913 // then load the same interstitial again, we could end up getting the first
1914 // interstitial's "failed" message (as a result of the cancel) when we're on
1915 // the second one.
1916 //
1917 // We can't tell this apart, so we think we're tearing down the current page
1918 // which will cause a crash later one. There is also some code in
1919 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1920 // out because of this problem.
1921 //
1922 // http://code.google.com/p/chromium/issues/detail?id=2855
1923 // Because this will not tear down the interstitial properly, if "back" is
1924 // back to another tab type, the interstitial will still be somewhat alive
1925 // in the previous tab type. If you navigate somewhere that activates the
1926 // tab with the interstitial again, you'll see a flash before the new load
1927 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271928 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181929 LOG(WARNING) << "Discarding message during interstitial.";
1930 return;
1931 }
1932
[email protected]a16690732012-07-13 19:22:171933 // Do not clear the pending entry if one exists, so that the user's typed
1934 // URL is not lost when a navigation fails or is aborted. We'll allow
1935 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181936
[email protected]54047eb52012-05-08 21:45:571937 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181938 }
1939
[email protected]d8c660432011-12-22 20:51:251940 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581941 observers_,
1942 DidFailProvisionalLoad(params.frame_id,
1943 params.is_main_frame,
1944 validated_url,
1945 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461946 params.error_description,
1947 render_view_host));
[email protected]724159a2010-12-30 01:11:181948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181951 const GURL& url,
[email protected]70435962011-08-02 20:13:281952 const std::string& security_info,
1953 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181954 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281955 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191956 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181957 cache.Increment();
1958
1959 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081960 int cert_id = 0;
1961 net::CertStatus cert_status = 0;
1962 int security_bits = -1;
1963 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511964 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1965 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001966 content::LoadFromMemoryCacheDetails details(
1967 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1968 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181969
[email protected]ad50def52011-10-19 23:17:071970 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271971 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501972 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001973 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181974}
1975
[email protected]b172aee2012-04-10 17:05:261976void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381977 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181978 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201979 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181980}
1981
[email protected]b172aee2012-04-10 17:05:261982void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021983 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231984 LOG(INFO) << security_origin << " ran insecure content from "
1985 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381986 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411987 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1988 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181989 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411990 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201991 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181992}
1993
[email protected]b172aee2012-04-10 17:05:261994void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181995 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251996 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:471997 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:181998}
1999
[email protected]b172aee2012-04-10 17:05:262000void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312001 int64 frame_id,
2002 const GURL& validated_url,
2003 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252004 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472005 DidFinishLoad(frame_id, validated_url, is_main_frame,
2006 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312007}
2008
[email protected]b172aee2012-04-10 17:05:262009void WebContentsImpl::OnDidFailLoadWithError(
2010 int64 frame_id,
2011 const GURL& validated_url,
2012 bool is_main_frame,
2013 int error_code,
2014 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312016 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472017 error_code, error_description,
2018 message_source_));
[email protected]724159a2010-12-30 01:11:182019}
2020
[email protected]b172aee2012-04-10 17:05:262021void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272022 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432023 if (delegate_)
2024 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262028 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232029 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252030 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262031 if (!entry)
2032 return;
2033 // Note that we don't call NavigationController::GotToOffset() as we don't
2034 // want to create a pending navigation entry (it might end up lingering
2035 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252036 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582037 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512038 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582039 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472040 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572041
2042 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2043 // it in now that we know. This allows us to find the entry when it commits.
2044 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232045 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332046 entry->set_site_instance(
2047 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572048 }
[email protected]216813952011-05-19 22:21:262049 }
2050}
2051
[email protected]b172aee2012-04-10 17:05:262052void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2053 int maximum_percent,
2054 bool remember) {
[email protected]216813952011-05-19 22:21:262055 minimum_zoom_percent_ = minimum_percent;
2056 maximum_zoom_percent_ = maximum_percent;
2057 temporary_zoom_settings_ = !remember;
2058}
2059
[email protected]20b433a2012-05-15 21:23:462060void WebContentsImpl::OnSaveURL(const GURL& url,
2061 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482062 download_stats::RecordDownloadSource(
2063 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262064 // Check if the URL to save matches the URL of the main frame. Since this
2065 // message originates from Pepper plugins, it may not be the case if the
2066 // plugin is an embedded element.
2067 GURL main_frame_url = GetURL();
2068 if (!main_frame_url.is_valid())
2069 return;
2070 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462071 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272072}
2073
[email protected]b172aee2012-04-10 17:05:262074void WebContentsImpl::OnEnumerateDirectory(int request_id,
2075 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432076 if (!delegate_)
2077 return;
2078
[email protected]b9535422012-02-09 01:47:592079 ChildProcessSecurityPolicyImpl* policy =
2080 ChildProcessSecurityPolicyImpl::GetInstance();
2081 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2082 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432086 if (delegate_)
2087 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202088}
2089
[email protected]b172aee2012-04-10 17:05:262090void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2091 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362092 const string16& title,
2093 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432094 if (!delegate_)
2095 return;
2096
[email protected]b9535422012-02-09 01:47:592097 ChildProcessSecurityPolicyImpl* policy =
2098 ChildProcessSecurityPolicyImpl::GetInstance();
2099 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2100 return;
[email protected]3a3b75a2012-06-01 08:38:362101 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::OnFindReply(int request_id,
2105 int number_of_matches,
2106 const gfx::Rect& selection_rect,
2107 int active_match_ordinal,
2108 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432109 if (delegate_) {
2110 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2111 active_match_ordinal, final_update);
2112 }
2113
[email protected]4e6239c2011-09-23 00:11:002114 // Send a notification to the renderer that we are ready to receive more
2115 // results from the scoping effort of the Find operation. The FindInPage
2116 // scoping is asynchronous and periodically sends results back up to the
2117 // browser using IPC. In an effort to not spam the browser we have the
2118 // browser send an ACK for each FindReply message and have the renderer
2119 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582120 GetRenderViewHostImpl()->Send(
2121 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162122}
2123
[email protected]b172aee2012-04-10 17:05:262124void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442125 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2126 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452127}
2128
[email protected]b172aee2012-04-10 17:05:262129void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2130 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102131 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252132 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102133 AppCacheAccessed(manifest_url, blocked_by_policy));
2134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322137 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432138 color_chooser_ = delegate_ ?
2139 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202140}
2141
[email protected]b172aee2012-04-10 17:05:262142void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202143 if (color_chooser_ &&
2144 color_chooser_id == color_chooser_->identifier())
2145 color_chooser_->End();
2146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322149 SkColor color) {
[email protected]da8543762012-03-20 08:52:202150 if (color_chooser_ &&
2151 color_chooser_id == color_chooser_->identifier())
2152 color_chooser_->SetSelectedColor(color);
2153}
2154
[email protected]9f2a9d72012-04-16 16:02:222155void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2156 const FilePath& path,
2157 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442158 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2159 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292160}
2161
[email protected]d0759f492012-04-19 22:50:502162// This exists for render views that don't have a WebUI, but do have WebUI
2163// bindings enabled.
2164void WebContentsImpl::OnWebUISend(const GURL& source_url,
2165 const std::string& name,
2166 const base::ListValue& args) {
2167 if (delegate_)
2168 delegate_->WebUISend(this, source_url, name, args);
2169}
2170
[email protected]96d185d2009-04-24 03:28:542171// Notifies the RenderWidgetHost instance about the fact that the page is
2172// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262173void WebContentsImpl::SetIsLoading(bool is_loading,
2174 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542175 if (is_loading == is_loading_)
2176 return;
2177
2178 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212179 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542180 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562181 upload_size_ = 0;
2182 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542183 }
2184
2185 render_manager_.SetIsLoading(is_loading);
2186
2187 is_loading_ = is_loading;
2188 waiting_for_response_ = is_loading;
2189
[email protected]6ebdc9b2010-09-27 16:55:572190 if (delegate_)
2191 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462192 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542193
[email protected]432115822011-07-10 15:52:272194 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2195 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072196 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542197 if (details)
[email protected]6c2381d2011-10-19 02:52:532198 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072199 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502200 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542201 det);
2202}
2203
[email protected]b172aee2012-04-10 17:05:262204void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132205 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322206 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562207 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382208 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442209 // that opened the window, as long as both renderers have the same
2210 // privileges.
[email protected]1fd1a502011-03-30 16:55:562211 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562212 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582213 // web_ui might be NULL if the URL refers to a non-existent extension.
2214 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402215 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522216 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442217 }
2218 }
[email protected]1fd1a502011-03-30 16:55:562219 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442220 }
2221
[email protected]4e697b042011-07-08 06:44:562222 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322223 // Clear the status bubble. This is a workaround for a bug where WebKit
2224 // doesn't let us know that the cursor left an element during a
2225 // transition (this is also why the mouse cursor remains as a hand after
2226 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2227 // clear the bubble when a user navigates to a named anchor in the same
2228 // page.
[email protected]36fc0392011-12-25 03:59:512229 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322230 }
2231
[email protected]a6e82fc2010-02-24 22:28:142232 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472233 // Once the main frame is navigated, we're no longer considered to have
2234 // displayed insecure content.
2235 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172236 }
[email protected]ce5c4502009-05-06 16:46:112237
[email protected]3c9e1872010-11-18 16:17:492238 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252239 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042240 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322244 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132245 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322246 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062247 // If we navigate off the page, reset JavaScript state. This does nothing
2248 // to prevent a malicious script from spamming messages, since the script
2249 // could just reload the page to stop blocking.
2250 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552251 dialog_creator_->ResetJavaScriptState(this);
2252 dialog_creator_ = NULL;
2253 }
[email protected]420ae012009-04-24 05:16:322254
[email protected]3c9e1872010-11-18 16:17:492255 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252256 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042257 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462261 // If we are creating a RVH for a restored controller, then we need to make
2262 // sure the RenderView starts with a next_page_id_ larger than the number
2263 // of restored entries. This must be called before the RenderView starts
2264 // navigating (to avoid a race between the browser updating max_page_id and
2265 // the renderer updating next_page_id_). Because of this, we only call this
2266 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562267 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582268 if (max_restored_page_id >
2269 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2270 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2271 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322272}
2273
[email protected]b172aee2012-04-10 17:05:262274bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2275 const string16& title) {
[email protected]420ae012009-04-24 05:16:322276 // For file URLs without a title, use the pathname instead. In the case of a
2277 // synthesized title, we don't want the update to count toward the "one set
2278 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512279 string16 final_title;
[email protected]420ae012009-04-24 05:16:322280 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512281 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2282 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322283 explicit_set = false; // Don't count synthetic titles toward the set limit.
2284 } else {
[email protected]acafd272011-07-26 17:35:572285 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322286 explicit_set = true;
2287 }
2288
[email protected]987fc3a2011-05-26 14:18:092289 // If a page is created via window.open and never navigated,
2290 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552291 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092292 if (entry) {
[email protected]36fc0392011-12-25 03:59:512293 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092294 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322295
[email protected]36fc0392011-12-25 03:59:512296 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092297 } else {
2298 if (page_title_when_no_navigation_entry_ == final_title)
2299 return false; // Nothing changed, don't bother.
2300
2301 page_title_when_no_navigation_entry_ = final_title;
2302 }
[email protected]420ae012009-04-24 05:16:322303
[email protected]420ae012009-04-24 05:16:322304 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232305 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322306
[email protected]2bb171882012-03-07 02:09:462307 std::pair<content::NavigationEntry*, bool> details =
2308 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142309
[email protected]ad50def52011-10-19 23:17:072310 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442311 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2312 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462313 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042314
[email protected]420ae012009-04-24 05:16:322315 return true;
2316}
2317
[email protected]b172aee2012-04-10 17:05:262318void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322319 // After sending out a swap notification, we need to send a disconnect
2320 // notification so that clients that pick up a pointer to |this| can NULL the
2321 // pointer. See Bug 1230284.
2322 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072323 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202324 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2325 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072326 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322330 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072331 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122332 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2333 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072334 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322335}
2336
[email protected]b172aee2012-04-10 17:05:262337void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322338 if (!notify_disconnection_)
2339 return;
2340
2341 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072342 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322343 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
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]5a3bdf52012-05-24 15:12:572348RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2349 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322350}
2351
[email protected]8d3347f2009-07-09 22:00:212352RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262353WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212354 return &render_manager_;
2355}
2356
[email protected]b172aee2012-04-10 17:05:262357content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372358 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462359 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512360}
2361
[email protected]b172aee2012-04-10 17:05:262362WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172363 return this;
2364}
2365
[email protected]b172aee2012-04-10 17:05:262366gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172367 if (delegate_)
2368 return delegate_->GetRootWindowResizerRect();
2369 return gfx::Rect();
2370}
2371
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442373 // Don't send notifications if we are just creating a swapped-out RVH for
2374 // the opener chain. These won't be used for view-source or WebUI, so it's
2375 // ok to return early.
2376 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2377 return;
2378
[email protected]ad50def52011-10-19 23:17:072379 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302380 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322381 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532382 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232383 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322384 if (!entry)
2385 return;
2386
2387 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352388 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562389 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582390 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322391
2392 if (entry->IsViewSourceMode()) {
2393 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582394 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2395 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322396 }
[email protected]0666aef2009-05-13 19:48:082397
[email protected]d487beefe2011-12-21 05:41:212398 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262399
2400 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252401 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322402}
2403
[email protected]b172aee2012-04-10 17:05:262404void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522405 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322406 // Don't notify the world, since this came from a renderer in the
2407 // background.
2408 return;
2409 }
2410
2411 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312412 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232413 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302414
2415 // Restore the focus to the tab (otherwise the focus will be on the top
2416 // window).
[email protected]484ae5912010-09-29 19:16:142417 if (was_crashed && !FocusLocationBarByDefault() &&
2418 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302419 Focus();
[email protected]484ae5912010-09-29 19:16:142420 }
[email protected]32ded2212011-11-10 18:51:432421
[email protected]d8c660432011-12-22 20:51:252422 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322423}
2424
[email protected]b172aee2012-04-10 17:05:262425void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2426 base::TerminationStatus status,
2427 int error_code) {
[email protected]151a63d2011-12-20 22:32:522428 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322429 // The pending page's RenderViewHost is gone.
2430 return;
2431 }
2432
2433 SetIsLoading(false, NULL);
2434 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232435 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312436 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322437
[email protected]d8c660432011-12-22 20:51:252438 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272439 observers_,
[email protected]be1f56ab2011-12-22 06:55:312440 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322441}
2442
[email protected]b172aee2012-04-10 17:05:262443void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482444 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252445 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062446}
2447
[email protected]b172aee2012-04-10 17:05:262448void WebContentsImpl::DidNavigate(
2449 RenderViewHost* rvh,
2450 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582451 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322452 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372453
[email protected]434f69f2012-02-06 21:56:522454 // Update the site of the SiteInstance if it doesn't have one yet, unless
2455 // this is for about:blank. In that case, the SiteInstance can still be
2456 // considered unused until a navigation to a real page.
2457 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2458 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332459 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522460 }
[email protected]420ae012009-04-24 05:16:322461
2462 // Need to update MIME type here because it's referred to in
2463 // UpdateNavigationCommands() called by RendererDidNavigate() to
2464 // determine whether or not to enable the encoding menu.
2465 // It's updated only for the main frame. For a subframe,
2466 // RenderView::UpdateURL does not set params.contents_mime_type.
2467 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2468 // TODO(jungshik): Add a test for the encoding menu to avoid
2469 // regressing it again.
[email protected]2905f742011-10-13 03:51:582470 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322471 contents_mime_type_ = params.contents_mime_type;
2472
[email protected]8286f51a2011-05-31 17:39:132473 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002474 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392475
[email protected]a9c0bfe2010-09-17 08:35:222476 // Send notification about committed provisional loads. This notification is
2477 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2478 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082479 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072480 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2481 // that is not recorded in the navigation history. For the purpose of
2482 // tracking navigation events, we treat this event as a sub frame navigation
2483 // event.
2484 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582485 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222486 // Whether or not a page transition was triggered by going backward or
2487 // forward in the history is only stored in the navigation controller's
2488 // entry list.
2489 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512490 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582491 content::PAGE_TRANSITION_FORWARD_BACK)) {
2492 transition_type = content::PageTransitionFromInt(
2493 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222494 }
[email protected]0d60f0192011-04-14 12:40:102495 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252496 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102497 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462498 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222499 }
2500
[email protected]76543b92009-08-31 17:27:452501 if (!did_navigate)
2502 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322503
2504 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2505 // for the appropriate notification (best) or you can add it to
2506 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2507 // necessary, please).
2508
2509 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002510 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322511 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512512 if (delegate_)
2513 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002514 }
[email protected]420ae012009-04-24 05:16:322515 DidNavigateAnyFramePostCommit(rvh, details, params);
2516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2519 int32 page_id,
2520 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152521 // Ensure that this state update comes from either the active RVH or one of
2522 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522523 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322524
2525 // We must be prepared to handle state updates for any page, these occur
2526 // when the user is scrolling and entering form data, as well as when we're
2527 // leaving a page, in which case our state may have already been moved to
2528 // the next page. The navigation controller will look up the appropriate
2529 // NavigationEntry and update it when it is notified via the delegate.
2530
2531 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582532 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322533 if (entry_index < 0)
2534 return;
[email protected]10f417c52011-12-28 21:04:232535 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322536
[email protected]36fc0392011-12-25 03:59:512537 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322538 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512539 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322540 controller_.NotifyEntryChanged(entry, entry_index);
2541}
2542
[email protected]b172aee2012-04-10 17:05:262543void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2544 int32 page_id,
2545 const string16& title,
2546 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322547 // If we have a title, that's a pretty good indication that we've started
2548 // getting useful data.
2549 SetNotWaitingForResponse();
2550
[email protected]73eb2602012-02-09 19:50:552551 // Try to find the navigation entry, which might not be the current one.
2552 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232553 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582554 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092555
[email protected]73eb2602012-02-09 19:50:552556 // We can handle title updates when we don't have an entry in
2557 // UpdateTitleForEntry, but only if the update is from the current RVH.
2558 if (!entry && rvh != GetRenderViewHost())
2559 return;
2560
[email protected]a49e10b2011-08-01 23:57:462561 // TODO(evan): make use of title_direction.
2562 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092563 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322564 return;
2565
2566 // Broadcast notifications when the UI should be updated.
2567 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462568 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2572 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312573 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512577 if (delegate_)
2578 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322579}
2580
[email protected]b172aee2012-04-10 17:05:262581void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292582 // The UI may be in an event-tracking loop, such as between the
2583 // mouse-down and mouse-up in text selection or a button click.
2584 // Defer the close until after tracking is complete, so that we
2585 // don't free objects out from under the UI.
2586 // TODO(shess): This could probably be integrated with the
2587 // IsDoingDrag() test below. Punting for now because I need more
2588 // research to understand how this impacts platforms other than Mac.
2589 // TODO(shess): This could get more fine-grained. For instance,
2590 // closing a tab in another window while selecting text in the
2591 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212592 if (GetView()->IsEventTracking()) {
2593 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292594 return;
2595 }
2596
[email protected]24a4d1062009-07-10 23:10:422597 // If we close the tab while we're in the middle of a drag, we'll crash.
2598 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212599 if (GetView()->IsDoingDrag()) {
2600 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422601 return;
2602 }
2603
[email protected]420ae012009-04-24 05:16:322604 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522605 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512606 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522610 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512611 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572612}
2613
[email protected]b172aee2012-04-10 17:05:262614void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512615 if (delegate_ && delegate_->IsPopupOrPanel(this))
2616 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322617}
2618
[email protected]89793072012-07-23 22:25:292619void WebContentsImpl::DidStartLoading(
2620 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322621 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492622
[email protected]82114f52012-03-20 22:53:412623 if (delegate_ && content_restrictions_)
2624 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492625
2626 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2628 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322629}
2630
[email protected]89793072012-07-23 22:25:292631void WebContentsImpl::DidStopLoading(
2632 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322633 scoped_ptr<LoadNotificationDetails> details;
2634
[email protected]10f417c52011-12-28 21:04:232635 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322636 // An entry may not exist for a stop when loading an initial blank page or
2637 // if an iframe injected by script into a blank page finishes loading.
2638 if (entry) {
[email protected]420ae012009-04-24 05:16:322639 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2640
2641 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512642 entry->GetVirtualURL(),
2643 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322644 elapsed,
2645 &controller_,
2646 controller_.GetCurrentEntryIndex()));
2647 }
2648
[email protected]420ae012009-04-24 05:16:322649 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492650
2651 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292652 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2653 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322654}
2655
[email protected]b172aee2012-04-10 17:05:262656void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162657 controller_.DiscardNonCommittedEntries();
2658
2659 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462660 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162661}
2662
[email protected]b172aee2012-04-10 17:05:262663void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512664 if (delegate_)
2665 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402666}
2667
[email protected]87717d0e2012-04-26 02:58:432668void WebContentsImpl::DocumentAvailableInMainFrame(
2669 RenderViewHost* render_view_host) {
2670 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2671 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102672}
2673
[email protected]b172aee2012-04-10 17:05:262674void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082675 RenderViewHost* render_view_host,
2676 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072677 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272678 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322679 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532680 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082681}
2682
[email protected]196159d2012-05-04 17:26:542683void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2684 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262685 const content::Referrer& referrer,
2686 WindowOpenDisposition disposition,
2687 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542688 // If this came from a swapped out RenderViewHost, we only allow the request
2689 // if we are still in the same BrowsingInstance.
2690 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2691 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2692 return;
2693 }
2694
[email protected]4ad5d77d2011-12-03 02:00:482695 // Delegate to RequestTransferURL because this is just the generic
2696 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582697 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482698 GlobalRequestID());
2699}
2700
[email protected]b172aee2012-04-10 17:05:262701void WebContentsImpl::RequestTransferURL(
2702 const GURL& url,
2703 const content::Referrer& referrer,
2704 WindowOpenDisposition disposition,
2705 int64 source_frame_id,
2706 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202707 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582708 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582709 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352710 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322711 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2712 // generated suggestions).
2713 //
[email protected]e0112912011-02-02 22:54:352714 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162715 // want web sites to see a referrer of "chrome://blah" (and some
2716 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322717 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432718 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222719 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482720 false /* is_renderer_initiated */);
2721 params.transferred_global_request_id = old_request_id;
2722 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222723 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322724 } else {
[email protected]6bf6a6b52012-02-03 15:41:432725 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482726 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2727 params.transferred_global_request_id = old_request_id;
2728 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582729 }
2730 if (new_contents) {
2731 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252732 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582733 DidOpenRequestedURL(new_contents,
2734 url,
2735 referrer,
2736 disposition,
2737 transition_type,
2738 source_frame_id));
[email protected]420ae012009-04-24 05:16:322739 }
2740}
2741
[email protected]e1c3a552012-05-04 20:51:322742void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2743 // Tell the active RenderViewHost to run unload handlers and close, as long
2744 // as the request came from a RenderViewHost in the same BrowsingInstance.
2745 // In most cases, we receive this from a swapped out RenderViewHost.
2746 // It is possible to receive it from one that has just been swapped in,
2747 // in which case we might as well deliver the message anyway.
2748 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2749 GetRenderViewHost()->ClosePage();
2750}
2751
[email protected]f546640b2012-05-15 00:03:492752void WebContentsImpl::RouteMessageEvent(
2753 RenderViewHost* rvh,
2754 const ViewMsg_PostMessage_Params& params) {
2755 // Only deliver the message to the active RenderViewHost if the request
2756 // came from a RenderViewHost in the same BrowsingInstance.
2757 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2758 return;
2759
2760 ViewMsg_PostMessage_Params new_params(params);
2761
2762 // If there is a source_routing_id, translate it to the routing ID for
2763 // the equivalent swapped out RVH in the target process. If we need
2764 // to create a swapped out RVH for the source tab, we create its opener
2765 // chain as well, since those will also be accessible to the target page.
2766 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2767 // Try to look up the WebContents for the source page.
2768 WebContentsImpl* source_contents = NULL;
2769 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2770 rvh->GetProcess()->GetID(), params.source_routing_id);
2771 if (source_rvh) {
2772 source_contents = static_cast<WebContentsImpl*>(
2773 source_rvh->GetDelegate()->GetAsWebContents());
2774 }
2775
2776 if (source_contents) {
2777 new_params.source_routing_id =
2778 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2779 } else {
2780 // We couldn't find it, so don't pass a source frame.
2781 new_params.source_routing_id = MSG_ROUTING_NONE;
2782 }
2783 }
2784
2785 // In most cases, we receive this from a swapped out RenderViewHost.
2786 // It is possible to receive it from one that has just been swapped in,
2787 // in which case we might as well deliver the message anyway.
2788 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2789 GetRenderViewHost()->GetRoutingID(), new_params));
2790}
2791
[email protected]b172aee2012-04-10 17:05:262792void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342793 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412794 const string16& message,
2795 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322796 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142797 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322798 IPC::Message* reply_msg,
2799 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072800 // Suppress JavaScript dialogs when requested. Also suppress messages when
2801 // showing an interstitial as it's shown over the previous page and we don't
2802 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502803 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582804 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272805 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072806 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522807 delegate_->ShouldSuppressDialogs() ||
2808 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322809
2810 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432811 std::string accept_lang = content::GetContentClient()->browser()->
2812 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552813 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522814 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432815 this,
2816 frame_url.GetOrigin(),
2817 accept_lang,
2818 javascript_message_type,
2819 message,
[email protected]51da7e32012-01-30 19:24:522820 default_prompt,
[email protected]b172aee2012-04-10 17:05:262821 base::Bind(&WebContentsImpl::OnDialogClosed,
2822 base::Unretained(this),
2823 rvh,
2824 reply_msg),
[email protected]51da7e32012-01-30 19:24:522825 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322826 }
[email protected]3ab9cb82011-06-03 18:02:072827
2828 if (suppress_this_message) {
2829 // If we are suppressing messages, just reply as if the user immediately
2830 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342831 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072832 }
2833
2834 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2838 const string16& message,
2839 bool is_reload,
2840 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582841 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512842 if (delegate_)
2843 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072844
2845 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582846 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072847 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522848 delegate_->ShouldSuppressDialogs() ||
2849 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152850 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342851 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582852 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502853 return;
2854 }
[email protected]3ab9cb82011-06-03 18:02:072855
[email protected]7ab1e7d62009-10-14 23:32:012856 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552857 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522858 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322859 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262860 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522861 reply_msg));
[email protected]420ae012009-04-24 05:16:322862}
2863
[email protected]a796f202012-05-30 14:14:252864bool WebContentsImpl::AddMessageToConsole(int32 level,
2865 const string16& message,
2866 int32 line_no,
2867 const string16& source_id) {
2868 if (!delegate_)
2869 return false;
2870 return delegate_->AddMessageToConsole(this, level, message, line_no,
2871 source_id);
2872}
2873
[email protected]b172aee2012-04-10 17:05:262874WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332875 // We want to base the page config off of the real URL, rather than the
2876 // display URL.
2877 GURL url = controller_.GetActiveEntry()
2878 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2879 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322880}
2881
[email protected]b172aee2012-04-10 17:05:262882void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272883 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252884 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222885
[email protected]ea114722012-03-12 01:11:252886 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172887 if (rdh) // NULL in unittests.
2888 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252889}
2890
[email protected]b172aee2012-04-10 17:05:262891void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442892 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252893 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442894}
2895
[email protected]b172aee2012-04-10 17:05:262896void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2897 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152898 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522899 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152900 return;
2901
[email protected]9f76c1e2012-03-05 15:15:582902 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2903
[email protected]e5fc1632011-08-08 07:51:532904 // Ignore renderer unresponsive event if debugger is attached to the tab
2905 // since the event may be a result of the renderer sitting on a breakpoint.
2906 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442907 DevToolsAgentHost* agent =
2908 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2909 if (agent &&
2910 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532911 return;
2912
[email protected]420ae012009-04-24 05:16:322913 if (is_during_unload) {
2914 // Hang occurred while firing the beforeunload/unload handler.
2915 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582916 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322917
2918 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2919 return;
2920
2921 // If the tab hangs in the beforeunload/unload handler there's really
2922 // nothing we can do to recover. Pretend the unload listeners have
2923 // all fired and close the tab. If the hang is in the beforeunload handler
2924 // then the user will not have the option of cancelling the close.
2925 Close(rvh);
2926 return;
2927 }
2928
[email protected]9f76c1e2012-03-05 15:15:582929 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472930 return;
2931
[email protected]6934a702011-12-20 00:04:512932 if (delegate_)
2933 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322934}
2935
[email protected]b172aee2012-04-10 17:05:262936void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512937 if (delegate_)
2938 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322939}
2940
[email protected]b172aee2012-04-10 17:05:262941void WebContentsImpl::LoadStateChanged(
2942 const GURL& url,
2943 const net::LoadStateWithParam& load_state,
2944 uint64 upload_position,
2945 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322946 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562947 upload_position_ = upload_position;
2948 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502949 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202950 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302951 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212952 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322953 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462954 if (IsLoading()) {
2955 NotifyNavigationStateChanged(
2956 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2957 }
[email protected]420ae012009-04-24 05:16:322958}
2959
[email protected]b172aee2012-04-10 17:05:262960void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512961 if (delegate_)
2962 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252963}
2964
[email protected]b172aee2012-04-10 17:05:262965void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322966 bool proceed,
2967 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512968 if (delegate_)
2969 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322970}
2971
[email protected]b172aee2012-04-10 17:05:262972void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542973 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232974 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2975 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542976}
2977
[email protected]b172aee2012-04-10 17:05:262978void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102979 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262980 gfx::Size size = view_->GetContainerSize();
2981 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2982 // here during container initialization and normal window size will be set
2983 // later. In case of tab duplication this resizing to 0x0 prevents setting
2984 // normal size later so just ignore it.
2985 if (!size.IsEmpty())
2986 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322987}
2988
[email protected]b172aee2012-04-10 17:05:262989void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542990 NotifySwapped();
2991}
2992
[email protected]14392a52012-05-02 20:28:442993int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2994 SiteInstance* instance) {
2995 if (!opener_)
2996 return MSG_ROUTING_NONE;
2997
2998 // Recursively create RenderViews for anything else in the opener chain.
2999 return opener_->CreateOpenerRenderViews(instance);
3000}
3001
3002int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3003 int opener_route_id = MSG_ROUTING_NONE;
3004
3005 // If this tab has an opener, ensure it has a RenderView in the given
3006 // SiteInstance as well.
3007 if (opener_)
3008 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3009
3010 // Create a swapped out RenderView in the given SiteInstance if none exists,
3011 // setting its opener to the given route_id. Return the new view's route_id.
3012 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:203016 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:543017}
3018
[email protected]b172aee2012-04-10 17:05:263019WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563020 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323021}
3022
[email protected]10f417c52011-12-28 21:04:233023NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263024 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323025 return controller_.GetLastCommittedEntry();
3026}
3027
[email protected]b172aee2012-04-10 17:05:263028bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443029 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443030 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323031 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523032
[email protected]420ae012009-04-24 05:16:323033 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443034 if (rwh_view)
3035 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323036
[email protected]74ce1ad2011-12-16 21:51:463037 // Make sure we use the correct starting page_id in the new RenderView.
3038 UpdateMaxPageIDIfNecessary(render_view_host);
3039 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583040 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463041
[email protected]7900bfdb2012-05-24 19:31:243042 std::string embedder_channel_name;
3043 int embedder_container_id;
3044 GetBrowserPluginEmbedderInfo(render_view_host,
3045 &embedder_channel_name,
3046 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583047 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493048 render_view_host)->CreateRenderView(string16(),
3049 opener_route_id,
3050 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243051 embedder_channel_name,
3052 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523053 return false;
[email protected]14392a52012-05-02 20:28:443054 }
[email protected]a4127722011-04-27 23:13:523055
[email protected]e60c0232011-11-11 19:56:353056#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503057 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3058 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443059 if (rwh_view) {
3060 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3061 render_widget_host->WasResized();
3062 }
[email protected]f8233cc2011-05-31 20:24:503063#endif
3064
[email protected]420ae012009-04-24 05:16:323065 return true;
3066}
3067
[email protected]b172aee2012-04-10 17:05:263068void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3069 IPC::Message* reply_msg,
3070 bool success,
3071 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543072 if (is_showing_before_unload_dialog_ && !success) {
3073 // If a beforeunload dialog is canceled, we need to stop the throbber from
3074 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293075 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353076 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543077
[email protected]3bbacc5b2012-04-17 17:46:153078 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543079 }
3080 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583081 static_cast<RenderViewHostImpl*>(
3082 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543083}
3084
[email protected]b172aee2012-04-10 17:05:263085void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123086 encoding_ = content::GetContentClient()->browser()->
3087 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103088}
[email protected]f45d2a72010-03-08 23:28:353089
[email protected]b172aee2012-04-10 17:05:263090void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463091 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263092 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573093 DownloadManager* dlm =
3094 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143095 if (!dlm)
3096 return;
3097 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263098 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143099 const NavigationEntry* entry = controller_.GetActiveEntry();
3100 if (entry)
3101 post_id = entry->GetPostID();
3102 }
[email protected]29a5ffc82012-03-13 19:35:583103 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143104 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143105 scoped_ptr<DownloadUrlParameters> params(
3106 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493107 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143108 params->set_post_id(post_id);
3109 params->set_prefer_cache(true);
3110 if (post_id >= 0)
3111 params->set_method("POST");
3112 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143113}
3114
[email protected]b172aee2012-04-10 17:05:263115void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213116 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443117 // Can be NULL during tests.
3118 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213119 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363120}
[email protected]9f76c1e2012-03-05 15:15:583121
[email protected]b172aee2012-04-10 17:05:263122RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583123 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3124}
[email protected]7900bfdb2012-05-24 19:31:243125
3126void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3127 content::RenderViewHost* render_view_host,
3128 std::string* embedder_channel_name,
3129 int* embedder_container_id) {
3130 content::RenderProcessHost* embedder_render_process_host =
3131 browser_plugin_host()->embedder_render_process_host();
3132 *embedder_container_id = browser_plugin_host()->instance_id();
3133 int embedder_process_id =
3134 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3135 if (embedder_process_id != -1) {
3136 *embedder_channel_name =
3137 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3138 embedder_process_id);
3139 }
3140}