blob: c077141da592cd1dfa10f67fda809fb462f64908 [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]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]172cf712012-05-23 15:07:3917#include "content/browser/browser_plugin/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.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]09d31d52012-03-11 22:30:2750#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0051#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3752#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1453#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3254#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3855#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4256#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2557#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1058#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5059#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2160#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4861#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1862#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5463#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0364#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1665#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2966#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5467#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3468#include "net/url_request/url_request_context_getter.h"
[email protected]302fe422012-06-11 14:49:1169#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3770#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5671#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4172#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0173#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4174#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2475#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3676#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3177#include "webkit/glue/webpreferences.h"
78
[email protected]f66df822012-05-18 16:52:1779#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5080#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5782#endif
[email protected]3e45ba92009-02-20 21:09:0083
[email protected]420ae012009-04-24 05:16:3284// Cross-Site Navigations
85//
[email protected]b172aee2012-04-10 17:05:2686// If a WebContentsImpl is told to navigate to a different web site (as
87// determined by SiteInstance), it will replace its current RenderViewHost with
88// a new RenderViewHost dedicated to the new SiteInstance. This works as
89// follows:
[email protected]420ae012009-04-24 05:16:3290//
91// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4692// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3293// - The pending RVH is "suspended," so that no navigation messages are sent to
94// its renderer until the onbeforeunload JavaScript handler has a chance to
95// run in the current RVH.
96// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
97// that it has a pending cross-site request. ResourceDispatcherHost will
98// check for this when the response arrives.
99// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46100// cancel all the pending logic. Otherwise we allow the pending RVH to send
101// the navigation request to its renderer.
102// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
103// main resource load on the pending RVH. It checks CrossSiteRequestManager
104// to see that it is a cross-site request, and installs a
105// CrossSiteResourceHandler.
106// - When RDH receives a response, the BufferedResourceHandler determines
107// whether it is a download. If so, it sends a message to the new renderer
108// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26109// pending RVH remains until the next DidNavigate event for this
110// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32111// - After RDH receives a response and determines that it is safe and not a
112// download, it pauses the response to first run the old page's onunload
113// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26114// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32115// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15116// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32117// the ResourceDispatcherHost, who unpauses the response. Data is then sent
118// to the pending RVH.
119// - The pending renderer sends a FrameNavigate message that invokes the
120// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46121// pending RVH.
[email protected]992db4c2011-05-12 15:37:15122// - The previous renderer is kept swapped out in RenderViewHostManager in case
123// the user goes back. The process only stays live if another tab is using
124// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32125
[email protected]b441a8492012-06-06 14:55:57126using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44127using content::DevToolsAgentHost;
128using content::DevToolsAgentHostRegistry;
129using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17130using content::DownloadItem;
131using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14132using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20133using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56134using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13135using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27136using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54137using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50138using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23139using content::NavigationEntry;
140using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20141using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11142using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57143using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57144using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27145using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11146using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50147using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58148using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04149using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25150using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14151using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43152using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33153using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38154using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09155using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25156using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56157using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22158using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50159using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25160using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44161
[email protected]420ae012009-04-24 05:16:32162namespace {
163
164// Amount of time we wait between when a key event is received and the renderer
165// is queried for its state and pushed to the NavigationEntry.
166const int kQueryStateDelay = 5000;
167
[email protected]6ebdc9b2010-09-27 16:55:57168const int kSyncWaitDelay = 40;
169
[email protected]82114f52012-03-20 22:53:41170const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05171
[email protected]420ae012009-04-24 05:16:32172#if defined(OS_WIN)
173
174BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
175 // Note: erase is required to properly paint some widgets borders. This can
176 // be seen with textfields.
177 InvalidateRect(hwnd, NULL, TRUE);
178 return TRUE;
179}
180#endif
181
[email protected]2c5569662011-03-22 20:45:02182ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23183 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50184 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16185 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47186 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47190 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16191 break; // Fall through to rest of function.
192 }
[email protected]5e369672009-11-03 23:48:30193
[email protected]59246c572012-02-10 13:32:13194 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
195 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23196 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13197 browser_context->DidLastSessionExitCleanly()) {
198 if (entry.GetHasPostData())
199 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02200 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13201 }
[email protected]5e369672009-11-03 23:48:30202
[email protected]2c5569662011-03-22 20:45:02203 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30204}
205
[email protected]10f417c52011-12-28 21:04:23206void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47207 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42208 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50209 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24210 const std::string& embedder_channel_name,
211 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16212 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51213 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54214 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55215 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
216 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51217 params->url = entry.GetURL();
218 params->referrer = entry.GetReferrer();
219 params->transition = entry.GetTransitionType();
220 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00221 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55222 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34223 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47224 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48225 params->transferred_request_child_id =
226 entry.transferred_global_request_id().child_id;
227 params->transferred_request_request_id =
228 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00229 // Avoid downloading when in view-source mode.
230 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24231 params->embedder_channel_name = embedder_channel_name;
232 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47233
234 if (delegate)
235 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34236}
237
[email protected]f98f5092012-05-19 00:08:14238int GetSwitchValueAsInt(
239 const CommandLine& command_line,
240 const std::string& switch_string,
241 int min_value) {
242 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
243 int int_value;
244 if (base::StringToInt(string_value, &int_value))
245 return std::max(min_value, int_value);
246 else
247 return min_value;
248}
249
[email protected]420ae012009-04-24 05:16:32250} // namespace
251
[email protected]a81343d232011-12-27 07:39:20252namespace content {
253
254WebContents* WebContents::Create(
255 BrowserContext* browser_context,
256 SiteInstance* site_instance,
257 int routing_id,
[email protected]b172aee2012-04-10 17:05:26258 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20259 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26260 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43261 browser_context,
262 site_instance,
263 routing_id,
[email protected]b172aee2012-04-10 17:05:26264 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44265 NULL,
[email protected]adbfb8df2012-02-24 01:19:43266 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20267}
[email protected]746d3052012-05-22 15:15:47268
[email protected]299d7f12012-05-23 05:31:15269WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47270 return rvh->GetDelegate()->GetAsWebContents();
271}
272
[email protected]a81343d232011-12-27 07:39:20273}
[email protected]f4f50ef2011-01-21 19:01:19274
[email protected]b172aee2012-04-10 17:05:26275// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32276
[email protected]b172aee2012-04-10 17:05:26277WebContentsImpl::WebContentsImpl(
278 content::BrowserContext* browser_context,
279 SiteInstance* site_instance,
280 int routing_id,
281 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44282 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26283 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42284 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07285 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37286 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57287 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44288 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05289 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34290 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23291 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
292 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34293 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21294 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56295 upload_size_(0),
296 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47297 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57298 capturing_contents_(false),
299 is_being_destroyed_(false),
300 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55301 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57302#if defined(OS_WIN)
303 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
304#endif
[email protected]7ab1e7d62009-10-14 23:32:01305 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56306 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38307 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25308 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01309 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25310 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01311 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00312 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43313 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20314 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37315 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32316
[email protected]38b098f2012-03-14 21:11:57317 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57318 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
319 if (view_.get()) {
320 CHECK(render_view_host_delegate_view_);
321 } else {
[email protected]38b098f2012-03-14 21:11:57322 content::WebContentsViewDelegate* delegate =
323 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
324 this);
[email protected]5a3bdf52012-05-24 15:12:57325 view_.reset(CreateWebContentsView(
326 this, delegate, &render_view_host_delegate_view_));
327 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57328 }
329 CHECK(view_.get());
330
[email protected]ca13a442012-04-17 14:00:12331 // We have the initial size of the view be based on the size of the view of
332 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26333 view_->CreateView(base_web_contents ?
334 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00335
[email protected]14392a52012-05-02 20:28:44336 // Listen for whether our opener gets destroyed.
337 if (opener_) {
338 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
339 content::Source<WebContents>(opener_));
340 }
341
[email protected]bafe6cd2012-05-23 23:09:50342 registrar_.Add(this,
343 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
344 content::NotificationService::AllBrowserContextsAndSources());
345
[email protected]483623eb2011-10-25 09:30:00346#if defined(ENABLE_JAVA_BRIDGE)
347 java_bridge_dispatcher_host_manager_.reset(
348 new JavaBridgeDispatcherHostManager(this));
349#endif
[email protected]172cf712012-05-23 15:07:39350
351 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35352}
initial.commit09911bf2008-07-26 23:55:29353
[email protected]b172aee2012-04-10 17:05:26354WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32355 is_being_destroyed_ = true;
356
[email protected]3ab9cb82011-06-03 18:02:07357 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55358 if (dialog_creator_)
359 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07360
[email protected]da8543762012-03-20 08:52:20361 if (color_chooser_)
362 color_chooser_->End();
363
[email protected]420ae012009-04-24 05:16:32364 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32365
[email protected]ca13a442012-04-17 14:00:12366 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07367 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09368 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
369 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07370 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32371
372 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07373#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32374 // If we still have a window handle, destroy it. GetNativeView can return
375 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42376 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52377 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58378 if (host && host->GetView())
379 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42380 }
[email protected]420ae012009-04-24 05:16:32381#endif
[email protected]7ab1e7d62009-10-14 23:32:01382
383 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15384 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01385 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15386 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01387 }
[email protected]b5a1d11c2011-02-17 03:09:42388
[email protected]2db9bd72012-04-13 20:20:56389 FOR_EACH_OBSERVER(WebContentsObserver,
390 observers_,
391 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08392
[email protected]6934a702011-12-20 00:04:51393 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42394}
395
[email protected]b172aee2012-04-10 17:05:26396WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
397 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54398 WebPreferences prefs;
399
400 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
401
402 prefs.developer_extras_enabled = true;
403 prefs.javascript_enabled =
404 !command_line.HasSwitch(switches::kDisableJavaScript);
405 prefs.web_security_enabled =
406 !command_line.HasSwitch(switches::kDisableWebSecurity);
407 prefs.plugins_enabled =
408 !command_line.HasSwitch(switches::kDisablePlugins);
409 prefs.java_enabled =
410 !command_line.HasSwitch(switches::kDisableJava);
411
412 prefs.uses_page_cache =
413 command_line.HasSwitch(switches::kEnableFastback);
414 prefs.remote_fonts_enabled =
415 !command_line.HasSwitch(switches::kDisableRemoteFonts);
416 prefs.xss_auditor_enabled =
417 !command_line.HasSwitch(switches::kDisableXSSAuditor);
418 prefs.application_cache_enabled =
419 !command_line.HasSwitch(switches::kDisableApplicationCache);
420
421 prefs.local_storage_enabled =
422 !command_line.HasSwitch(switches::kDisableLocalStorage);
423 prefs.databases_enabled =
424 !command_line.HasSwitch(switches::kDisableDatabases);
425 prefs.webaudio_enabled =
426 !command_line.HasSwitch(switches::kDisableWebAudio);
427
428 prefs.experimental_webgl_enabled =
429 GpuProcessHost::gpu_enabled() &&
430 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
431 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
432
[email protected]5a073092012-06-08 00:42:51433 prefs.flash_3d_enabled =
434 GpuProcessHost::gpu_enabled() &&
435 !command_line.HasSwitch(switches::kDisableFlash3d);
436 prefs.flash_stage3d_enabled =
437 GpuProcessHost::gpu_enabled() &&
438 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19439
[email protected]64d69de42012-02-06 00:19:54440 prefs.gl_multisampling_enabled =
441 !command_line.HasSwitch(switches::kDisableGLMultisampling);
442 prefs.privileged_webgl_extensions_enabled =
443 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
444 prefs.site_specific_quirks_enabled =
445 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
446 prefs.allow_file_access_from_file_urls =
447 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
448 prefs.show_composited_layer_borders =
449 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
450 prefs.show_composited_layer_tree =
451 command_line.HasSwitch(switches::kShowCompositedLayerTree);
452 prefs.show_fps_counter =
453 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19454 prefs.show_paint_rects =
455 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54456 prefs.accelerated_compositing_enabled =
457 GpuProcessHost::gpu_enabled() &&
458 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54459 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23460 command_line.HasSwitch(switches::kForceCompositingMode) &&
461 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54462 prefs.fixed_position_compositing_enabled =
463 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
464 prefs.accelerated_2d_canvas_enabled =
465 GpuProcessHost::gpu_enabled() &&
466 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58467 prefs.deferred_2d_canvas_enabled =
[email protected]00bbad22012-05-25 13:24:17468 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54469 prefs.accelerated_painting_enabled =
470 GpuProcessHost::gpu_enabled() &&
471 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
472 prefs.accelerated_filters_enabled =
473 GpuProcessHost::gpu_enabled() &&
474 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
475 prefs.accelerated_layers_enabled =
476 prefs.accelerated_animation_enabled =
477 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54478 prefs.accelerated_plugins_enabled =
479 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
480 prefs.accelerated_video_enabled =
481 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54482 prefs.interactive_form_validation_enabled =
483 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
484 prefs.fullscreen_enabled =
485 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16486 prefs.css_regions_enabled =
487 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29488 prefs.css_shaders_enabled =
489 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]a08412b62012-05-29 21:28:56490 prefs.device_supports_touch =
491 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]64d69de42012-02-06 00:19:54492
493#if defined(OS_MACOSX)
494 bool default_enable_scroll_animator = true;
495#else
496 // On CrOS, the launcher always passes in the --enable flag.
497 bool default_enable_scroll_animator = false;
498#endif
499 prefs.enable_scroll_animator = default_enable_scroll_animator;
500 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
501 prefs.enable_scroll_animator = true;
502 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
503 prefs.enable_scroll_animator = false;
504
505 prefs.visual_word_movement_enabled =
506 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54507
508 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32509 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54510 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11511 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
512 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54513 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11514 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54515 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19516 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
517 prefs.flash_3d_enabled = false;
518 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
519 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11520 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54521 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11522 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54523 prefs.gl_multisampling_enabled = false;
524
525 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45526 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32527 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54528 prefs.accelerated_video_enabled = false;
529 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45530 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09531 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54532 }
533 }
534
[email protected]b9535422012-02-09 01:47:59535 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58536 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54537 prefs.loads_images_automatically = true;
538 prefs.javascript_enabled = true;
539 }
540
541 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
542
543 // Force accelerated compositing and 2d canvas off for chrome:, about: and
544 // chrome-devtools: pages (unless it's specifically allowed).
545 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54546 url.SchemeIs(chrome::kChromeUIScheme) ||
547 (url.SchemeIs(chrome::kAboutScheme) &&
548 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25549 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54550 prefs.accelerated_compositing_enabled = false;
551 prefs.accelerated_2d_canvas_enabled = false;
552 }
[email protected]43d9d782012-03-01 15:40:09553
[email protected]302fe422012-06-11 14:49:11554#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
555 prefs.threaded_animation_enabled =
556 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
557 prefs.per_tile_painting_enabled =
558 command_line.HasSwitch(switches::kEnablePerTilePainting);
559 prefs.partial_swap_enabled =
560 command_line.HasSwitch(switches::kEnablePartialSwap);
561#endif
562
[email protected]f98f5092012-05-19 00:08:14563 if (command_line.HasSwitch(switches::kDefaultTileWidth))
564 prefs.default_tile_width =
565 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
566 if (command_line.HasSwitch(switches::kDefaultTileHeight))
567 prefs.default_tile_height =
568 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
569 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
570 prefs.max_untiled_layer_width =
571 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
572 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
573 prefs.max_untiled_layer_height =
574 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
575
[email protected]2486dce2012-05-23 17:18:19576 if (gfx::Screen::IsDIPEnabled()) {
577 // Only apply when using DIP coordinate system as this setting interferes
578 // with fixed layout mode.
579 prefs.apply_default_device_scale_factor_in_compositor = true;
580 }
581
[email protected]96bcdc102012-05-24 23:42:10582 prefs.fixed_position_creates_stacking_context =
583 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
584
[email protected]2e21fe292012-03-02 22:52:32585 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54586
587 return prefs;
588}
589
[email protected]b172aee2012-04-10 17:05:26590NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20591 return controller_;
592}
593
[email protected]b172aee2012-04-10 17:05:26594RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28595 return &render_manager_;
596}
597
[email protected]b172aee2012-04-10 17:05:26598bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56599 if (GetWebUI() &&
600 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17601 return true;
[email protected]d2353452012-01-19 19:53:56602 }
[email protected]f82d57b52011-04-27 19:13:17603
[email protected]d8c660432011-12-22 20:51:25604 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
605 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10606 while ((observer = it.GetNext()) != NULL)
607 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53608 return true;
[email protected]403415a2011-01-10 18:57:53609
[email protected]724159a2010-12-30 01:11:18610 bool handled = true;
611 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26612 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58613 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
614 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24615 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
616 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18617 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
618 OnDidLoadResourceFromMemoryCache)
619 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
620 OnDidDisplayInsecureContent)
621 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
622 OnDidRunInsecureContent)
623 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
624 OnDocumentLoadedInFrame)
625 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26626 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
627 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17628 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
629 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25630 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26631 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59632 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21633 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20634 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
635 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
636 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16637 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45638 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10639 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20640 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
641 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
642 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
643 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29644 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50645 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18646 IPC_MESSAGE_UNHANDLED(handled = false)
647 IPC_END_MESSAGE_MAP_EX()
648
649 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38650 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18651 GetRenderProcessHost()->ReceivedBadMessage();
652 }
653
654 return handled;
655}
656
[email protected]b172aee2012-04-10 17:05:26657void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18658 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23659 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51660 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18661}
662
[email protected]b172aee2012-04-10 17:05:26663NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56664 return controller_;
665}
666
[email protected]b172aee2012-04-10 17:05:26667const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56668 return controller_;
669}
670
[email protected]b172aee2012-04-10 17:05:26671content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55672 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30673}
674
[email protected]b172aee2012-04-10 17:05:26675const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31676 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23677 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51678 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31679}
680
681
[email protected]b172aee2012-04-10 17:05:26682const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31683 return &property_bag_;
684}
685
[email protected]b172aee2012-04-10 17:05:26686base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31687 return &property_bag_;
688}
689
[email protected]b172aee2012-04-10 17:05:26690content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31691 return delegate_;
692}
693
[email protected]b172aee2012-04-10 17:05:26694void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31695 // TODO(cbentzel): remove this debugging code?
696 if (delegate == delegate_)
697 return;
698 if (delegate_)
699 delegate_->Detach(this);
700 delegate_ = delegate;
701 if (delegate_)
702 delegate_->Attach(this);
703}
704
[email protected]b172aee2012-04-10 17:05:26705content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41706 RenderViewHostImpl* host = render_manager_.current_host();
707 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16708}
709
[email protected]b172aee2012-04-10 17:05:26710RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31711 return render_manager_.current_host();
712}
713
[email protected]b172aee2012-04-10 17:05:26714RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31715 return render_manager_.GetRenderWidgetHostView();
716}
717
[email protected]b172aee2012-04-10 17:05:26718content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31719 return view_.get();
720}
721
[email protected]b172aee2012-04-10 17:05:26722content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50723 WebUIControllerFactory* factory =
724 content::GetContentClient()->browser()->GetWebUIControllerFactory();
725 if (!factory)
726 return NULL;
[email protected]d2353452012-01-19 19:53:56727 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22728 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50729 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22730 if (controller) {
731 web_ui->SetController(controller);
732 return web_ui;
733 }
734
735 delete web_ui;
736 return NULL;
737}
738
[email protected]b172aee2012-04-10 17:05:26739content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31740 return render_manager_.web_ui() ? render_manager_.web_ui()
741 : render_manager_.pending_web_ui();
742}
743
[email protected]b172aee2012-04-10 17:05:26744content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31745 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34746}
747
[email protected]86ef6a392012-05-11 22:03:11748void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
749 user_agent_override_ = override;
750}
751
752const std::string& WebContentsImpl::GetUserAgentOverride() const {
753 return user_agent_override_;
754}
755
[email protected]b172aee2012-04-10 17:05:26756const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55757 // Transient entries take precedence. They are used for interstitial pages
758 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23759 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08760 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20761 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30762 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23763 if (entry) {
[email protected]b5cca982011-05-26 04:42:08764 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23765 }
[email protected]7ade2732011-02-10 00:13:58766 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
767 render_manager_.pending_web_ui() : render_manager_.web_ui();
768 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54769 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55770 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54771 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35772 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22773 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54774 if (!title.empty())
775 return title;
776 }
777 }
778
779 // We use the title for the last committed entry rather than a pending
780 // navigation entry. For example, when the user types in a URL, we want to
781 // keep the old page's title until the new load has committed and we get a new
782 // title.
[email protected]96d185d2009-04-24 03:28:54783 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23784 if (entry) {
[email protected]b5cca982011-05-26 04:42:08785 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23786 }
[email protected]987fc3a2011-05-26 14:18:09787
788 // |page_title_when_no_navigation_entry_| is finally used
789 // if no title cannot be retrieved.
790 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54791}
792
[email protected]b172aee2012-04-10 17:05:26793int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46794 return GetMaxPageIDForSiteInstance(GetSiteInstance());
795}
796
[email protected]b172aee2012-04-10 17:05:26797int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
798 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33799 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
800 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46801
[email protected]b6583592012-01-25 19:52:33802 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34803}
804
[email protected]b172aee2012-04-10 17:05:26805void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46806 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
807}
808
[email protected]b172aee2012-04-10 17:05:26809void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33810 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46811 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33812 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34813}
814
[email protected]b172aee2012-04-10 17:05:26815void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
816 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57817}
818
[email protected]b172aee2012-04-10 17:05:26819SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58820 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54821}
822
[email protected]b172aee2012-04-10 17:05:26823SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38824 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
825 render_manager_.pending_render_view_host() :
826 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58827 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38828}
829
[email protected]b172aee2012-04-10 17:05:26830bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return waiting_for_response_;
836}
837
[email protected]b172aee2012-04-10 17:05:26838const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return load_state_;
840}
841
[email protected]b172aee2012-04-10 17:05:26842const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return load_state_host_;
844}
845
[email protected]b172aee2012-04-10 17:05:26846uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return upload_size_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return upload_position_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return encoding_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return displayed_insecure_content_;
860}
861
[email protected]b172aee2012-04-10 17:05:26862void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31863 capturing_contents_ = cap;
864}
865
[email protected]b172aee2012-04-10 17:05:26866bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
868 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
869 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49870}
871
[email protected]b172aee2012-04-10 17:05:26872void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
873 int error_code) {
[email protected]443b80e2010-12-14 00:42:23874 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34875 return;
876
[email protected]443b80e2010-12-14 00:42:23877 crashed_status_ = status;
878 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46879 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34880}
881
[email protected]b172aee2012-04-10 17:05:26882base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return crashed_status_;
884}
885
[email protected]b172aee2012-04-10 17:05:26886bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31887 return is_being_destroyed_;
888}
889
[email protected]b172aee2012-04-10 17:05:26890void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34891 if (delegate_)
892 delegate_->NavigationStateChanged(this, changed_flags);
893}
894
[email protected]b172aee2012-04-10 17:05:26895void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54896 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04897 RenderWidgetHostViewPort* rwhv =
898 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16899 if (rwhv) {
900 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43901#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16902 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43903#endif
904 }
[email protected]96d185d2009-04-24 03:28:54905
[email protected]5ac20162010-11-24 23:33:11906 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38907
[email protected]d8c660432011-12-22 20:51:25908 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59909
910 // The resize rect might have changed while this was inactive -- send the new
911 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58912 RenderViewHostImpl* rvh =
913 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59914 if (rvh) {
915 rvh->ResizeRectChanged(GetRootWindowResizerRect());
916 }
[email protected]96d185d2009-04-24 03:28:54917}
918
[email protected]be1f56ab2011-12-22 06:55:31919
[email protected]b172aee2012-04-10 17:05:26920base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31921 return last_selected_time_;
922}
923
[email protected]b172aee2012-04-10 17:05:26924void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31925 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52926 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
927 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26928 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52929 // removes the |GetRenderViewHost()|; then when we actually destroy the
930 // window, OnWindowPosChanged() notices and calls HideContents() (which
931 // calls us).
[email protected]c30585c2012-02-16 15:02:04932 RenderWidgetHostViewPort* rwhv =
933 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16934 if (rwhv)
935 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54936 }
937
[email protected]375fa1b2012-05-22 22:05:37938 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07939 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37940 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09941 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37942 content::Details<bool>(&is_visible));
943}
944
945void WebContentsImpl::WasRestored() {
946 bool is_visible = true;
947 content::NotificationService::current()->Notify(
948 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
949 content::Source<WebContents>(this),
950 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54951}
952
[email protected]b172aee2012-04-10 17:05:26953void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04954 RenderWidgetHostViewPort* rwhv =
955 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31956 if (rwhv)
957 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37958 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31959}
960
[email protected]b172aee2012-04-10 17:05:26961void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31962 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
963 // our superclass HideContents(), because some callers want to be very picky
964 // about the order in which these get called. In addition to making the code
965 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26966 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
967 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31968 WasHidden();
969}
970
[email protected]b172aee2012-04-10 17:05:26971bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31972 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27973 return WillNotifyDisconnection() &&
974 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58975 !static_cast<RenderViewHostImpl*>(
976 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31977}
978
[email protected]b172aee2012-04-10 17:05:26979void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27980 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25981 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27982}
983
[email protected]b172aee2012-04-10 17:05:26984WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44985 // We use our current SiteInstance since the cloned entry will use it anyway.
986 // We pass |this| for the |base_web_contents| to size the view correctly, and
987 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26988 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44989 GetBrowserContext(), GetSiteInstance(),
990 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20991 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27992 return tc;
993}
994
[email protected]b172aee2012-04-10 17:05:26995void WebContentsImpl::AddNewContents(WebContents* new_contents,
996 WindowOpenDisposition disposition,
997 const gfx::Rect& initial_pos,
998 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27999 if (!delegate_)
1000 return;
1001
1002 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1003 user_gesture);
1004}
1005
[email protected]b172aee2012-04-10 17:05:261006gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271007 return view_->GetContentNativeView();
1008}
1009
[email protected]b172aee2012-04-10 17:05:261010gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271011 return view_->GetNativeView();
1012}
1013
[email protected]b172aee2012-04-10 17:05:261014void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271015 view_->GetContainerBounds(out);
1016}
1017
[email protected]b172aee2012-04-10 17:05:261018void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271019 view_->Focus();
1020}
1021
[email protected]14392a52012-05-02 20:28:441022void WebContentsImpl::Observe(int type,
1023 const content::NotificationSource& source,
1024 const content::NotificationDetails& details) {
1025 switch (type) {
1026 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1027 OnWebContentsDestroyed(
1028 content::Source<content::WebContents>(source).ptr());
1029 break;
[email protected]bafe6cd2012-05-23 23:09:501030 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1031 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1032 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1033 i != pending_widget_views_.end(); ++i) {
1034 if (host->GetView() == i->second) {
1035 pending_widget_views_.erase(i);
1036 break;
1037 }
1038 }
1039 break;
1040 }
[email protected]14392a52012-05-02 20:28:441041 default:
1042 NOTREACHED();
1043 }
1044}
1045
1046void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1047 // Clear the opener if it has been closed.
1048 if (web_contents == opener_) {
1049 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1050 content::Source<WebContents>(opener_));
1051 opener_ = NULL;
1052 }
1053}
1054
[email protected]b172aee2012-04-10 17:05:261055void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311056 observers_.AddObserver(observer);
1057}
1058
[email protected]b172aee2012-04-10 17:05:261059void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311060 observers_.RemoveObserver(observer);
1061}
1062
[email protected]b172aee2012-04-10 17:05:261063void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341064 if (delegate_)
1065 delegate_->ActivateContents(this);
1066}
1067
[email protected]b172aee2012-04-10 17:05:261068void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121069 if (delegate_)
1070 delegate_->DeactivateContents(this);
1071}
1072
[email protected]b172aee2012-04-10 17:05:261073void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481074 if (delegate_)
1075 delegate_->LostCapture();
1076}
1077
[email protected]b172aee2012-04-10 17:05:261078bool WebContentsImpl::PreHandleKeyboardEvent(
1079 const NativeWebKeyboardEvent& event,
1080 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481081 return delegate_ &&
1082 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1083}
1084
[email protected]b172aee2012-04-10 17:05:261085void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481086 if (delegate_)
1087 delegate_->HandleKeyboardEvent(event);
1088}
1089
[email protected]b172aee2012-04-10 17:05:261090void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431091 if (delegate_)
1092 delegate_->HandleMouseDown();
1093}
1094
[email protected]b172aee2012-04-10 17:05:261095void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481096 if (delegate_)
1097 delegate_->HandleMouseUp();
1098}
1099
[email protected]b172aee2012-04-10 17:05:261100void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481101 if (delegate_)
1102 delegate_->HandleMouseActivate();
1103}
1104
[email protected]b172aee2012-04-10 17:05:261105void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471106 if (delegate_)
1107 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1108}
1109
[email protected]b172aee2012-04-10 17:05:261110bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381111 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121112}
1113
[email protected]a9c81f02012-06-01 00:15:441114void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1115 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371116 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441117 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371118 } else {
1119 GotResponseToLockMouseRequest(false);
1120 }
1121}
1122
[email protected]b172aee2012-04-10 17:05:261123void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371124 if (delegate_)
1125 delegate_->LostMouseLock();
1126}
1127
[email protected]bafe6cd2012-05-23 23:09:501128void WebContentsImpl::CreateNewWindow(
1129 int route_id,
[email protected]97714c82012-06-06 10:15:131130 const ViewHostMsg_CreateWindow_Params& params,
1131 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501132 if (delegate_ && !delegate_->ShouldCreateWebContents(
1133 this, route_id, params.window_container_type, params.frame_name,
1134 params.target_url)) {
1135 return;
1136 }
1137
1138 // We usually create the new window in the same BrowsingInstance (group of
1139 // script-related windows), by passing in the current SiteInstance. However,
1140 // if the opener is being suppressed, we create a new SiteInstance in its own
1141 // BrowsingInstance.
1142 scoped_refptr<SiteInstance> site_instance =
1143 params.opener_suppressed ?
1144 SiteInstance::Create(GetBrowserContext()) :
1145 GetSiteInstance();
1146
1147 // Create the new web contents. This will automatically create the new
1148 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131149 WebContentsImpl* new_contents = new WebContentsImpl(
1150 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571151 site_instance,
1152 route_id,
1153 this,
1154 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131155 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501156 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1157
1158 if (!params.opener_suppressed) {
1159 content::WebContentsView* new_view = new_contents->GetView();
1160
1161 // TODO(brettw): It seems bogus that we have to call this function on the
1162 // newly created object and give it one of its own member variables.
1163 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1164
1165 // Save the created window associated with the route so we can show it
1166 // later.
1167 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1168 pending_contents_[route_id] = new_contents;
1169 }
1170
1171 if (delegate_) {
1172 delegate_->WebContentsCreated(
1173 this, params.opener_frame_id, params.target_url, new_contents);
1174 }
1175
1176 if (params.opener_suppressed) {
1177 // When the opener is suppressed, the original renderer cannot access the
1178 // new window. As a result, we need to show and navigate the window here.
1179 gfx::Rect initial_pos;
1180 AddNewContents(
1181 new_contents, params.disposition, initial_pos, params.user_gesture);
1182
1183 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1184 CURRENT_TAB,
1185 content::PAGE_TRANSITION_LINK,
1186 true /* is_renderer_initiated */);
1187 new_contents->OpenURL(open_params);
1188 }
1189}
1190
1191void WebContentsImpl::CreateNewWidget(int route_id,
1192 WebKit::WebPopupType popup_type) {
1193 CreateNewWidget(route_id, false, popup_type);
1194}
1195
1196void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1197 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1198}
1199
1200void WebContentsImpl::CreateNewWidget(int route_id,
1201 bool is_fullscreen,
1202 WebKit::WebPopupType popup_type) {
1203 content::RenderProcessHost* process = GetRenderProcessHost();
1204 RenderWidgetHostImpl* widget_host =
1205 new RenderWidgetHostImpl(this, process, route_id);
1206 RenderWidgetHostViewPort* widget_view =
1207 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1208 if (!is_fullscreen) {
1209 // Popups should not get activated.
1210 widget_view->SetPopupType(popup_type);
1211 }
1212 // Save the created widget associated with the route so we can show it later.
1213 pending_widget_views_[route_id] = widget_view;
1214
1215#if defined(OS_MACOSX)
1216 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1217 // to allow it to survive the trip without being hosted.
1218 base::mac::NSObjectRetain(widget_view->GetNativeView());
1219#endif
1220}
1221
1222void WebContentsImpl::ShowCreatedWindow(int route_id,
1223 WindowOpenDisposition disposition,
1224 const gfx::Rect& initial_pos,
1225 bool user_gesture) {
1226 WebContentsImpl* contents = GetCreatedWindow(route_id);
1227 if (contents)
1228 AddNewContents(contents, disposition, initial_pos, user_gesture);
1229}
1230
1231void WebContentsImpl::ShowCreatedWidget(int route_id,
1232 const gfx::Rect& initial_pos) {
1233 ShowCreatedWidget(route_id, false, initial_pos);
1234}
1235
1236void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1237 ShowCreatedWidget(route_id, true, gfx::Rect());
1238}
1239
1240void WebContentsImpl::ShowCreatedWidget(int route_id,
1241 bool is_fullscreen,
1242 const gfx::Rect& initial_pos) {
1243 if (delegate_)
1244 delegate_->RenderWidgetShowing();
1245
1246 RenderWidgetHostViewPort* widget_host_view =
1247 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1248 if (!widget_host_view)
1249 return;
1250 if (is_fullscreen) {
1251 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1252 } else {
1253 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1254 }
[email protected]89054502012-06-03 10:29:241255
1256 RenderWidgetHostImpl* render_widget_host_impl =
1257 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1258 render_widget_host_impl->Init();
1259 // Only allow privileged mouse lock for fullscreen render widget, which is
1260 // used to implement Pepper Flash fullscreen.
1261 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501262
1263#if defined(OS_MACOSX)
1264 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1265 // properly embedded (or purposefully ignored) we can release the retain we
1266 // took in CreateNewWidget().
1267 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1268#endif
1269}
1270
1271WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1272 PendingContents::iterator iter = pending_contents_.find(route_id);
1273
1274 // Certain systems can block the creation of new windows. If we didn't succeed
1275 // in creating one, just return NULL.
1276 if (iter == pending_contents_.end()) {
1277 return NULL;
1278 }
1279
1280 WebContentsImpl* new_contents = iter->second;
1281 pending_contents_.erase(route_id);
1282
1283 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1284 !new_contents->GetRenderViewHost()->GetView())
1285 return NULL;
1286
1287 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1288 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1289 return new_contents;
1290}
1291
1292RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1293 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1294 if (iter == pending_widget_views_.end()) {
1295 DCHECK(false);
1296 return NULL;
1297 }
1298
1299 RenderWidgetHostView* widget_host_view = iter->second;
1300 pending_widget_views_.erase(route_id);
1301
1302 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1303 if (!widget_host->GetProcess()->HasConnection()) {
1304 // The view has gone away or the renderer crashed. Nothing to do.
1305 return NULL;
1306 }
1307
1308 return widget_host_view;
1309}
1310
1311void WebContentsImpl::ShowContextMenu(
1312 const content::ContextMenuParams& params) {
1313 // Allow WebContentsDelegates to handle the context menu operation first.
1314 if (delegate_ && delegate_->HandleContextMenu(params))
1315 return;
1316
[email protected]5a3bdf52012-05-24 15:12:571317 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501318}
1319
[email protected]f13b4202012-06-12 23:53:231320void WebContentsImpl::RequestMediaAccessPermission(
1321 const content::MediaStreamRequest* request,
1322 const content::MediaResponseCallback& callback) {
1323 if (delegate_)
1324 delegate_->RequestMediaAccessPermission(this, request, callback);
1325 else
1326 callback.Run(content::MediaStreamDevices());
1327}
1328
[email protected]b172aee2012-04-10 17:05:261329void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231330 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331331 if (delegate_)
1332 delegate_->UpdatePreferredSize(this, pref_size);
1333}
1334
[email protected]b172aee2012-04-10 17:05:261335void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341336 if (delegate_)
1337 delegate_->ResizeDueToAutoResize(this, new_size);
1338}
1339
[email protected]b172aee2012-04-10 17:05:261340WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201341 if (!delegate_)
1342 return NULL;
[email protected]00c37fc2011-08-02 00:22:501343
[email protected]e5d549d2011-12-28 01:29:201344 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1345 // Notify observers.
1346 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1347 DidOpenURL(params.url, params.referrer,
1348 params.disposition, params.transition));
1349 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341350}
1351
[email protected]b172aee2012-04-10 17:05:261352bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501353 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251354 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231355 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251356 reload_type);
[email protected]876bc832010-09-07 16:29:541357}
[email protected]96d185d2009-04-24 03:28:541358
[email protected]ba45bfd2012-05-22 21:51:441359void WebContentsImpl::RenderViewForInterstitialPageCreated(
1360 content::RenderViewHost* render_view_host) {
1361 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1362 RenderViewForInterstitialPageCreated(render_view_host));
1363}
1364
[email protected]b172aee2012-04-10 17:05:261365bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231366 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501367 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401368 // The renderer will reject IPC messages with URLs longer than
1369 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511370 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401371 return false;
1372
[email protected]9f76c1e2012-03-05 15:15:581373 RenderViewHostImpl* dest_render_view_host =
1374 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401375 if (!dest_render_view_host)
1376 return false; // Unable to create the desired render view host.
1377
[email protected]80a8fad2011-01-29 04:02:381378 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071379 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581380 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501381 WebUIControllerFactory* factory =
1382 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271383 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501384 bool is_allowed_in_web_ui_renderer =
1385 factory &&
[email protected]24e18252012-04-16 21:26:271386 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1387 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231388 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1389 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271390 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231391 content::GetContentClient()->SetActiveURL(entry.GetURL());
1392 CHECK(0);
1393 }
[email protected]54ec6472010-04-09 19:39:581394
[email protected]96d185d2009-04-24 03:28:541395 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441396 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521397 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441398 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511399 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541400
1401 // Used for page load time metrics.
1402 current_load_start_ = base::TimeTicks::Now();
1403
1404 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241405 std::string embedder_channel_name;
1406 int embedder_container_id;
1407 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1408 &embedder_channel_name,
1409 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341410 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271411 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241412 embedder_channel_name,
1413 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471414 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341415 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541416
[email protected]36fc0392011-12-25 03:59:511417 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541418 // HACK!! This code suppresses javascript: URLs from being added to
1419 // session history, which is what we want to do for javascript: URLs that
1420 // do not generate content. What we really need is a message from the
1421 // renderer telling us that a new page was not created. The same message
1422 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511423 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541424 return false;
1425 }
1426
[email protected]3c9e1872010-11-18 16:17:491427 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251428 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041429 observers_,
[email protected]36fc0392011-12-25 03:59:511430 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541431
[email protected]09b29342011-06-24 19:18:481432 if (delegate_)
1433 delegate_->DidNavigateToPendingEntry(this);
1434
[email protected]d5f942ba2008-09-26 19:30:341435 return true;
1436}
1437
[email protected]b172aee2012-04-10 17:05:261438void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331439 const SiteInstance* site_instance,
1440 int history_length,
1441 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411442 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1443 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191444 if (render_manager_.pending_render_view_host()) {
1445 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141446 return;
[email protected]9e1ad4b2011-08-14 16:49:191447 }
[email protected]9f76c1e2012-03-05 15:15:581448 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191449 if (!rvh) {
1450 NOTREACHED();
1451 return;
1452 }
[email protected]9f76c1e2012-03-05 15:15:581453 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191454 NOTREACHED();
1455 return;
1456 }
[email protected]9f76c1e2012-03-05 15:15:581457 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191458 history_length,
1459 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141460}
1461
[email protected]b172aee2012-04-10 17:05:261462void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271463 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541464 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1465 return;
1466 }
[email protected]9f76c1e2012-03-05 15:15:581467 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541468}
1469
[email protected]b172aee2012-04-10 17:05:261470bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271471 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541472}
1473
[email protected]b172aee2012-04-10 17:05:261474InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271475 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221476}
1477
[email protected]b172aee2012-04-10 17:05:261478bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161479 // WebKit creates Document object when MIME type is application/xhtml+xml,
1480 // so we also support this MIME type.
1481 return contents_mime_type_ == "text/html" ||
1482 contents_mime_type_ == "text/xml" ||
1483 contents_mime_type_ == "application/xhtml+xml" ||
1484 contents_mime_type_ == "text/plain" ||
1485 contents_mime_type_ == "text/css" ||
1486 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1487}
1488
[email protected]b172aee2012-04-10 17:05:261489void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591490 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161491 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481492 download_stats::RecordDownloadSource(
1493 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461494 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141495 return;
[email protected]c7dd2f62011-07-18 15:57:591496 }
1497
1498 Stop();
1499
1500 // Create the save package and possibly prompt the user for the name to save
1501 // the page as. The user prompt is an asynchronous operation that runs on
1502 // another thread.
1503 save_package_ = new SavePackage(this);
1504 save_package_->GetSaveInfo();
1505}
1506
1507// Used in automated testing to bypass prompting the user for file names.
1508// Instead, the names and paths are hard coded rather than running them through
1509// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261510bool WebContentsImpl::SavePage(const FilePath& main_file,
1511 const FilePath& dir_path,
1512 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591513 // Stop the page from navigating.
1514 Stop();
1515
1516 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271517 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591518}
1519
[email protected]b172aee2012-04-10 17:05:261520void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121521 const FilePath& file,
1522 const base::Callback<void(const FilePath&, int64)>& callback) {
1523 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1524}
1525
[email protected]b172aee2012-04-10 17:05:261526bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231527 NavigationEntryImpl* active_entry =
1528 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321529 return (active_entry != NULL &&
1530 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511531 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321532}
1533
[email protected]b172aee2012-04-10 17:05:261534const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271535 return contents_mime_type_;
1536}
1537
[email protected]b172aee2012-04-10 17:05:261538bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271539 return notify_disconnection_;
1540}
1541
[email protected]b172aee2012-04-10 17:05:261542void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311543 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581544 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1545 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161546}
1547
[email protected]b172aee2012-04-10 17:05:261548void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311549 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581550 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1551 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161552}
1553
[email protected]b172aee2012-04-10 17:05:261554content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271555 return &renderer_preferences_;
1556}
1557
[email protected]b172aee2012-04-10 17:05:261558void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271559 new_tab_start_time_ = time;
1560}
1561
[email protected]b172aee2012-04-10 17:05:261562base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271563 return new_tab_start_time_;
1564}
1565
[email protected]e35ccd52012-05-23 16:22:471566void WebContentsImpl::Close() {
1567 Close(GetRenderViewHost());
1568}
1569
[email protected]b172aee2012-04-10 17:05:261570void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151571 if (close_start_time_.is_null())
1572 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011573}
1574
[email protected]b172aee2012-04-10 17:05:261575bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191576#if defined(OS_CHROMEOS)
1577 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1578 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511579 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201580 return false;
1581 return true;
[email protected]46624bf2010-06-09 16:04:191582#else
1583 return true;
1584#endif
1585}
1586
[email protected]b172aee2012-04-10 17:05:261587void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521588 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581589 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511590 if (delegate_)
1591 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341592}
1593
[email protected]e35ccd52012-05-23 16:22:471594void WebContentsImpl::UserGestureDone() {
1595 OnUserGesture();
1596}
1597
[email protected]b172aee2012-04-10 17:05:261598void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271599 closed_by_user_gesture_ = value;
1600}
1601
[email protected]b172aee2012-04-10 17:05:261602bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271603 return closed_by_user_gesture_;
1604}
1605
[email protected]b172aee2012-04-10 17:05:261606double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051607 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561608 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251609 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171610 return 0;
[email protected]b75b8292010-10-01 07:28:251611
1612 double zoom_level;
1613 if (temporary_zoom_settings_) {
1614 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581615 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251616 } else {
[email protected]2ae88d12011-10-14 09:11:191617 GURL url;
[email protected]10f417c52011-12-28 21:04:231618 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191619 // Since zoom map is updated using rewritten URL, use rewritten URL
1620 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511621 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191622 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251623 }
[email protected]d0b8d092010-10-25 04:05:171624 return zoom_level;
1625}
[email protected]b75b8292010-10-01 07:28:251626
[email protected]b172aee2012-04-10 17:05:261627int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1628 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171629 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011630 // Calculate the zoom percent from the factor. Round up to the nearest whole
1631 // number.
[email protected]b75b8292010-10-01 07:28:251632 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011633 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251634 *enable_decrement = percent > minimum_zoom_percent_;
1635 *enable_increment = percent < maximum_zoom_percent_;
1636 return percent;
1637}
1638
[email protected]b172aee2012-04-10 17:05:261639void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501640 if (!delegate_)
1641 return;
1642
[email protected]10f417c52011-12-28 21:04:231643 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501644 if (!active_entry)
1645 return;
1646
[email protected]36fc0392011-12-25 03:59:511647 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121648}
1649
[email protected]b172aee2012-04-10 17:05:261650void WebContentsImpl::ViewFrameSource(const GURL& url,
1651 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271652 if (!delegate_)
1653 return;
1654
1655 delegate_->ViewSourceForFrame(this, url, content_state);
1656}
1657
[email protected]b172aee2012-04-10 17:05:261658int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271659 return minimum_zoom_percent_;
1660}
1661
[email protected]b172aee2012-04-10 17:05:261662int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271663 return maximum_zoom_percent_;
1664}
1665
[email protected]b172aee2012-04-10 17:05:261666gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231667 return preferred_size_;
1668}
1669
[email protected]b172aee2012-04-10 17:05:261670int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271671 return content_restrictions_;
1672}
1673
[email protected]b172aee2012-04-10 17:05:261674WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501675 WebUIControllerFactory* factory =
1676 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1677 if (!factory)
1678 return WebUI::kNoWebUI;
1679 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271680}
1681
[email protected]b172aee2012-04-10 17:05:261682content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271683 // When there is a pending navigation entry, we want to use the pending WebUI
1684 // that goes along with it to control the basic flags. For example, we want to
1685 // show the pending URL in the URL bar, so we want the display_url flag to
1686 // be from the pending entry.
1687 //
1688 // The confusion comes because there are multiple possibilities for the
1689 // initial load in a tab as a side effect of the way the RenderViewHostManager
1690 // works.
1691 //
1692 // - For the very first tab the load looks "normal". The new tab Web UI is
1693 // the pending one, and we want it to apply here.
1694 //
1695 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1696 // get switched to the one previously associated with the new tab pages.
1697 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1698 // have a committed Web UI in this case.
1699 //
1700 // This condition handles all of these cases:
1701 //
1702 // - First load in first tab: no committed nav entry + pending nav entry +
1703 // pending dom ui:
1704 // -> Use pending Web UI if any.
1705 //
1706 // - First load in second tab: no committed nav entry + pending nav entry +
1707 // no pending Web UI:
1708 // -> Use the committed Web UI if any.
1709 //
1710 // - Second navigation in any tab: committed nav entry + pending nav entry:
1711 // -> Use pending Web UI if any.
1712 //
1713 // - Normal state with no load: committed nav entry + no pending nav entry:
1714 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251715 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271716 (controller_.GetLastCommittedEntry() ||
1717 render_manager_.pending_web_ui()))
1718 return render_manager_.pending_web_ui();
1719 return render_manager_.web_ui();
1720}
1721
[email protected]b172aee2012-04-10 17:05:261722bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271723 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581724 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271725}
1726
[email protected]b172aee2012-04-10 17:05:261727bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441728 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501729}
1730
[email protected]b172aee2012-04-10 17:05:261731void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321732 SkColor color) {
[email protected]da8543762012-03-20 08:52:201733 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1734 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1735}
1736
[email protected]b172aee2012-04-10 17:05:261737void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201738 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1739 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1740 if (delegate_)
1741 delegate_->DidEndColorChooser();
1742 color_chooser_ = NULL;
1743}
1744
[email protected]b172aee2012-04-10 17:05:261745bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471746 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271747 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221748 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231749 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411750 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271754 if (delegate_)
1755 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211756}
1757
[email protected]3a3b75a2012-06-01 08:38:361758void WebContentsImpl::OnRegisterIntentService(
1759 const webkit_glue::WebIntentServiceData& data,
1760 bool user_gesture) {
1761 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301762}
1763
[email protected]b172aee2012-04-10 17:05:261764void WebContentsImpl::OnWebIntentDispatch(
1765 const webkit_glue::WebIntentData& intent,
1766 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001767 WebIntentsDispatcherImpl* intents_dispatcher =
1768 new WebIntentsDispatcherImpl(this, intent, intent_id);
1769 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301770}
1771
[email protected]54047eb52012-05-08 21:45:571772void WebContentsImpl::DidStartProvisionalLoadForFrame(
1773 content::RenderViewHost* render_view_host,
1774 int64 frame_id,
1775 bool is_main_frame,
1776 const GURL& opener_url,
1777 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281778 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181779 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451780 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571781 content::RenderProcessHost* render_process_host =
1782 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161783 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581784 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571785 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451786 false,
[email protected]9f76c1e2012-03-05 15:15:581787 &validated_url);
[email protected]97d402f32012-06-01 02:55:161788 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451789 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571790 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451791 true,
1792 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181793
[email protected]0d60f0192011-04-14 12:40:101794 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251795 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101796 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571797 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541798
1799 if (is_main_frame) {
1800 // Notify observers about the provisional change in the main frame URL.
1801 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1802 ProvisionalChangeToMainFrameUrl(validated_url,
1803 validated_opener_url,
1804 render_view_host));
1805 }
1806}
1807
1808void WebContentsImpl::DidRedirectProvisionalLoad(
1809 content::RenderViewHost* render_view_host,
1810 int32 page_id,
1811 const GURL& opener_url,
1812 const GURL& source_url,
1813 const GURL& target_url) {
1814 // TODO(creis): Remove this method and have the pre-rendering code listen to
1815 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1816 // instead. See http://crbug.com/78512.
1817 GURL validated_source_url(source_url);
1818 GURL validated_target_url(target_url);
1819 GURL validated_opener_url(opener_url);
1820 content::RenderProcessHost* render_process_host =
1821 render_view_host->GetProcess();
1822 RenderViewHostImpl::FilterURL(
1823 ChildProcessSecurityPolicyImpl::GetInstance(),
1824 render_process_host->GetID(),
1825 false,
1826 &validated_source_url);
1827 RenderViewHostImpl::FilterURL(
1828 ChildProcessSecurityPolicyImpl::GetInstance(),
1829 render_process_host->GetID(),
1830 false,
1831 &validated_target_url);
1832 RenderViewHostImpl::FilterURL(
1833 ChildProcessSecurityPolicyImpl::GetInstance(),
1834 render_process_host->GetID(),
1835 true,
1836 &validated_opener_url);
1837 NavigationEntry* entry;
1838 if (page_id == -1) {
1839 entry = controller_.GetPendingEntry();
1840 } else {
1841 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1842 page_id);
1843 }
1844 if (!entry || entry->GetURL() != validated_source_url)
1845 return;
1846
1847 // Notify observers about the provisional change in the main frame URL.
1848 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1849 ProvisionalChangeToMainFrameUrl(validated_target_url,
1850 validated_opener_url,
1851 render_view_host));
[email protected]724159a2010-12-30 01:11:181852}
1853
[email protected]54047eb52012-05-08 21:45:571854void WebContentsImpl::DidFailProvisionalLoadWithError(
1855 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581856 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1857 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1858 << ", error_code: " << params.error_code
1859 << ", error_description: " << params.error_description
1860 << ", is_main_frame: " << params.is_main_frame
1861 << ", showing_repost_interstitial: " <<
1862 params.showing_repost_interstitial
1863 << ", frame_id: " << params.frame_id;
1864 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571865 content::RenderProcessHost* render_process_host =
1866 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161867 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581868 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571869 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451870 false,
[email protected]9f76c1e2012-03-05 15:15:581871 &validated_url);
[email protected]724159a2010-12-30 01:11:181872
[email protected]d7b175e2011-10-11 15:31:581873 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181874 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1875 // This means that the interstitial won't be torn down properly, which is
1876 // bad. But if we have an interstitial, go back to another tab type, and
1877 // then load the same interstitial again, we could end up getting the first
1878 // interstitial's "failed" message (as a result of the cancel) when we're on
1879 // the second one.
1880 //
1881 // We can't tell this apart, so we think we're tearing down the current page
1882 // which will cause a crash later one. There is also some code in
1883 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1884 // out because of this problem.
1885 //
1886 // http://code.google.com/p/chromium/issues/detail?id=2855
1887 // Because this will not tear down the interstitial properly, if "back" is
1888 // back to another tab type, the interstitial will still be somewhat alive
1889 // in the previous tab type. If you navigate somewhere that activates the
1890 // tab with the interstitial again, you'll see a flash before the new load
1891 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271892 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181893 LOG(WARNING) << "Discarding message during interstitial.";
1894 return;
1895 }
1896
[email protected]02102f82011-06-13 20:37:021897 // Discard our pending entry if the load canceled (e.g. if we decided to
1898 // download the file instead of load it). We do not verify that the URL
1899 // being canceled matches the pending entry's URL because they will not
1900 // match if a redirect occurred (in which case we do not want to leave a
1901 // stale redirect URL showing). This means that we also cancel the pending
1902 // entry if the user started a new navigation. As a result, the navigation
1903 // controller may not remember that a load is in progress, but the
1904 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251905 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161906 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181907
[email protected]54047eb52012-05-08 21:45:571908 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181909 }
1910
[email protected]d8c660432011-12-22 20:51:251911 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581912 observers_,
1913 DidFailProvisionalLoad(params.frame_id,
1914 params.is_main_frame,
1915 validated_url,
1916 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461917 params.error_description,
1918 render_view_host));
[email protected]724159a2010-12-30 01:11:181919}
1920
[email protected]b172aee2012-04-10 17:05:261921void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181922 const GURL& url,
[email protected]70435962011-08-02 20:13:281923 const std::string& security_info,
1924 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181925 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281926 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191927 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181928 cache.Increment();
1929
1930 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081931 int cert_id = 0;
1932 net::CertStatus cert_status = 0;
1933 int security_bits = -1;
1934 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511935 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1936 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301937 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]6d6cfb3a2012-05-23 22:53:181938 cert_id, cert_status, http_method,
1939 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181940
[email protected]ad50def52011-10-19 23:17:071941 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271942 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501943 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531944 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181945}
1946
[email protected]b172aee2012-04-10 17:05:261947void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381948 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181949 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201950 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181951}
1952
[email protected]b172aee2012-04-10 17:05:261953void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021954 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231955 LOG(INFO) << security_origin << " ran insecure content from "
1956 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381957 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411958 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1959 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181960 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411961 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201962 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181963}
1964
[email protected]b172aee2012-04-10 17:05:261965void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181966 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251967 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101968 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181969}
1970
[email protected]b172aee2012-04-10 17:05:261971void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311972 int64 frame_id,
1973 const GURL& validated_url,
1974 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251975 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311976 DidFinishLoad(frame_id, validated_url, is_main_frame));
1977}
1978
[email protected]b172aee2012-04-10 17:05:261979void WebContentsImpl::OnDidFailLoadWithError(
1980 int64 frame_id,
1981 const GURL& validated_url,
1982 bool is_main_frame,
1983 int error_code,
1984 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251985 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311986 DidFailLoad(frame_id, validated_url, is_main_frame,
1987 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181988}
1989
[email protected]b172aee2012-04-10 17:05:261990void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271991 content_restrictions_ = restrictions;
1992 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171993}
1994
[email protected]b172aee2012-04-10 17:05:261995void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261996 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231997 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251998 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261999 if (!entry)
2000 return;
2001 // Note that we don't call NavigationController::GotToOffset() as we don't
2002 // want to create a pending navigation entry (it might end up lingering
2003 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252004 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582005 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512006 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582007 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472008 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572009
2010 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2011 // it in now that we know. This allows us to find the entry when it commits.
2012 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232013 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332014 entry->set_site_instance(
2015 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572016 }
[email protected]216813952011-05-19 22:21:262017 }
2018}
2019
[email protected]b172aee2012-04-10 17:05:262020void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2021 int maximum_percent,
2022 bool remember) {
[email protected]216813952011-05-19 22:21:262023 minimum_zoom_percent_ = minimum_percent;
2024 maximum_zoom_percent_ = maximum_percent;
2025 temporary_zoom_settings_ = !remember;
2026}
2027
[email protected]20b433a2012-05-15 21:23:462028void WebContentsImpl::OnSaveURL(const GURL& url,
2029 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482030 download_stats::RecordDownloadSource(
2031 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262032 // Check if the URL to save matches the URL of the main frame. Since this
2033 // message originates from Pepper plugins, it may not be the case if the
2034 // plugin is an embedded element.
2035 GURL main_frame_url = GetURL();
2036 if (!main_frame_url.is_valid())
2037 return;
2038 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462039 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272040}
2041
[email protected]b172aee2012-04-10 17:05:262042void WebContentsImpl::OnEnumerateDirectory(int request_id,
2043 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592044 ChildProcessSecurityPolicyImpl* policy =
2045 ChildProcessSecurityPolicyImpl::GetInstance();
2046 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2047 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212048}
2049
[email protected]b172aee2012-04-10 17:05:262050void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512051 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202052}
2053
[email protected]b172aee2012-04-10 17:05:262054void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2055 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362056 const string16& title,
2057 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592058 ChildProcessSecurityPolicyImpl* policy =
2059 ChildProcessSecurityPolicyImpl::GetInstance();
2060 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2061 return;
[email protected]3a3b75a2012-06-01 08:38:362062 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202063}
2064
[email protected]b172aee2012-04-10 17:05:262065void WebContentsImpl::OnFindReply(int request_id,
2066 int number_of_matches,
2067 const gfx::Rect& selection_rect,
2068 int active_match_ordinal,
2069 bool final_update) {
[email protected]6934a702011-12-20 00:04:512070 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2071 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002072 // Send a notification to the renderer that we are ready to receive more
2073 // results from the scoping effort of the Find operation. The FindInPage
2074 // scoping is asynchronous and periodically sends results back up to the
2075 // browser using IPC. In an effort to not spam the browser we have the
2076 // browser send an ACK for each FindReply message and have the renderer
2077 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582078 GetRenderViewHostImpl()->Send(
2079 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162080}
2081
[email protected]b172aee2012-04-10 17:05:262082void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442083 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2084 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452085}
2086
[email protected]b172aee2012-04-10 17:05:262087void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2088 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102089 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252090 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102091 AppCacheAccessed(manifest_url, blocked_by_policy));
2092}
2093
[email protected]b172aee2012-04-10 17:05:262094void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322095 SkColor color) {
[email protected]da8543762012-03-20 08:52:202096 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2097}
2098
[email protected]b172aee2012-04-10 17:05:262099void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202100 if (color_chooser_ &&
2101 color_chooser_id == color_chooser_->identifier())
2102 color_chooser_->End();
2103}
2104
[email protected]b172aee2012-04-10 17:05:262105void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322106 SkColor color) {
[email protected]da8543762012-03-20 08:52:202107 if (color_chooser_ &&
2108 color_chooser_id == color_chooser_->identifier())
2109 color_chooser_->SetSelectedColor(color);
2110}
2111
[email protected]9f2a9d72012-04-16 16:02:222112void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2113 const FilePath& path,
2114 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2116 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292117}
2118
[email protected]d0759f492012-04-19 22:50:502119// This exists for render views that don't have a WebUI, but do have WebUI
2120// bindings enabled.
2121void WebContentsImpl::OnWebUISend(const GURL& source_url,
2122 const std::string& name,
2123 const base::ListValue& args) {
2124 if (delegate_)
2125 delegate_->WebUISend(this, source_url, name, args);
2126}
2127
[email protected]96d185d2009-04-24 03:28:542128// Notifies the RenderWidgetHost instance about the fact that the page is
2129// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262130void WebContentsImpl::SetIsLoading(bool is_loading,
2131 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542132 if (is_loading == is_loading_)
2133 return;
2134
2135 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212136 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542137 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562138 upload_size_ = 0;
2139 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542140 }
2141
2142 render_manager_.SetIsLoading(is_loading);
2143
2144 is_loading_ = is_loading;
2145 waiting_for_response_ = is_loading;
2146
[email protected]6ebdc9b2010-09-27 16:55:572147 if (delegate_)
2148 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462149 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542150
[email protected]432115822011-07-10 15:52:272151 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2152 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072153 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542154 if (details)
[email protected]6c2381d2011-10-19 02:52:532155 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072156 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502157 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542158 det);
2159}
2160
[email protected]b172aee2012-04-10 17:05:262161void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132162 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322163 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562164 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382165 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442166 // that opened the window, as long as both renderers have the same
2167 // privileges.
[email protected]1fd1a502011-03-30 16:55:562168 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562169 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582170 // web_ui might be NULL if the URL refers to a non-existent extension.
2171 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402172 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522173 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442174 }
2175 }
[email protected]1fd1a502011-03-30 16:55:562176 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442177 }
2178
[email protected]4e697b042011-07-08 06:44:562179 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322180 // Clear the status bubble. This is a workaround for a bug where WebKit
2181 // doesn't let us know that the cursor left an element during a
2182 // transition (this is also why the mouse cursor remains as a hand after
2183 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2184 // clear the bubble when a user navigates to a named anchor in the same
2185 // page.
[email protected]36fc0392011-12-25 03:59:512186 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322187 }
2188
[email protected]a6e82fc2010-02-24 22:28:142189 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472190 // Once the main frame is navigated, we're no longer considered to have
2191 // displayed insecure content.
2192 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172193 }
[email protected]ce5c4502009-05-06 16:46:112194
[email protected]3c9e1872010-11-18 16:17:492195 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252196 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042197 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322198}
2199
[email protected]b172aee2012-04-10 17:05:262200void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322201 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132202 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322203 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062204 // If we navigate off the page, reset JavaScript state. This does nothing
2205 // to prevent a malicious script from spamming messages, since the script
2206 // could just reload the page to stop blocking.
2207 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552208 dialog_creator_->ResetJavaScriptState(this);
2209 dialog_creator_ = NULL;
2210 }
[email protected]420ae012009-04-24 05:16:322211
[email protected]3c9e1872010-11-18 16:17:492212 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252213 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042214 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462218 // If we are creating a RVH for a restored controller, then we need to make
2219 // sure the RenderView starts with a next_page_id_ larger than the number
2220 // of restored entries. This must be called before the RenderView starts
2221 // navigating (to avoid a race between the browser updating max_page_id and
2222 // the renderer updating next_page_id_). Because of this, we only call this
2223 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562224 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582225 if (max_restored_page_id >
2226 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2227 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2228 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322229}
2230
[email protected]b172aee2012-04-10 17:05:262231bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2232 const string16& title) {
[email protected]420ae012009-04-24 05:16:322233 // For file URLs without a title, use the pathname instead. In the case of a
2234 // synthesized title, we don't want the update to count toward the "one set
2235 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512236 string16 final_title;
[email protected]420ae012009-04-24 05:16:322237 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512238 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2239 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322240 explicit_set = false; // Don't count synthetic titles toward the set limit.
2241 } else {
[email protected]acafd272011-07-26 17:35:572242 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322243 explicit_set = true;
2244 }
2245
[email protected]987fc3a2011-05-26 14:18:092246 // If a page is created via window.open and never navigated,
2247 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552248 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092249 if (entry) {
[email protected]36fc0392011-12-25 03:59:512250 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092251 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322252
[email protected]36fc0392011-12-25 03:59:512253 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092254 } else {
2255 if (page_title_when_no_navigation_entry_ == final_title)
2256 return false; // Nothing changed, don't bother.
2257
2258 page_title_when_no_navigation_entry_ = final_title;
2259 }
[email protected]420ae012009-04-24 05:16:322260
[email protected]420ae012009-04-24 05:16:322261 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232262 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322263
[email protected]2bb171882012-03-07 02:09:462264 std::pair<content::NavigationEntry*, bool> details =
2265 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142266
[email protected]ad50def52011-10-19 23:17:072267 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442268 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2269 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462270 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042271
[email protected]420ae012009-04-24 05:16:322272 return true;
2273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322276 // After sending out a swap notification, we need to send a disconnect
2277 // notification so that clients that pick up a pointer to |this| can NULL the
2278 // pointer. See Bug 1230284.
2279 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072280 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202281 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2282 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072283 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322284}
2285
[email protected]b172aee2012-04-10 17:05:262286void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322287 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072288 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122289 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2290 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072291 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322292}
2293
[email protected]b172aee2012-04-10 17:05:262294void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322295 if (!notify_disconnection_)
2296 return;
2297
2298 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072299 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322300 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2301 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072302 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322303}
2304
[email protected]5a3bdf52012-05-24 15:12:572305RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2306 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322307}
2308
[email protected]8d3347f2009-07-09 22:00:212309RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262310WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212311 return &render_manager_;
2312}
2313
[email protected]b172aee2012-04-10 17:05:262314content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372315 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462316 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512317}
2318
[email protected]b172aee2012-04-10 17:05:262319WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172320 return this;
2321}
2322
[email protected]b172aee2012-04-10 17:05:262323gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172324 if (delegate_)
2325 return delegate_->GetRootWindowResizerRect();
2326 return gfx::Rect();
2327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442330 // Don't send notifications if we are just creating a swapped-out RVH for
2331 // the opener chain. These won't be used for view-source or WebUI, so it's
2332 // ok to return early.
2333 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2334 return;
2335
[email protected]ad50def52011-10-19 23:17:072336 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272337 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322338 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532339 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232340 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322341 if (!entry)
2342 return;
2343
2344 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352345 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562346 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582347 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322348
2349 if (entry->IsViewSourceMode()) {
2350 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582351 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2352 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322353 }
[email protected]0666aef2009-05-13 19:48:082354
[email protected]d487beefe2011-12-21 05:41:212355 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262356
2357 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252358 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]b172aee2012-04-10 17:05:262361void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522362 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322363 // Don't notify the world, since this came from a renderer in the
2364 // background.
2365 return;
2366 }
2367
2368 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312369 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232370 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302371
2372 // Restore the focus to the tab (otherwise the focus will be on the top
2373 // window).
[email protected]484ae5912010-09-29 19:16:142374 if (was_crashed && !FocusLocationBarByDefault() &&
2375 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302376 Focus();
[email protected]484ae5912010-09-29 19:16:142377 }
[email protected]32ded2212011-11-10 18:51:432378
[email protected]d8c660432011-12-22 20:51:252379 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322380}
2381
[email protected]b172aee2012-04-10 17:05:262382void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2383 base::TerminationStatus status,
2384 int error_code) {
[email protected]151a63d2011-12-20 22:32:522385 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322386 // The pending page's RenderViewHost is gone.
2387 return;
2388 }
2389
2390 SetIsLoading(false, NULL);
2391 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232392 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312393 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322394
[email protected]d8c660432011-12-22 20:51:252395 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272396 observers_,
[email protected]be1f56ab2011-12-22 06:55:312397 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322398}
2399
[email protected]b172aee2012-04-10 17:05:262400void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482401 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252402 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062403}
2404
[email protected]b172aee2012-04-10 17:05:262405void WebContentsImpl::DidNavigate(
2406 RenderViewHost* rvh,
2407 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582408 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322409 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372410
[email protected]434f69f2012-02-06 21:56:522411 // Update the site of the SiteInstance if it doesn't have one yet, unless
2412 // this is for about:blank. In that case, the SiteInstance can still be
2413 // considered unused until a navigation to a real page.
2414 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2415 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332416 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522417 }
[email protected]420ae012009-04-24 05:16:322418
2419 // Need to update MIME type here because it's referred to in
2420 // UpdateNavigationCommands() called by RendererDidNavigate() to
2421 // determine whether or not to enable the encoding menu.
2422 // It's updated only for the main frame. For a subframe,
2423 // RenderView::UpdateURL does not set params.contents_mime_type.
2424 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2425 // TODO(jungshik): Add a test for the encoding menu to avoid
2426 // regressing it again.
[email protected]2905f742011-10-13 03:51:582427 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322428 contents_mime_type_ = params.contents_mime_type;
2429
[email protected]8286f51a2011-05-31 17:39:132430 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002431 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392432
[email protected]a9c0bfe2010-09-17 08:35:222433 // Send notification about committed provisional loads. This notification is
2434 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2435 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082436 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072437 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2438 // that is not recorded in the navigation history. For the purpose of
2439 // tracking navigation events, we treat this event as a sub frame navigation
2440 // event.
2441 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582442 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222443 // Whether or not a page transition was triggered by going backward or
2444 // forward in the history is only stored in the navigation controller's
2445 // entry list.
2446 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512447 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582448 content::PAGE_TRANSITION_FORWARD_BACK)) {
2449 transition_type = content::PageTransitionFromInt(
2450 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222451 }
[email protected]0d60f0192011-04-14 12:40:102452 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102454 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462455 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222456 }
2457
[email protected]76543b92009-08-31 17:27:452458 if (!did_navigate)
2459 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322460
2461 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2462 // for the appropriate notification (best) or you can add it to
2463 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2464 // necessary, please).
2465
2466 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002467 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322468 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512469 if (delegate_)
2470 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002471 }
[email protected]420ae012009-04-24 05:16:322472 DidNavigateAnyFramePostCommit(rvh, details, params);
2473}
2474
[email protected]b172aee2012-04-10 17:05:262475void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2476 int32 page_id,
2477 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152478 // Ensure that this state update comes from either the active RVH or one of
2479 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522480 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322481
2482 // We must be prepared to handle state updates for any page, these occur
2483 // when the user is scrolling and entering form data, as well as when we're
2484 // leaving a page, in which case our state may have already been moved to
2485 // the next page. The navigation controller will look up the appropriate
2486 // NavigationEntry and update it when it is notified via the delegate.
2487
2488 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582489 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322490 if (entry_index < 0)
2491 return;
[email protected]10f417c52011-12-28 21:04:232492 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322493
[email protected]36fc0392011-12-25 03:59:512494 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322495 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512496 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322497 controller_.NotifyEntryChanged(entry, entry_index);
2498}
2499
[email protected]b172aee2012-04-10 17:05:262500void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2501 int32 page_id,
2502 const string16& title,
2503 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322504 // If we have a title, that's a pretty good indication that we've started
2505 // getting useful data.
2506 SetNotWaitingForResponse();
2507
[email protected]73eb2602012-02-09 19:50:552508 // Try to find the navigation entry, which might not be the current one.
2509 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232510 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582511 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092512
[email protected]73eb2602012-02-09 19:50:552513 // We can handle title updates when we don't have an entry in
2514 // UpdateTitleForEntry, but only if the update is from the current RVH.
2515 if (!entry && rvh != GetRenderViewHost())
2516 return;
2517
[email protected]a49e10b2011-08-01 23:57:462518 // TODO(evan): make use of title_direction.
2519 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092520 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322521 return;
2522
2523 // Broadcast notifications when the UI should be updated.
2524 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462525 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322526}
2527
[email protected]b172aee2012-04-10 17:05:262528void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2529 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312530 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322531}
2532
[email protected]b172aee2012-04-10 17:05:262533void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512534 if (delegate_)
2535 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322536}
2537
[email protected]b172aee2012-04-10 17:05:262538void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292539 // The UI may be in an event-tracking loop, such as between the
2540 // mouse-down and mouse-up in text selection or a button click.
2541 // Defer the close until after tracking is complete, so that we
2542 // don't free objects out from under the UI.
2543 // TODO(shess): This could probably be integrated with the
2544 // IsDoingDrag() test below. Punting for now because I need more
2545 // research to understand how this impacts platforms other than Mac.
2546 // TODO(shess): This could get more fine-grained. For instance,
2547 // closing a tab in another window while selecting text in the
2548 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212549 if (GetView()->IsEventTracking()) {
2550 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292551 return;
2552 }
2553
[email protected]24a4d1062009-07-10 23:10:422554 // If we close the tab while we're in the middle of a drag, we'll crash.
2555 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212556 if (GetView()->IsDoingDrag()) {
2557 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422558 return;
2559 }
2560
[email protected]420ae012009-04-24 05:16:322561 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522562 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512563 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522567 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512568 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512572 if (delegate_ && delegate_->IsPopupOrPanel(this))
2573 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322577 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492578
[email protected]82114f52012-03-20 22:53:412579 if (delegate_ && content_restrictions_)
2580 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492581
2582 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252583 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322584}
2585
[email protected]b172aee2012-04-10 17:05:262586void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322587 scoped_ptr<LoadNotificationDetails> details;
2588
[email protected]10f417c52011-12-28 21:04:232589 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322590 // An entry may not exist for a stop when loading an initial blank page or
2591 // if an iframe injected by script into a blank page finishes loading.
2592 if (entry) {
[email protected]420ae012009-04-24 05:16:322593 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2594
2595 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512596 entry->GetVirtualURL(),
2597 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322598 elapsed,
2599 &controller_,
2600 controller_.GetCurrentEntryIndex()));
2601 }
2602
[email protected]420ae012009-04-24 05:16:322603 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492604
2605 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252606 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162610 controller_.DiscardNonCommittedEntries();
2611
2612 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462613 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162614}
2615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512617 if (delegate_)
2618 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402619}
2620
[email protected]87717d0e2012-04-26 02:58:432621void WebContentsImpl::DocumentAvailableInMainFrame(
2622 RenderViewHost* render_view_host) {
2623 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2624 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102625}
2626
[email protected]b172aee2012-04-10 17:05:262627void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082628 RenderViewHost* render_view_host,
2629 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072630 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272631 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322632 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532633 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082634}
2635
[email protected]196159d2012-05-04 17:26:542636void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2637 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262638 const content::Referrer& referrer,
2639 WindowOpenDisposition disposition,
2640 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542641 // If this came from a swapped out RenderViewHost, we only allow the request
2642 // if we are still in the same BrowsingInstance.
2643 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2644 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2645 return;
2646 }
2647
[email protected]4ad5d77d2011-12-03 02:00:482648 // Delegate to RequestTransferURL because this is just the generic
2649 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582650 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482651 GlobalRequestID());
2652}
2653
[email protected]b172aee2012-04-10 17:05:262654void WebContentsImpl::RequestTransferURL(
2655 const GURL& url,
2656 const content::Referrer& referrer,
2657 WindowOpenDisposition disposition,
2658 int64 source_frame_id,
2659 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202660 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582661 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582662 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352663 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322664 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2665 // generated suggestions).
2666 //
[email protected]e0112912011-02-02 22:54:352667 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162668 // want web sites to see a referrer of "chrome://blah" (and some
2669 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322670 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432671 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222672 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482673 false /* is_renderer_initiated */);
2674 params.transferred_global_request_id = old_request_id;
2675 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222676 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322677 } else {
[email protected]6bf6a6b52012-02-03 15:41:432678 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482679 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2680 params.transferred_global_request_id = old_request_id;
2681 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582682 }
2683 if (new_contents) {
2684 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252685 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582686 DidOpenRequestedURL(new_contents,
2687 url,
2688 referrer,
2689 disposition,
2690 transition_type,
2691 source_frame_id));
[email protected]420ae012009-04-24 05:16:322692 }
2693}
2694
[email protected]e1c3a552012-05-04 20:51:322695void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2696 // Tell the active RenderViewHost to run unload handlers and close, as long
2697 // as the request came from a RenderViewHost in the same BrowsingInstance.
2698 // In most cases, we receive this from a swapped out RenderViewHost.
2699 // It is possible to receive it from one that has just been swapped in,
2700 // in which case we might as well deliver the message anyway.
2701 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2702 GetRenderViewHost()->ClosePage();
2703}
2704
[email protected]f546640b2012-05-15 00:03:492705void WebContentsImpl::RouteMessageEvent(
2706 RenderViewHost* rvh,
2707 const ViewMsg_PostMessage_Params& params) {
2708 // Only deliver the message to the active RenderViewHost if the request
2709 // came from a RenderViewHost in the same BrowsingInstance.
2710 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2711 return;
2712
2713 ViewMsg_PostMessage_Params new_params(params);
2714
2715 // If there is a source_routing_id, translate it to the routing ID for
2716 // the equivalent swapped out RVH in the target process. If we need
2717 // to create a swapped out RVH for the source tab, we create its opener
2718 // chain as well, since those will also be accessible to the target page.
2719 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2720 // Try to look up the WebContents for the source page.
2721 WebContentsImpl* source_contents = NULL;
2722 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2723 rvh->GetProcess()->GetID(), params.source_routing_id);
2724 if (source_rvh) {
2725 source_contents = static_cast<WebContentsImpl*>(
2726 source_rvh->GetDelegate()->GetAsWebContents());
2727 }
2728
2729 if (source_contents) {
2730 new_params.source_routing_id =
2731 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2732 } else {
2733 // We couldn't find it, so don't pass a source frame.
2734 new_params.source_routing_id = MSG_ROUTING_NONE;
2735 }
2736 }
2737
2738 // In most cases, we receive this from a swapped out RenderViewHost.
2739 // It is possible to receive it from one that has just been swapped in,
2740 // in which case we might as well deliver the message anyway.
2741 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2742 GetRenderViewHost()->GetRoutingID(), new_params));
2743}
2744
[email protected]b172aee2012-04-10 17:05:262745void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342746 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412747 const string16& message,
2748 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322749 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142750 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322751 IPC::Message* reply_msg,
2752 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072753 // Suppress JavaScript dialogs when requested. Also suppress messages when
2754 // showing an interstitial as it's shown over the previous page and we don't
2755 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502756 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582757 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272758 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072759 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522760 delegate_->ShouldSuppressDialogs() ||
2761 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322762
2763 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432764 std::string accept_lang = content::GetContentClient()->browser()->
2765 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552766 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522767 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432768 this,
2769 frame_url.GetOrigin(),
2770 accept_lang,
2771 javascript_message_type,
2772 message,
[email protected]51da7e32012-01-30 19:24:522773 default_prompt,
[email protected]b172aee2012-04-10 17:05:262774 base::Bind(&WebContentsImpl::OnDialogClosed,
2775 base::Unretained(this),
2776 rvh,
2777 reply_msg),
[email protected]51da7e32012-01-30 19:24:522778 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322779 }
[email protected]3ab9cb82011-06-03 18:02:072780
2781 if (suppress_this_message) {
2782 // If we are suppressing messages, just reply as if the user immediately
2783 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342784 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072785 }
2786
2787 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322788}
2789
[email protected]b172aee2012-04-10 17:05:262790void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2791 const string16& message,
2792 bool is_reload,
2793 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582794 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512795 if (delegate_)
2796 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072797
2798 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582799 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072800 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522801 delegate_->ShouldSuppressDialogs() ||
2802 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152803 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342804 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582805 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502806 return;
2807 }
[email protected]3ab9cb82011-06-03 18:02:072808
[email protected]7ab1e7d62009-10-14 23:32:012809 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552810 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522811 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322812 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262813 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522814 reply_msg));
[email protected]420ae012009-04-24 05:16:322815}
2816
[email protected]a796f202012-05-30 14:14:252817bool WebContentsImpl::AddMessageToConsole(int32 level,
2818 const string16& message,
2819 int32 line_no,
2820 const string16& source_id) {
2821 if (!delegate_)
2822 return false;
2823 return delegate_->AddMessageToConsole(this, level, message, line_no,
2824 source_id);
2825}
2826
[email protected]b172aee2012-04-10 17:05:262827WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332828 // We want to base the page config off of the real URL, rather than the
2829 // display URL.
2830 GURL url = controller_.GetActiveEntry()
2831 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2832 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322833}
2834
[email protected]b172aee2012-04-10 17:05:262835void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272836 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252837 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222838
[email protected]ea114722012-03-12 01:11:252839 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172840 if (rdh) // NULL in unittests.
2841 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252842}
2843
[email protected]b172aee2012-04-10 17:05:262844void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442845 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252846 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442847}
2848
[email protected]b172aee2012-04-10 17:05:262849void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2850 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152851 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522852 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152853 return;
2854
[email protected]9f76c1e2012-03-05 15:15:582855 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2856
[email protected]e5fc1632011-08-08 07:51:532857 // Ignore renderer unresponsive event if debugger is attached to the tab
2858 // since the event may be a result of the renderer sitting on a breakpoint.
2859 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442860 DevToolsAgentHost* agent =
2861 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2862 if (agent &&
2863 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532864 return;
2865
[email protected]420ae012009-04-24 05:16:322866 if (is_during_unload) {
2867 // Hang occurred while firing the beforeunload/unload handler.
2868 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582869 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322870
2871 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2872 return;
2873
2874 // If the tab hangs in the beforeunload/unload handler there's really
2875 // nothing we can do to recover. Pretend the unload listeners have
2876 // all fired and close the tab. If the hang is in the beforeunload handler
2877 // then the user will not have the option of cancelling the close.
2878 Close(rvh);
2879 return;
2880 }
2881
[email protected]9f76c1e2012-03-05 15:15:582882 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472883 return;
2884
[email protected]6934a702011-12-20 00:04:512885 if (delegate_)
2886 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322887}
2888
[email protected]b172aee2012-04-10 17:05:262889void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512890 if (delegate_)
2891 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322892}
2893
[email protected]b172aee2012-04-10 17:05:262894void WebContentsImpl::LoadStateChanged(
2895 const GURL& url,
2896 const net::LoadStateWithParam& load_state,
2897 uint64 upload_position,
2898 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322899 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562900 upload_position_ = upload_position;
2901 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502902 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202903 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302904 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212905 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322906 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462907 if (IsLoading()) {
2908 NotifyNavigationStateChanged(
2909 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2910 }
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]b172aee2012-04-10 17:05:262913void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512914 if (delegate_)
2915 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252916}
2917
[email protected]b172aee2012-04-10 17:05:262918void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322919 bool proceed,
2920 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512921 if (delegate_)
2922 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322923}
2924
[email protected]b172aee2012-04-10 17:05:262925void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542926 RenderViewHost* render_view_host) {
2927 DidStartLoading();
2928}
2929
[email protected]b172aee2012-04-10 17:05:262930void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542931 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232932 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2933 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542934}
2935
[email protected]b172aee2012-04-10 17:05:262936void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102937 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262938 gfx::Size size = view_->GetContainerSize();
2939 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2940 // here during container initialization and normal window size will be set
2941 // later. In case of tab duplication this resizing to 0x0 prevents setting
2942 // normal size later so just ignore it.
2943 if (!size.IsEmpty())
2944 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322945}
2946
[email protected]b172aee2012-04-10 17:05:262947void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542948 NotifySwapped();
2949}
2950
[email protected]14392a52012-05-02 20:28:442951int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2952 SiteInstance* instance) {
2953 if (!opener_)
2954 return MSG_ROUTING_NONE;
2955
2956 // Recursively create RenderViews for anything else in the opener chain.
2957 return opener_->CreateOpenerRenderViews(instance);
2958}
2959
2960int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2961 int opener_route_id = MSG_ROUTING_NONE;
2962
2963 // If this tab has an opener, ensure it has a RenderView in the given
2964 // SiteInstance as well.
2965 if (opener_)
2966 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2967
2968 // Create a swapped out RenderView in the given SiteInstance if none exists,
2969 // setting its opener to the given route_id. Return the new view's route_id.
2970 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2971}
2972
[email protected]b172aee2012-04-10 17:05:262973NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202974 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542975}
2976
[email protected]b172aee2012-04-10 17:05:262977WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562978 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322979}
2980
[email protected]10f417c52011-12-28 21:04:232981NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262982 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322983 return controller_.GetLastCommittedEntry();
2984}
2985
[email protected]b172aee2012-04-10 17:05:262986bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442987 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442988 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322989 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522990
[email protected]420ae012009-04-24 05:16:322991 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442992 if (rwh_view)
2993 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322994
[email protected]74ce1ad2011-12-16 21:51:462995 // Make sure we use the correct starting page_id in the new RenderView.
2996 UpdateMaxPageIDIfNecessary(render_view_host);
2997 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582998 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462999
[email protected]7900bfdb2012-05-24 19:31:243000 std::string embedder_channel_name;
3001 int embedder_container_id;
3002 GetBrowserPluginEmbedderInfo(render_view_host,
3003 &embedder_channel_name,
3004 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583005 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493006 render_view_host)->CreateRenderView(string16(),
3007 opener_route_id,
3008 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243009 embedder_channel_name,
3010 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523011 return false;
[email protected]14392a52012-05-02 20:28:443012 }
[email protected]a4127722011-04-27 23:13:523013
[email protected]e60c0232011-11-11 19:56:353014#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503015 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3016 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443017 if (rwh_view) {
3018 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3019 render_widget_host->WasResized();
3020 }
[email protected]f8233cc2011-05-31 20:24:503021#endif
3022
[email protected]420ae012009-04-24 05:16:323023 return true;
3024}
3025
[email protected]b172aee2012-04-10 17:05:263026void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3027 IPC::Message* reply_msg,
3028 bool success,
3029 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543030 if (is_showing_before_unload_dialog_ && !success) {
3031 // If a beforeunload dialog is canceled, we need to stop the throbber from
3032 // spinning, since we forced it to start spinning in Navigate.
3033 DidStopLoading();
3034
[email protected]3bbacc5b2012-04-17 17:46:153035 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543036 }
3037 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583038 static_cast<RenderViewHostImpl*>(
3039 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543040}
3041
[email protected]b172aee2012-04-10 17:05:263042void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123043 encoding_ = content::GetContentClient()->browser()->
3044 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103045}
[email protected]f45d2a72010-03-08 23:28:353046
[email protected]b172aee2012-04-10 17:05:263047void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463048 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263049 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573050 DownloadManager* dlm =
3051 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143052 if (!dlm)
3053 return;
3054 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263055 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143056 const NavigationEntry* entry = controller_.GetActiveEntry();
3057 if (entry)
3058 post_id = entry->GetPostID();
3059 }
[email protected]29a5ffc82012-03-13 19:35:583060 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143061 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143062 scoped_ptr<DownloadUrlParameters> params(
3063 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493064 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143065 params->set_post_id(post_id);
3066 params->set_prefer_cache(true);
3067 if (post_id >= 0)
3068 params->set_method("POST");
3069 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143070}
3071
[email protected]b172aee2012-04-10 17:05:263072void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213073 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443074 // Can be NULL during tests.
3075 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213076 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363077}
[email protected]9f76c1e2012-03-05 15:15:583078
[email protected]b172aee2012-04-10 17:05:263079RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583080 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3081}
[email protected]7900bfdb2012-05-24 19:31:243082
3083void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3084 content::RenderViewHost* render_view_host,
3085 std::string* embedder_channel_name,
3086 int* embedder_container_id) {
3087 content::RenderProcessHost* embedder_render_process_host =
3088 browser_plugin_host()->embedder_render_process_host();
3089 *embedder_container_id = browser_plugin_host()->instance_id();
3090 int embedder_process_id =
3091 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3092 if (embedder_process_id != -1) {
3093 *embedder_channel_name =
3094 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3095 embedder_process_id);
3096 }
3097}