blob: df91c8e019d23bb7f256f9c09695f709d135c78a [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]14cf0f12012-06-18 17:15:5718#include "content/browser/browser_plugin/old/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5919#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4420#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0421#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4622#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1223#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1624#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3225#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5426#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0527#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0028#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5031#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2532#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5740#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2043#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1746#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1447#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4648#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1549#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0050#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2751#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0052#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3753#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1454#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3255#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3856#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4257#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2558#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1059#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5060#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2161#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4862#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1863#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5464#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0365#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1666#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2967#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5468#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3469#include "net/url_request/url_request_context_getter.h"
[email protected]302fe422012-06-11 14:49:1170#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3771#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5672#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4173#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0174#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4175#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2476#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3677#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3178#include "webkit/glue/webpreferences.h"
79
[email protected]f66df822012-05-18 16:52:1780#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5081#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5783#endif
[email protected]3e45ba92009-02-20 21:09:0084
[email protected]420ae012009-04-24 05:16:3285// Cross-Site Navigations
86//
[email protected]b172aee2012-04-10 17:05:2687// If a WebContentsImpl is told to navigate to a different web site (as
88// determined by SiteInstance), it will replace its current RenderViewHost with
89// a new RenderViewHost dedicated to the new SiteInstance. This works as
90// follows:
[email protected]420ae012009-04-24 05:16:3291//
92// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4693// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3294// - The pending RVH is "suspended," so that no navigation messages are sent to
95// its renderer until the onbeforeunload JavaScript handler has a chance to
96// run in the current RVH.
97// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
98// that it has a pending cross-site request. ResourceDispatcherHost will
99// check for this when the response arrives.
100// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46101// cancel all the pending logic. Otherwise we allow the pending RVH to send
102// the navigation request to its renderer.
103// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
104// main resource load on the pending RVH. It checks CrossSiteRequestManager
105// to see that it is a cross-site request, and installs a
106// CrossSiteResourceHandler.
107// - When RDH receives a response, the BufferedResourceHandler determines
108// whether it is a download. If so, it sends a message to the new renderer
109// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26110// pending RVH remains until the next DidNavigate event for this
111// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32112// - After RDH receives a response and determines that it is safe and not a
113// download, it pauses the response to first run the old page's onunload
114// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26115// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32116// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15117// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32118// the ResourceDispatcherHost, who unpauses the response. Data is then sent
119// to the pending RVH.
120// - The pending renderer sends a FrameNavigate message that invokes the
121// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46122// pending RVH.
[email protected]992db4c2011-05-12 15:37:15123// - The previous renderer is kept swapped out in RenderViewHostManager in case
124// the user goes back. The process only stays live if another tab is using
125// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32126
[email protected]b441a8492012-06-06 14:55:57127using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44128using content::DevToolsAgentHost;
129using content::DevToolsAgentHostRegistry;
130using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17131using content::DownloadItem;
132using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14133using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20134using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56135using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13136using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27137using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54138using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50139using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23140using content::NavigationEntry;
141using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20142using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11143using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57144using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57145using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27146using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11147using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50148using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58149using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04150using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25151using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14152using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43153using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33154using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38155using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09156using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25157using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56158using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22159using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50160using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25161using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44162
[email protected]420ae012009-04-24 05:16:32163namespace {
164
165// Amount of time we wait between when a key event is received and the renderer
166// is queried for its state and pushed to the NavigationEntry.
167const int kQueryStateDelay = 5000;
168
[email protected]6ebdc9b2010-09-27 16:55:57169const int kSyncWaitDelay = 40;
170
[email protected]82114f52012-03-20 22:53:41171const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05172
[email protected]420ae012009-04-24 05:16:32173#if defined(OS_WIN)
174
175BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
176 // Note: erase is required to properly paint some widgets borders. This can
177 // be seen with textfields.
178 InvalidateRect(hwnd, NULL, TRUE);
179 return TRUE;
180}
181#endif
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23184 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16186 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47189 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47191 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16192 break; // Fall through to rest of function.
193 }
[email protected]5e369672009-11-03 23:48:30194
[email protected]59246c572012-02-10 13:32:13195 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
196 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23197 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13198 browser_context->DidLastSessionExitCleanly()) {
199 if (entry.GetHasPostData())
200 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13202 }
[email protected]5e369672009-11-03 23:48:30203
[email protected]2c5569662011-03-22 20:45:02204 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30205}
206
[email protected]10f417c52011-12-28 21:04:23207void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47208 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42209 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50210 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24211 const std::string& embedder_channel_name,
212 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16213 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51214 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54215 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55216 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
217 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51218 params->url = entry.GetURL();
219 params->referrer = entry.GetReferrer();
220 params->transition = entry.GetTransitionType();
221 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00222 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55223 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34224 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47225 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48226 params->transferred_request_child_id =
227 entry.transferred_global_request_id().child_id;
228 params->transferred_request_request_id =
229 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22230 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00231 // Avoid downloading when in view-source mode.
232 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24233 params->embedder_channel_name = embedder_channel_name;
234 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47235
236 if (delegate)
237 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34238}
239
[email protected]f98f5092012-05-19 00:08:14240int GetSwitchValueAsInt(
241 const CommandLine& command_line,
242 const std::string& switch_string,
243 int min_value) {
244 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
245 int int_value;
246 if (base::StringToInt(string_value, &int_value))
247 return std::max(min_value, int_value);
248 else
249 return min_value;
250}
251
[email protected]420ae012009-04-24 05:16:32252} // namespace
253
[email protected]a81343d232011-12-27 07:39:20254namespace content {
255
256WebContents* WebContents::Create(
257 BrowserContext* browser_context,
258 SiteInstance* site_instance,
259 int routing_id,
[email protected]b172aee2012-04-10 17:05:26260 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20261 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26262 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43263 browser_context,
264 site_instance,
265 routing_id,
[email protected]b172aee2012-04-10 17:05:26266 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44267 NULL,
[email protected]adbfb8df2012-02-24 01:19:43268 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20269}
[email protected]746d3052012-05-22 15:15:47270
[email protected]299d7f12012-05-23 05:31:15271WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47272 return rvh->GetDelegate()->GetAsWebContents();
273}
274
[email protected]a81343d232011-12-27 07:39:20275}
[email protected]f4f50ef2011-01-21 19:01:19276
[email protected]b172aee2012-04-10 17:05:26277// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32278
[email protected]b172aee2012-04-10 17:05:26279WebContentsImpl::WebContentsImpl(
280 content::BrowserContext* browser_context,
281 SiteInstance* site_instance,
282 int routing_id,
283 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44284 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26285 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42286 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07287 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37288 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57289 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44290 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05291 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34292 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23293 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
294 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34295 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21296 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56297 upload_size_(0),
298 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47299 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57300 capturing_contents_(false),
301 is_being_destroyed_(false),
302 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55303 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57304#if defined(OS_WIN)
305 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
306#endif
[email protected]7ab1e7d62009-10-14 23:32:01307 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56308 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38309 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25310 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01311 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25312 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01313 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00314 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43315 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20316 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37317 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32318
[email protected]38b098f2012-03-14 21:11:57319 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57320 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
321 if (view_.get()) {
322 CHECK(render_view_host_delegate_view_);
323 } else {
[email protected]38b098f2012-03-14 21:11:57324 content::WebContentsViewDelegate* delegate =
325 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
326 this);
[email protected]5a3bdf52012-05-24 15:12:57327 view_.reset(CreateWebContentsView(
328 this, delegate, &render_view_host_delegate_view_));
329 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57330 }
331 CHECK(view_.get());
332
[email protected]ca13a442012-04-17 14:00:12333 // We have the initial size of the view be based on the size of the view of
334 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26335 view_->CreateView(base_web_contents ?
336 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00337
[email protected]14392a52012-05-02 20:28:44338 // Listen for whether our opener gets destroyed.
339 if (opener_) {
340 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
341 content::Source<WebContents>(opener_));
342 }
343
[email protected]bafe6cd2012-05-23 23:09:50344 registrar_.Add(this,
345 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
346 content::NotificationService::AllBrowserContextsAndSources());
347
[email protected]483623eb2011-10-25 09:30:00348#if defined(ENABLE_JAVA_BRIDGE)
349 java_bridge_dispatcher_host_manager_.reset(
350 new JavaBridgeDispatcherHostManager(this));
351#endif
[email protected]172cf712012-05-23 15:07:39352
353 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35354}
initial.commit09911bf2008-07-26 23:55:29355
[email protected]b172aee2012-04-10 17:05:26356WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32357 is_being_destroyed_ = true;
358
[email protected]3ab9cb82011-06-03 18:02:07359 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55360 if (dialog_creator_)
361 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07362
[email protected]da8543762012-03-20 08:52:20363 if (color_chooser_)
364 color_chooser_->End();
365
[email protected]420ae012009-04-24 05:16:32366 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32367
[email protected]ca13a442012-04-17 14:00:12368 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07369 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09370 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
371 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07372 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32373
374 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07375#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32376 // If we still have a window handle, destroy it. GetNativeView can return
377 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42378 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52379 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58380 if (host && host->GetView())
381 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42382 }
[email protected]420ae012009-04-24 05:16:32383#endif
[email protected]7ab1e7d62009-10-14 23:32:01384
385 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15386 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01387 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15388 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01389 }
[email protected]b5a1d11c2011-02-17 03:09:42390
[email protected]2db9bd72012-04-13 20:20:56391 FOR_EACH_OBSERVER(WebContentsObserver,
392 observers_,
393 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08394
[email protected]6934a702011-12-20 00:04:51395 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42396}
397
[email protected]b172aee2012-04-10 17:05:26398WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
399 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54400 WebPreferences prefs;
401
402 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
403
404 prefs.developer_extras_enabled = true;
405 prefs.javascript_enabled =
406 !command_line.HasSwitch(switches::kDisableJavaScript);
407 prefs.web_security_enabled =
408 !command_line.HasSwitch(switches::kDisableWebSecurity);
409 prefs.plugins_enabled =
410 !command_line.HasSwitch(switches::kDisablePlugins);
411 prefs.java_enabled =
412 !command_line.HasSwitch(switches::kDisableJava);
413
414 prefs.uses_page_cache =
415 command_line.HasSwitch(switches::kEnableFastback);
416 prefs.remote_fonts_enabled =
417 !command_line.HasSwitch(switches::kDisableRemoteFonts);
418 prefs.xss_auditor_enabled =
419 !command_line.HasSwitch(switches::kDisableXSSAuditor);
420 prefs.application_cache_enabled =
421 !command_line.HasSwitch(switches::kDisableApplicationCache);
422
423 prefs.local_storage_enabled =
424 !command_line.HasSwitch(switches::kDisableLocalStorage);
425 prefs.databases_enabled =
426 !command_line.HasSwitch(switches::kDisableDatabases);
427 prefs.webaudio_enabled =
428 !command_line.HasSwitch(switches::kDisableWebAudio);
429
430 prefs.experimental_webgl_enabled =
431 GpuProcessHost::gpu_enabled() &&
432 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
433 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
434
[email protected]5a073092012-06-08 00:42:51435 prefs.flash_3d_enabled =
436 GpuProcessHost::gpu_enabled() &&
437 !command_line.HasSwitch(switches::kDisableFlash3d);
438 prefs.flash_stage3d_enabled =
439 GpuProcessHost::gpu_enabled() &&
440 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19441
[email protected]64d69de42012-02-06 00:19:54442 prefs.gl_multisampling_enabled =
443 !command_line.HasSwitch(switches::kDisableGLMultisampling);
444 prefs.privileged_webgl_extensions_enabled =
445 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
446 prefs.site_specific_quirks_enabled =
447 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
448 prefs.allow_file_access_from_file_urls =
449 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
450 prefs.show_composited_layer_borders =
451 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
452 prefs.show_composited_layer_tree =
453 command_line.HasSwitch(switches::kShowCompositedLayerTree);
454 prefs.show_fps_counter =
455 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19456 prefs.show_paint_rects =
457 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54458 prefs.accelerated_compositing_enabled =
459 GpuProcessHost::gpu_enabled() &&
460 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54461 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23462 command_line.HasSwitch(switches::kForceCompositingMode) &&
463 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54464 prefs.fixed_position_compositing_enabled =
465 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
466 prefs.accelerated_2d_canvas_enabled =
467 GpuProcessHost::gpu_enabled() &&
468 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58469 prefs.deferred_2d_canvas_enabled =
[email protected]7aca2362012-07-10 20:17:08470 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54471 prefs.accelerated_painting_enabled =
472 GpuProcessHost::gpu_enabled() &&
473 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
474 prefs.accelerated_filters_enabled =
475 GpuProcessHost::gpu_enabled() &&
476 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
477 prefs.accelerated_layers_enabled =
478 prefs.accelerated_animation_enabled =
479 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54480 prefs.accelerated_plugins_enabled =
481 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
482 prefs.accelerated_video_enabled =
483 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54484 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]d849b122012-07-18 07:35:26492#if defined(OS_ANDROID)
493 prefs.device_supports_mouse = false;
494#endif
[email protected]64d69de42012-02-06 00:19:54495
496#if defined(OS_MACOSX)
497 bool default_enable_scroll_animator = true;
498#else
499 // On CrOS, the launcher always passes in the --enable flag.
500 bool default_enable_scroll_animator = false;
501#endif
502 prefs.enable_scroll_animator = default_enable_scroll_animator;
503 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
504 prefs.enable_scroll_animator = true;
505 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
506 prefs.enable_scroll_animator = false;
507
508 prefs.visual_word_movement_enabled =
509 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54510
511 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32512 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54513 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11514 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
515 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54516 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11517 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54518 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19519 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
520 prefs.flash_3d_enabled = false;
521 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
522 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11523 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54524 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11525 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54526 prefs.gl_multisampling_enabled = false;
527
528 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45529 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32530 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54531 prefs.accelerated_video_enabled = false;
532 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45533 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09534 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54535 }
536 }
537
[email protected]b9535422012-02-09 01:47:59538 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58539 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54540 prefs.loads_images_automatically = true;
541 prefs.javascript_enabled = true;
542 }
543
544 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
545
546 // Force accelerated compositing and 2d canvas off for chrome:, about: and
547 // chrome-devtools: pages (unless it's specifically allowed).
548 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54549 url.SchemeIs(chrome::kChromeUIScheme) ||
550 (url.SchemeIs(chrome::kAboutScheme) &&
551 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25552 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54553 prefs.accelerated_compositing_enabled = false;
554 prefs.accelerated_2d_canvas_enabled = false;
555 }
[email protected]43d9d782012-03-01 15:40:09556
[email protected]302fe422012-06-11 14:49:11557#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
558 prefs.threaded_animation_enabled =
559 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
560 prefs.per_tile_painting_enabled =
561 command_line.HasSwitch(switches::kEnablePerTilePainting);
562 prefs.partial_swap_enabled =
563 command_line.HasSwitch(switches::kEnablePartialSwap);
564#endif
565
[email protected]f98f5092012-05-19 00:08:14566 if (command_line.HasSwitch(switches::kDefaultTileWidth))
567 prefs.default_tile_width =
568 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
569 if (command_line.HasSwitch(switches::kDefaultTileHeight))
570 prefs.default_tile_height =
571 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
572 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
573 prefs.max_untiled_layer_width =
574 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
575 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
576 prefs.max_untiled_layer_height =
577 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
578
[email protected]2486dce2012-05-23 17:18:19579 if (gfx::Screen::IsDIPEnabled()) {
580 // Only apply when using DIP coordinate system as this setting interferes
581 // with fixed layout mode.
582 prefs.apply_default_device_scale_factor_in_compositor = true;
583 }
584
[email protected]96bcdc102012-05-24 23:42:10585 prefs.fixed_position_creates_stacking_context =
586 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
587
[email protected]6b4dcb072012-06-18 22:26:51588 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
589
[email protected]2e21fe292012-03-02 22:52:32590 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54591
592 return prefs;
593}
594
[email protected]b172aee2012-04-10 17:05:26595NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20596 return controller_;
597}
598
[email protected]b172aee2012-04-10 17:05:26599RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28600 return &render_manager_;
601}
602
[email protected]b172aee2012-04-10 17:05:26603bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56604 if (GetWebUI() &&
605 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17606 return true;
[email protected]d2353452012-01-19 19:53:56607 }
[email protected]f82d57b52011-04-27 19:13:17608
[email protected]d8c660432011-12-22 20:51:25609 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
610 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10611 while ((observer = it.GetNext()) != NULL)
612 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53613 return true;
[email protected]403415a2011-01-10 18:57:53614
[email protected]724159a2010-12-30 01:11:18615 bool handled = true;
616 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26617 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58618 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
619 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24620 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
621 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18622 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
623 OnDidLoadResourceFromMemoryCache)
624 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
625 OnDidDisplayInsecureContent)
626 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
627 OnDidRunInsecureContent)
628 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
629 OnDocumentLoadedInFrame)
630 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26631 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
632 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17633 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
634 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25635 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26636 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59637 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21638 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20639 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
640 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
641 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16642 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45643 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10644 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20645 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
646 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
647 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
648 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29649 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50650 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18651 IPC_MESSAGE_UNHANDLED(handled = false)
652 IPC_END_MESSAGE_MAP_EX()
653
654 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38655 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18656 GetRenderProcessHost()->ReceivedBadMessage();
657 }
658
659 return handled;
660}
661
[email protected]b172aee2012-04-10 17:05:26662void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18663 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23664 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51665 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18666}
667
[email protected]b172aee2012-04-10 17:05:26668NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56669 return controller_;
670}
671
[email protected]b172aee2012-04-10 17:05:26672const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56673 return controller_;
674}
675
[email protected]b172aee2012-04-10 17:05:26676content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55677 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30678}
679
[email protected]b172aee2012-04-10 17:05:26680const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31681 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23682 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51683 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31684}
685
686
[email protected]b172aee2012-04-10 17:05:26687const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31688 return &property_bag_;
689}
690
[email protected]b172aee2012-04-10 17:05:26691base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31692 return &property_bag_;
693}
694
[email protected]b172aee2012-04-10 17:05:26695content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31696 return delegate_;
697}
698
[email protected]b172aee2012-04-10 17:05:26699void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31700 // TODO(cbentzel): remove this debugging code?
701 if (delegate == delegate_)
702 return;
703 if (delegate_)
704 delegate_->Detach(this);
705 delegate_ = delegate;
706 if (delegate_)
707 delegate_->Attach(this);
708}
709
[email protected]b172aee2012-04-10 17:05:26710content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41711 RenderViewHostImpl* host = render_manager_.current_host();
712 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16713}
714
[email protected]b172aee2012-04-10 17:05:26715RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31716 return render_manager_.current_host();
717}
718
[email protected]b172aee2012-04-10 17:05:26719RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31720 return render_manager_.GetRenderWidgetHostView();
721}
722
[email protected]b172aee2012-04-10 17:05:26723content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31724 return view_.get();
725}
726
[email protected]b172aee2012-04-10 17:05:26727content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50728 WebUIControllerFactory* factory =
729 content::GetContentClient()->browser()->GetWebUIControllerFactory();
730 if (!factory)
731 return NULL;
[email protected]d2353452012-01-19 19:53:56732 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22733 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50734 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22735 if (controller) {
736 web_ui->SetController(controller);
737 return web_ui;
738 }
739
740 delete web_ui;
741 return NULL;
742}
743
[email protected]b172aee2012-04-10 17:05:26744content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31745 return render_manager_.web_ui() ? render_manager_.web_ui()
746 : render_manager_.pending_web_ui();
747}
748
[email protected]b172aee2012-04-10 17:05:26749content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31750 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34751}
752
[email protected]86ef6a392012-05-11 22:03:11753void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22754 if (GetUserAgentOverride() == override)
755 return;
756
757 renderer_preferences_.user_agent_override = override;
758
759 // Send the new override string to the renderer.
760 RenderViewHost* host = GetRenderViewHost();
761 if (host)
762 host->SyncRendererPrefs();
763
764 // Reload the page if a load is currently in progress to avoid having
765 // different parts of the page loaded using different user agents.
766 NavigationEntry* entry = controller_.GetActiveEntry();
767 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
768 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11769}
770
771const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22772 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11773}
774
[email protected]b172aee2012-04-10 17:05:26775const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55776 // Transient entries take precedence. They are used for interstitial pages
777 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23778 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08779 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20780 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30781 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23782 if (entry) {
[email protected]b5cca982011-05-26 04:42:08783 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23784 }
[email protected]7ade2732011-02-10 00:13:58785 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
786 render_manager_.pending_web_ui() : render_manager_.web_ui();
787 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54788 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55789 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54790 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35791 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22792 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54793 if (!title.empty())
794 return title;
795 }
796 }
797
798 // We use the title for the last committed entry rather than a pending
799 // navigation entry. For example, when the user types in a URL, we want to
800 // keep the old page's title until the new load has committed and we get a new
801 // title.
[email protected]96d185d2009-04-24 03:28:54802 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23803 if (entry) {
[email protected]b5cca982011-05-26 04:42:08804 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23805 }
[email protected]987fc3a2011-05-26 14:18:09806
807 // |page_title_when_no_navigation_entry_| is finally used
808 // if no title cannot be retrieved.
809 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54810}
811
[email protected]b172aee2012-04-10 17:05:26812int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46813 return GetMaxPageIDForSiteInstance(GetSiteInstance());
814}
815
[email protected]b172aee2012-04-10 17:05:26816int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
817 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33818 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
819 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46820
[email protected]b6583592012-01-25 19:52:33821 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34822}
823
[email protected]b172aee2012-04-10 17:05:26824void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46825 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
826}
827
[email protected]b172aee2012-04-10 17:05:26828void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33829 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46830 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33831 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34832}
833
[email protected]b172aee2012-04-10 17:05:26834void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
835 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57836}
837
[email protected]b172aee2012-04-10 17:05:26838SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58839 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54840}
841
[email protected]b172aee2012-04-10 17:05:26842SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38843 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
844 render_manager_.pending_render_view_host() :
845 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58846 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38847}
848
[email protected]b172aee2012-04-10 17:05:26849bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49851}
852
[email protected]b172aee2012-04-10 17:05:26853bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return waiting_for_response_;
855}
856
[email protected]b172aee2012-04-10 17:05:26857const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return load_state_;
859}
860
[email protected]b172aee2012-04-10 17:05:26861const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31862 return load_state_host_;
863}
864
[email protected]b172aee2012-04-10 17:05:26865uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return upload_size_;
867}
868
[email protected]b172aee2012-04-10 17:05:26869uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31870 return upload_position_;
871}
872
[email protected]b172aee2012-04-10 17:05:26873const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31874 return encoding_;
875}
876
[email protected]b172aee2012-04-10 17:05:26877bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31878 return displayed_insecure_content_;
879}
880
[email protected]b172aee2012-04-10 17:05:26881void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31882 capturing_contents_ = cap;
883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
887 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
888 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49889}
890
[email protected]b172aee2012-04-10 17:05:26891void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
892 int error_code) {
[email protected]443b80e2010-12-14 00:42:23893 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34894 return;
895
[email protected]443b80e2010-12-14 00:42:23896 crashed_status_ = status;
897 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46898 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34899}
900
[email protected]b172aee2012-04-10 17:05:26901base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return crashed_status_;
903}
904
[email protected]b172aee2012-04-10 17:05:26905bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return is_being_destroyed_;
907}
908
[email protected]b172aee2012-04-10 17:05:26909void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34910 if (delegate_)
911 delegate_->NavigationStateChanged(this, changed_flags);
912}
913
[email protected]3e324142012-06-25 18:26:33914base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
915 return last_selected_time_;
916}
917
918void WebContentsImpl::WasRestored() {
[email protected]96d185d2009-04-24 03:28:54919 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04920 RenderWidgetHostViewPort* rwhv =
921 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16922 if (rwhv) {
[email protected]3e324142012-06-25 18:26:33923 rwhv->WasRestored();
[email protected]789e9152009-08-04 21:59:43924#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16925 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43926#endif
927 }
[email protected]96d185d2009-04-24 03:28:54928
[email protected]5ac20162010-11-24 23:33:11929 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38930
[email protected]3e324142012-06-25 18:26:33931 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasRestored());
[email protected]b9769d82012-02-10 00:23:59932
933 // The resize rect might have changed while this was inactive -- send the new
934 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58935 RenderViewHostImpl* rvh =
936 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59937 if (rvh) {
938 rvh->ResizeRectChanged(GetRootWindowResizerRect());
939 }
[email protected]96d185d2009-04-24 03:28:54940
[email protected]3e324142012-06-25 18:26:33941 bool is_visible = true;
942 content::NotificationService::current()->Notify(
943 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
944 content::Source<WebContents>(this),
945 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31946}
947
[email protected]b172aee2012-04-10 17:05:26948void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31949 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52950 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
951 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26952 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52953 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33954 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52955 // calls us).
[email protected]c30585c2012-02-16 15:02:04956 RenderWidgetHostViewPort* rwhv =
957 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16958 if (rwhv)
959 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54960 }
961
[email protected]375fa1b2012-05-22 22:05:37962 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07963 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37964 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09965 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37966 content::Details<bool>(&is_visible));
967}
968
[email protected]b172aee2012-04-10 17:05:26969bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31970 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27971 return WillNotifyDisconnection() &&
972 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58973 !static_cast<RenderViewHostImpl*>(
974 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31975}
976
[email protected]b172aee2012-04-10 17:05:26977void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27978 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25979 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27980}
981
[email protected]b172aee2012-04-10 17:05:26982WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44983 // We use our current SiteInstance since the cloned entry will use it anyway.
984 // We pass |this| for the |base_web_contents| to size the view correctly, and
985 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26986 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44987 GetBrowserContext(), GetSiteInstance(),
988 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20989 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27990 return tc;
991}
992
[email protected]b172aee2012-04-10 17:05:26993void WebContentsImpl::AddNewContents(WebContents* new_contents,
994 WindowOpenDisposition disposition,
995 const gfx::Rect& initial_pos,
996 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27997 if (!delegate_)
998 return;
999
1000 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1001 user_gesture);
1002}
1003
[email protected]b172aee2012-04-10 17:05:261004gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271005 return view_->GetContentNativeView();
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271009 return view_->GetNativeView();
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271013 view_->GetContainerBounds(out);
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271017 view_->Focus();
1018}
1019
[email protected]14392a52012-05-02 20:28:441020void WebContentsImpl::Observe(int type,
1021 const content::NotificationSource& source,
1022 const content::NotificationDetails& details) {
1023 switch (type) {
1024 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1025 OnWebContentsDestroyed(
1026 content::Source<content::WebContents>(source).ptr());
1027 break;
[email protected]bafe6cd2012-05-23 23:09:501028 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1029 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1030 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1031 i != pending_widget_views_.end(); ++i) {
1032 if (host->GetView() == i->second) {
1033 pending_widget_views_.erase(i);
1034 break;
1035 }
1036 }
1037 break;
1038 }
[email protected]14392a52012-05-02 20:28:441039 default:
1040 NOTREACHED();
1041 }
1042}
1043
1044void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1045 // Clear the opener if it has been closed.
1046 if (web_contents == opener_) {
1047 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1048 content::Source<WebContents>(opener_));
1049 opener_ = NULL;
1050 }
1051}
1052
[email protected]b172aee2012-04-10 17:05:261053void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311054 observers_.AddObserver(observer);
1055}
1056
[email protected]b172aee2012-04-10 17:05:261057void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311058 observers_.RemoveObserver(observer);
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341062 if (delegate_)
1063 delegate_->ActivateContents(this);
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121067 if (delegate_)
1068 delegate_->DeactivateContents(this);
1069}
1070
[email protected]b172aee2012-04-10 17:05:261071void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481072 if (delegate_)
1073 delegate_->LostCapture();
1074}
1075
[email protected]b172aee2012-04-10 17:05:261076bool WebContentsImpl::PreHandleKeyboardEvent(
1077 const NativeWebKeyboardEvent& event,
1078 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481079 return delegate_ &&
1080 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1081}
1082
[email protected]b172aee2012-04-10 17:05:261083void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481084 if (delegate_)
1085 delegate_->HandleKeyboardEvent(event);
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431089 if (delegate_)
1090 delegate_->HandleMouseDown();
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481094 if (delegate_)
1095 delegate_->HandleMouseUp();
1096}
1097
[email protected]b172aee2012-04-10 17:05:261098void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481099 if (delegate_)
1100 delegate_->HandleMouseActivate();
1101}
1102
[email protected]b172aee2012-04-10 17:05:261103void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471104 if (delegate_)
1105 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1106}
1107
[email protected]b172aee2012-04-10 17:05:261108bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381109 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121110}
1111
[email protected]a9c81f02012-06-01 00:15:441112void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1113 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371114 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441115 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371116 } else {
1117 GotResponseToLockMouseRequest(false);
1118 }
1119}
1120
[email protected]b172aee2012-04-10 17:05:261121void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371122 if (delegate_)
1123 delegate_->LostMouseLock();
1124}
1125
[email protected]bafe6cd2012-05-23 23:09:501126void WebContentsImpl::CreateNewWindow(
1127 int route_id,
[email protected]97714c82012-06-06 10:15:131128 const ViewHostMsg_CreateWindow_Params& params,
1129 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501130 if (delegate_ && !delegate_->ShouldCreateWebContents(
1131 this, route_id, params.window_container_type, params.frame_name,
1132 params.target_url)) {
1133 return;
1134 }
1135
1136 // We usually create the new window in the same BrowsingInstance (group of
1137 // script-related windows), by passing in the current SiteInstance. However,
1138 // if the opener is being suppressed, we create a new SiteInstance in its own
1139 // BrowsingInstance.
1140 scoped_refptr<SiteInstance> site_instance =
1141 params.opener_suppressed ?
1142 SiteInstance::Create(GetBrowserContext()) :
1143 GetSiteInstance();
1144
1145 // Create the new web contents. This will automatically create the new
1146 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131147 WebContentsImpl* new_contents = new WebContentsImpl(
1148 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571149 site_instance,
1150 route_id,
1151 this,
1152 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131153 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501154 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1155
1156 if (!params.opener_suppressed) {
1157 content::WebContentsView* new_view = new_contents->GetView();
1158
1159 // TODO(brettw): It seems bogus that we have to call this function on the
1160 // newly created object and give it one of its own member variables.
1161 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1162
1163 // Save the created window associated with the route so we can show it
1164 // later.
1165 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1166 pending_contents_[route_id] = new_contents;
1167 }
1168
1169 if (delegate_) {
1170 delegate_->WebContentsCreated(
1171 this, params.opener_frame_id, params.target_url, new_contents);
1172 }
1173
1174 if (params.opener_suppressed) {
1175 // When the opener is suppressed, the original renderer cannot access the
1176 // new window. As a result, we need to show and navigate the window here.
1177 gfx::Rect initial_pos;
1178 AddNewContents(
1179 new_contents, params.disposition, initial_pos, params.user_gesture);
1180
1181 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1182 CURRENT_TAB,
1183 content::PAGE_TRANSITION_LINK,
1184 true /* is_renderer_initiated */);
1185 new_contents->OpenURL(open_params);
1186 }
1187}
1188
1189void WebContentsImpl::CreateNewWidget(int route_id,
1190 WebKit::WebPopupType popup_type) {
1191 CreateNewWidget(route_id, false, popup_type);
1192}
1193
1194void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1195 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1196}
1197
1198void WebContentsImpl::CreateNewWidget(int route_id,
1199 bool is_fullscreen,
1200 WebKit::WebPopupType popup_type) {
1201 content::RenderProcessHost* process = GetRenderProcessHost();
1202 RenderWidgetHostImpl* widget_host =
1203 new RenderWidgetHostImpl(this, process, route_id);
1204 RenderWidgetHostViewPort* widget_view =
1205 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1206 if (!is_fullscreen) {
1207 // Popups should not get activated.
1208 widget_view->SetPopupType(popup_type);
1209 }
1210 // Save the created widget associated with the route so we can show it later.
1211 pending_widget_views_[route_id] = widget_view;
1212
1213#if defined(OS_MACOSX)
1214 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1215 // to allow it to survive the trip without being hosted.
1216 base::mac::NSObjectRetain(widget_view->GetNativeView());
1217#endif
1218}
1219
1220void WebContentsImpl::ShowCreatedWindow(int route_id,
1221 WindowOpenDisposition disposition,
1222 const gfx::Rect& initial_pos,
1223 bool user_gesture) {
1224 WebContentsImpl* contents = GetCreatedWindow(route_id);
1225 if (contents)
1226 AddNewContents(contents, disposition, initial_pos, user_gesture);
1227}
1228
1229void WebContentsImpl::ShowCreatedWidget(int route_id,
1230 const gfx::Rect& initial_pos) {
1231 ShowCreatedWidget(route_id, false, initial_pos);
1232}
1233
1234void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1235 ShowCreatedWidget(route_id, true, gfx::Rect());
1236}
1237
1238void WebContentsImpl::ShowCreatedWidget(int route_id,
1239 bool is_fullscreen,
1240 const gfx::Rect& initial_pos) {
1241 if (delegate_)
1242 delegate_->RenderWidgetShowing();
1243
1244 RenderWidgetHostViewPort* widget_host_view =
1245 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1246 if (!widget_host_view)
1247 return;
1248 if (is_fullscreen) {
1249 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1250 } else {
1251 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1252 }
[email protected]89054502012-06-03 10:29:241253
1254 RenderWidgetHostImpl* render_widget_host_impl =
1255 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1256 render_widget_host_impl->Init();
1257 // Only allow privileged mouse lock for fullscreen render widget, which is
1258 // used to implement Pepper Flash fullscreen.
1259 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501260
1261#if defined(OS_MACOSX)
1262 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1263 // properly embedded (or purposefully ignored) we can release the retain we
1264 // took in CreateNewWidget().
1265 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1266#endif
1267}
1268
1269WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1270 PendingContents::iterator iter = pending_contents_.find(route_id);
1271
1272 // Certain systems can block the creation of new windows. If we didn't succeed
1273 // in creating one, just return NULL.
1274 if (iter == pending_contents_.end()) {
1275 return NULL;
1276 }
1277
1278 WebContentsImpl* new_contents = iter->second;
1279 pending_contents_.erase(route_id);
1280
1281 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1282 !new_contents->GetRenderViewHost()->GetView())
1283 return NULL;
1284
1285 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1286 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1287 return new_contents;
1288}
1289
1290RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1291 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1292 if (iter == pending_widget_views_.end()) {
1293 DCHECK(false);
1294 return NULL;
1295 }
1296
1297 RenderWidgetHostView* widget_host_view = iter->second;
1298 pending_widget_views_.erase(route_id);
1299
1300 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1301 if (!widget_host->GetProcess()->HasConnection()) {
1302 // The view has gone away or the renderer crashed. Nothing to do.
1303 return NULL;
1304 }
1305
1306 return widget_host_view;
1307}
1308
1309void WebContentsImpl::ShowContextMenu(
1310 const content::ContextMenuParams& params) {
1311 // Allow WebContentsDelegates to handle the context menu operation first.
1312 if (delegate_ && delegate_->HandleContextMenu(params))
1313 return;
1314
[email protected]5a3bdf52012-05-24 15:12:571315 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501316}
1317
[email protected]f13b4202012-06-12 23:53:231318void WebContentsImpl::RequestMediaAccessPermission(
1319 const content::MediaStreamRequest* request,
1320 const content::MediaResponseCallback& callback) {
1321 if (delegate_)
1322 delegate_->RequestMediaAccessPermission(this, request, callback);
1323 else
1324 callback.Run(content::MediaStreamDevices());
1325}
1326
[email protected]b172aee2012-04-10 17:05:261327void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231328 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331329 if (delegate_)
1330 delegate_->UpdatePreferredSize(this, pref_size);
1331}
1332
[email protected]b172aee2012-04-10 17:05:261333void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341334 if (delegate_)
1335 delegate_->ResizeDueToAutoResize(this, new_size);
1336}
1337
[email protected]b172aee2012-04-10 17:05:261338WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201339 if (!delegate_)
1340 return NULL;
[email protected]00c37fc2011-08-02 00:22:501341
[email protected]e5d549d2011-12-28 01:29:201342 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1343 // Notify observers.
1344 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1345 DidOpenURL(params.url, params.referrer,
1346 params.disposition, params.transition));
1347 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341348}
1349
[email protected]b172aee2012-04-10 17:05:261350bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501351 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251352 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231353 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251354 reload_type);
[email protected]876bc832010-09-07 16:29:541355}
[email protected]96d185d2009-04-24 03:28:541356
[email protected]ba45bfd2012-05-22 21:51:441357void WebContentsImpl::RenderViewForInterstitialPageCreated(
1358 content::RenderViewHost* render_view_host) {
1359 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1360 RenderViewForInterstitialPageCreated(render_view_host));
1361}
1362
[email protected]b172aee2012-04-10 17:05:261363bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231364 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501365 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401366 // The renderer will reject IPC messages with URLs longer than
1367 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511368 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401369 return false;
1370
[email protected]9f76c1e2012-03-05 15:15:581371 RenderViewHostImpl* dest_render_view_host =
1372 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401373 if (!dest_render_view_host)
1374 return false; // Unable to create the desired render view host.
1375
[email protected]80a8fad2011-01-29 04:02:381376 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071377 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581378 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501379 WebUIControllerFactory* factory =
1380 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271381 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501382 bool is_allowed_in_web_ui_renderer =
1383 factory &&
[email protected]24e18252012-04-16 21:26:271384 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1385 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231386 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1387 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271388 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231389 content::GetContentClient()->SetActiveURL(entry.GetURL());
1390 CHECK(0);
1391 }
[email protected]54ec6472010-04-09 19:39:581392
[email protected]96d185d2009-04-24 03:28:541393 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441394 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521395 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441396 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511397 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541398
1399 // Used for page load time metrics.
1400 current_load_start_ = base::TimeTicks::Now();
1401
1402 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241403 std::string embedder_channel_name;
1404 int embedder_container_id;
1405 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1406 &embedder_channel_name,
1407 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341408 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271409 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241410 embedder_channel_name,
1411 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471412 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341413 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541414
[email protected]36fc0392011-12-25 03:59:511415 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541416 // HACK!! This code suppresses javascript: URLs from being added to
1417 // session history, which is what we want to do for javascript: URLs that
1418 // do not generate content. What we really need is a message from the
1419 // renderer telling us that a new page was not created. The same message
1420 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511421 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541422 return false;
1423 }
1424
[email protected]3c9e1872010-11-18 16:17:491425 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251426 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041427 observers_,
[email protected]36fc0392011-12-25 03:59:511428 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541429
[email protected]09b29342011-06-24 19:18:481430 if (delegate_)
1431 delegate_->DidNavigateToPendingEntry(this);
1432
[email protected]d5f942ba2008-09-26 19:30:341433 return true;
1434}
1435
[email protected]b172aee2012-04-10 17:05:261436void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331437 const SiteInstance* site_instance,
1438 int history_length,
1439 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411440 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1441 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191442 if (render_manager_.pending_render_view_host()) {
1443 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141444 return;
[email protected]9e1ad4b2011-08-14 16:49:191445 }
[email protected]9f76c1e2012-03-05 15:15:581446 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191447 if (!rvh) {
1448 NOTREACHED();
1449 return;
1450 }
[email protected]9f76c1e2012-03-05 15:15:581451 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191452 NOTREACHED();
1453 return;
1454 }
[email protected]9f76c1e2012-03-05 15:15:581455 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191456 history_length,
1457 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141458}
1459
[email protected]b172aee2012-04-10 17:05:261460void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271461 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541462 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1463 return;
1464 }
[email protected]9f76c1e2012-03-05 15:15:581465 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541466}
1467
[email protected]b172aee2012-04-10 17:05:261468bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271469 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541470}
1471
[email protected]b172aee2012-04-10 17:05:261472InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271473 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221474}
1475
[email protected]b172aee2012-04-10 17:05:261476bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161477 // WebKit creates Document object when MIME type is application/xhtml+xml,
1478 // so we also support this MIME type.
1479 return contents_mime_type_ == "text/html" ||
1480 contents_mime_type_ == "text/xml" ||
1481 contents_mime_type_ == "application/xhtml+xml" ||
1482 contents_mime_type_ == "text/plain" ||
1483 contents_mime_type_ == "text/css" ||
1484 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1485}
1486
[email protected]b172aee2012-04-10 17:05:261487void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591488 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161489 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481490 download_stats::RecordDownloadSource(
1491 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461492 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141493 return;
[email protected]c7dd2f62011-07-18 15:57:591494 }
1495
1496 Stop();
1497
1498 // Create the save package and possibly prompt the user for the name to save
1499 // the page as. The user prompt is an asynchronous operation that runs on
1500 // another thread.
1501 save_package_ = new SavePackage(this);
1502 save_package_->GetSaveInfo();
1503}
1504
1505// Used in automated testing to bypass prompting the user for file names.
1506// Instead, the names and paths are hard coded rather than running them through
1507// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261508bool WebContentsImpl::SavePage(const FilePath& main_file,
1509 const FilePath& dir_path,
1510 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591511 // Stop the page from navigating.
1512 Stop();
1513
1514 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271515 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591516}
1517
[email protected]b172aee2012-04-10 17:05:261518void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121519 const FilePath& file,
1520 const base::Callback<void(const FilePath&, int64)>& callback) {
1521 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1522}
1523
[email protected]b172aee2012-04-10 17:05:261524bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231525 NavigationEntryImpl* active_entry =
1526 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321527 return (active_entry != NULL &&
1528 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511529 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321530}
1531
[email protected]b172aee2012-04-10 17:05:261532const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271533 return contents_mime_type_;
1534}
1535
[email protected]b172aee2012-04-10 17:05:261536bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271537 return notify_disconnection_;
1538}
1539
[email protected]b172aee2012-04-10 17:05:261540void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311541 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581542 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1543 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161544}
1545
[email protected]b172aee2012-04-10 17:05:261546void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311547 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581548 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1549 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161550}
1551
[email protected]b172aee2012-04-10 17:05:261552content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271553 return &renderer_preferences_;
1554}
1555
[email protected]b172aee2012-04-10 17:05:261556void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271557 new_tab_start_time_ = time;
1558}
1559
[email protected]b172aee2012-04-10 17:05:261560base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271561 return new_tab_start_time_;
1562}
1563
[email protected]e35ccd52012-05-23 16:22:471564void WebContentsImpl::Close() {
1565 Close(GetRenderViewHost());
1566}
1567
[email protected]b172aee2012-04-10 17:05:261568void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151569 if (close_start_time_.is_null())
1570 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011571}
1572
[email protected]b172aee2012-04-10 17:05:261573bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191574#if defined(OS_CHROMEOS)
1575 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1576 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511577 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201578 return false;
1579 return true;
[email protected]46624bf2010-06-09 16:04:191580#else
1581 return true;
1582#endif
1583}
1584
[email protected]b172aee2012-04-10 17:05:261585void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521586 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581587 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511588 if (delegate_)
1589 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341590}
1591
[email protected]e35ccd52012-05-23 16:22:471592void WebContentsImpl::UserGestureDone() {
1593 OnUserGesture();
1594}
1595
[email protected]b172aee2012-04-10 17:05:261596void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271597 closed_by_user_gesture_ = value;
1598}
1599
[email protected]b172aee2012-04-10 17:05:261600bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271601 return closed_by_user_gesture_;
1602}
1603
[email protected]b172aee2012-04-10 17:05:261604double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051605 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561606 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251607 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171608 return 0;
[email protected]b75b8292010-10-01 07:28:251609
1610 double zoom_level;
1611 if (temporary_zoom_settings_) {
1612 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581613 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251614 } else {
[email protected]2ae88d12011-10-14 09:11:191615 GURL url;
[email protected]10f417c52011-12-28 21:04:231616 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191617 // Since zoom map is updated using rewritten URL, use rewritten URL
1618 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511619 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191620 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251621 }
[email protected]d0b8d092010-10-25 04:05:171622 return zoom_level;
1623}
[email protected]b75b8292010-10-01 07:28:251624
[email protected]b172aee2012-04-10 17:05:261625int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1626 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171627 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011628 // Calculate the zoom percent from the factor. Round up to the nearest whole
1629 // number.
[email protected]b75b8292010-10-01 07:28:251630 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011631 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251632 *enable_decrement = percent > minimum_zoom_percent_;
1633 *enable_increment = percent < maximum_zoom_percent_;
1634 return percent;
1635}
1636
[email protected]b172aee2012-04-10 17:05:261637void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501638 if (!delegate_)
1639 return;
1640
[email protected]10f417c52011-12-28 21:04:231641 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501642 if (!active_entry)
1643 return;
1644
[email protected]36fc0392011-12-25 03:59:511645 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121646}
1647
[email protected]b172aee2012-04-10 17:05:261648void WebContentsImpl::ViewFrameSource(const GURL& url,
1649 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271650 if (!delegate_)
1651 return;
1652
1653 delegate_->ViewSourceForFrame(this, url, content_state);
1654}
1655
[email protected]b172aee2012-04-10 17:05:261656int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271657 return minimum_zoom_percent_;
1658}
1659
[email protected]b172aee2012-04-10 17:05:261660int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271661 return maximum_zoom_percent_;
1662}
1663
[email protected]b172aee2012-04-10 17:05:261664gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231665 return preferred_size_;
1666}
1667
[email protected]b172aee2012-04-10 17:05:261668int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271669 return content_restrictions_;
1670}
1671
[email protected]b172aee2012-04-10 17:05:261672WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501673 WebUIControllerFactory* factory =
1674 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1675 if (!factory)
1676 return WebUI::kNoWebUI;
1677 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271678}
1679
[email protected]b172aee2012-04-10 17:05:261680content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271681 // When there is a pending navigation entry, we want to use the pending WebUI
1682 // that goes along with it to control the basic flags. For example, we want to
1683 // show the pending URL in the URL bar, so we want the display_url flag to
1684 // be from the pending entry.
1685 //
1686 // The confusion comes because there are multiple possibilities for the
1687 // initial load in a tab as a side effect of the way the RenderViewHostManager
1688 // works.
1689 //
1690 // - For the very first tab the load looks "normal". The new tab Web UI is
1691 // the pending one, and we want it to apply here.
1692 //
1693 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1694 // get switched to the one previously associated with the new tab pages.
1695 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1696 // have a committed Web UI in this case.
1697 //
1698 // This condition handles all of these cases:
1699 //
1700 // - First load in first tab: no committed nav entry + pending nav entry +
1701 // pending dom ui:
1702 // -> Use pending Web UI if any.
1703 //
1704 // - First load in second tab: no committed nav entry + pending nav entry +
1705 // no pending Web UI:
1706 // -> Use the committed Web UI if any.
1707 //
1708 // - Second navigation in any tab: committed nav entry + pending nav entry:
1709 // -> Use pending Web UI if any.
1710 //
1711 // - Normal state with no load: committed nav entry + no pending nav entry:
1712 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251713 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271714 (controller_.GetLastCommittedEntry() ||
1715 render_manager_.pending_web_ui()))
1716 return render_manager_.pending_web_ui();
1717 return render_manager_.web_ui();
1718}
1719
[email protected]b172aee2012-04-10 17:05:261720bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271721 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581722 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271723}
1724
[email protected]b172aee2012-04-10 17:05:261725bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441726 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321730 SkColor color) {
[email protected]da8543762012-03-20 08:52:201731 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1732 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1733}
1734
[email protected]b172aee2012-04-10 17:05:261735void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201736 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1737 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1738 if (delegate_)
1739 delegate_->DidEndColorChooser();
1740 color_chooser_ = NULL;
1741}
1742
[email protected]b172aee2012-04-10 17:05:261743bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471744 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271745 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221746 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231747 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411748 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271749}
1750
[email protected]b172aee2012-04-10 17:05:261751void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271752 if (delegate_)
1753 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211754}
1755
[email protected]3a3b75a2012-06-01 08:38:361756void WebContentsImpl::OnRegisterIntentService(
1757 const webkit_glue::WebIntentServiceData& data,
1758 bool user_gesture) {
1759 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301760}
1761
[email protected]b172aee2012-04-10 17:05:261762void WebContentsImpl::OnWebIntentDispatch(
1763 const webkit_glue::WebIntentData& intent,
1764 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001765 WebIntentsDispatcherImpl* intents_dispatcher =
1766 new WebIntentsDispatcherImpl(this, intent, intent_id);
1767 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301768}
1769
[email protected]54047eb52012-05-08 21:45:571770void WebContentsImpl::DidStartProvisionalLoadForFrame(
1771 content::RenderViewHost* render_view_host,
1772 int64 frame_id,
1773 bool is_main_frame,
1774 const GURL& opener_url,
1775 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281776 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181777 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451778 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571779 content::RenderProcessHost* render_process_host =
1780 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541781 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571782 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451783 false,
[email protected]9f76c1e2012-03-05 15:15:581784 &validated_url);
[email protected]ef108e72012-06-20 14:03:541785 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571786 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451787 true,
1788 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181789
[email protected]0d60f0192011-04-14 12:40:101790 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251791 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101792 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571793 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541794
1795 if (is_main_frame) {
1796 // Notify observers about the provisional change in the main frame URL.
1797 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1798 ProvisionalChangeToMainFrameUrl(validated_url,
1799 validated_opener_url,
1800 render_view_host));
1801 }
1802}
1803
1804void WebContentsImpl::DidRedirectProvisionalLoad(
1805 content::RenderViewHost* render_view_host,
1806 int32 page_id,
1807 const GURL& opener_url,
1808 const GURL& source_url,
1809 const GURL& target_url) {
1810 // TODO(creis): Remove this method and have the pre-rendering code listen to
1811 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1812 // instead. See http://crbug.com/78512.
1813 GURL validated_source_url(source_url);
1814 GURL validated_target_url(target_url);
1815 GURL validated_opener_url(opener_url);
1816 content::RenderProcessHost* render_process_host =
1817 render_view_host->GetProcess();
1818 RenderViewHostImpl::FilterURL(
1819 ChildProcessSecurityPolicyImpl::GetInstance(),
1820 render_process_host->GetID(),
1821 false,
1822 &validated_source_url);
1823 RenderViewHostImpl::FilterURL(
1824 ChildProcessSecurityPolicyImpl::GetInstance(),
1825 render_process_host->GetID(),
1826 false,
1827 &validated_target_url);
1828 RenderViewHostImpl::FilterURL(
1829 ChildProcessSecurityPolicyImpl::GetInstance(),
1830 render_process_host->GetID(),
1831 true,
1832 &validated_opener_url);
1833 NavigationEntry* entry;
1834 if (page_id == -1) {
1835 entry = controller_.GetPendingEntry();
1836 } else {
1837 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1838 page_id);
1839 }
1840 if (!entry || entry->GetURL() != validated_source_url)
1841 return;
1842
1843 // Notify observers about the provisional change in the main frame URL.
1844 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1845 ProvisionalChangeToMainFrameUrl(validated_target_url,
1846 validated_opener_url,
1847 render_view_host));
[email protected]724159a2010-12-30 01:11:181848}
1849
[email protected]54047eb52012-05-08 21:45:571850void WebContentsImpl::DidFailProvisionalLoadWithError(
1851 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581852 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1853 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1854 << ", error_code: " << params.error_code
1855 << ", error_description: " << params.error_description
1856 << ", is_main_frame: " << params.is_main_frame
1857 << ", showing_repost_interstitial: " <<
1858 params.showing_repost_interstitial
1859 << ", frame_id: " << params.frame_id;
1860 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571861 content::RenderProcessHost* render_process_host =
1862 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541863 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571864 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451865 false,
[email protected]9f76c1e2012-03-05 15:15:581866 &validated_url);
[email protected]724159a2010-12-30 01:11:181867
[email protected]d7b175e2011-10-11 15:31:581868 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181869 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1870 // This means that the interstitial won't be torn down properly, which is
1871 // bad. But if we have an interstitial, go back to another tab type, and
1872 // then load the same interstitial again, we could end up getting the first
1873 // interstitial's "failed" message (as a result of the cancel) when we're on
1874 // the second one.
1875 //
1876 // We can't tell this apart, so we think we're tearing down the current page
1877 // which will cause a crash later one. There is also some code in
1878 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1879 // out because of this problem.
1880 //
1881 // http://code.google.com/p/chromium/issues/detail?id=2855
1882 // Because this will not tear down the interstitial properly, if "back" is
1883 // back to another tab type, the interstitial will still be somewhat alive
1884 // in the previous tab type. If you navigate somewhere that activates the
1885 // tab with the interstitial again, you'll see a flash before the new load
1886 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271887 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181888 LOG(WARNING) << "Discarding message during interstitial.";
1889 return;
1890 }
1891
[email protected]a16690732012-07-13 19:22:171892 // Do not clear the pending entry if one exists, so that the user's typed
1893 // URL is not lost when a navigation fails or is aborted. We'll allow
1894 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181895
[email protected]54047eb52012-05-08 21:45:571896 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181897 }
1898
[email protected]d8c660432011-12-22 20:51:251899 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581900 observers_,
1901 DidFailProvisionalLoad(params.frame_id,
1902 params.is_main_frame,
1903 validated_url,
1904 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461905 params.error_description,
1906 render_view_host));
[email protected]724159a2010-12-30 01:11:181907}
1908
[email protected]b172aee2012-04-10 17:05:261909void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181910 const GURL& url,
[email protected]70435962011-08-02 20:13:281911 const std::string& security_info,
1912 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181913 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281914 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191915 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181916 cache.Increment();
1917
1918 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081919 int cert_id = 0;
1920 net::CertStatus cert_status = 0;
1921 int security_bits = -1;
1922 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511923 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1924 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001925 content::LoadFromMemoryCacheDetails details(
1926 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1927 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181928
[email protected]ad50def52011-10-19 23:17:071929 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271930 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501931 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001932 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181933}
1934
[email protected]b172aee2012-04-10 17:05:261935void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381936 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181937 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201938 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181939}
1940
[email protected]b172aee2012-04-10 17:05:261941void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021942 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231943 LOG(INFO) << security_origin << " ran insecure content from "
1944 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381945 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411946 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1947 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181948 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411949 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::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181954 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251955 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101956 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181957}
1958
[email protected]b172aee2012-04-10 17:05:261959void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311960 int64 frame_id,
1961 const GURL& validated_url,
1962 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311964 DidFinishLoad(frame_id, validated_url, is_main_frame));
1965}
1966
[email protected]b172aee2012-04-10 17:05:261967void WebContentsImpl::OnDidFailLoadWithError(
1968 int64 frame_id,
1969 const GURL& validated_url,
1970 bool is_main_frame,
1971 int error_code,
1972 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251973 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311974 DidFailLoad(frame_id, validated_url, is_main_frame,
1975 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181976}
1977
[email protected]b172aee2012-04-10 17:05:261978void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271979 content_restrictions_ = restrictions;
1980 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171981}
1982
[email protected]b172aee2012-04-10 17:05:261983void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261984 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231985 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251986 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261987 if (!entry)
1988 return;
1989 // Note that we don't call NavigationController::GotToOffset() as we don't
1990 // want to create a pending navigation entry (it might end up lingering
1991 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251992 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581993 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511994 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581995 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471996 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571997
1998 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1999 // it in now that we know. This allows us to find the entry when it commits.
2000 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232001 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332002 entry->set_site_instance(
2003 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572004 }
[email protected]216813952011-05-19 22:21:262005 }
2006}
2007
[email protected]b172aee2012-04-10 17:05:262008void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2009 int maximum_percent,
2010 bool remember) {
[email protected]216813952011-05-19 22:21:262011 minimum_zoom_percent_ = minimum_percent;
2012 maximum_zoom_percent_ = maximum_percent;
2013 temporary_zoom_settings_ = !remember;
2014}
2015
[email protected]20b433a2012-05-15 21:23:462016void WebContentsImpl::OnSaveURL(const GURL& url,
2017 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482018 download_stats::RecordDownloadSource(
2019 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262020 // Check if the URL to save matches the URL of the main frame. Since this
2021 // message originates from Pepper plugins, it may not be the case if the
2022 // plugin is an embedded element.
2023 GURL main_frame_url = GetURL();
2024 if (!main_frame_url.is_valid())
2025 return;
2026 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462027 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272028}
2029
[email protected]b172aee2012-04-10 17:05:262030void WebContentsImpl::OnEnumerateDirectory(int request_id,
2031 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592032 ChildProcessSecurityPolicyImpl* policy =
2033 ChildProcessSecurityPolicyImpl::GetInstance();
2034 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2035 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512039 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202040}
2041
[email protected]b172aee2012-04-10 17:05:262042void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2043 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362044 const string16& title,
2045 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592046 ChildProcessSecurityPolicyImpl* policy =
2047 ChildProcessSecurityPolicyImpl::GetInstance();
2048 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2049 return;
[email protected]3a3b75a2012-06-01 08:38:362050 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202051}
2052
[email protected]b172aee2012-04-10 17:05:262053void WebContentsImpl::OnFindReply(int request_id,
2054 int number_of_matches,
2055 const gfx::Rect& selection_rect,
2056 int active_match_ordinal,
2057 bool final_update) {
[email protected]6934a702011-12-20 00:04:512058 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2059 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002060 // Send a notification to the renderer that we are ready to receive more
2061 // results from the scoping effort of the Find operation. The FindInPage
2062 // scoping is asynchronous and periodically sends results back up to the
2063 // browser using IPC. In an effort to not spam the browser we have the
2064 // browser send an ACK for each FindReply message and have the renderer
2065 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582066 GetRenderViewHostImpl()->Send(
2067 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162068}
2069
[email protected]b172aee2012-04-10 17:05:262070void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442071 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2072 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452073}
2074
[email protected]b172aee2012-04-10 17:05:262075void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2076 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102077 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252078 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102079 AppCacheAccessed(manifest_url, blocked_by_policy));
2080}
2081
[email protected]b172aee2012-04-10 17:05:262082void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322083 SkColor color) {
[email protected]da8543762012-03-20 08:52:202084 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2085}
2086
[email protected]b172aee2012-04-10 17:05:262087void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202088 if (color_chooser_ &&
2089 color_chooser_id == color_chooser_->identifier())
2090 color_chooser_->End();
2091}
2092
[email protected]b172aee2012-04-10 17:05:262093void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322094 SkColor color) {
[email protected]da8543762012-03-20 08:52:202095 if (color_chooser_ &&
2096 color_chooser_id == color_chooser_->identifier())
2097 color_chooser_->SetSelectedColor(color);
2098}
2099
[email protected]9f2a9d72012-04-16 16:02:222100void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2101 const FilePath& path,
2102 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442103 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2104 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292105}
2106
[email protected]d0759f492012-04-19 22:50:502107// This exists for render views that don't have a WebUI, but do have WebUI
2108// bindings enabled.
2109void WebContentsImpl::OnWebUISend(const GURL& source_url,
2110 const std::string& name,
2111 const base::ListValue& args) {
2112 if (delegate_)
2113 delegate_->WebUISend(this, source_url, name, args);
2114}
2115
[email protected]96d185d2009-04-24 03:28:542116// Notifies the RenderWidgetHost instance about the fact that the page is
2117// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262118void WebContentsImpl::SetIsLoading(bool is_loading,
2119 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542120 if (is_loading == is_loading_)
2121 return;
2122
2123 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212124 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542125 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562126 upload_size_ = 0;
2127 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542128 }
2129
2130 render_manager_.SetIsLoading(is_loading);
2131
2132 is_loading_ = is_loading;
2133 waiting_for_response_ = is_loading;
2134
[email protected]6ebdc9b2010-09-27 16:55:572135 if (delegate_)
2136 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462137 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542138
[email protected]432115822011-07-10 15:52:272139 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2140 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072141 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542142 if (details)
[email protected]6c2381d2011-10-19 02:52:532143 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072144 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502145 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542146 det);
2147}
2148
[email protected]b172aee2012-04-10 17:05:262149void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132150 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322151 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562152 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382153 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442154 // that opened the window, as long as both renderers have the same
2155 // privileges.
[email protected]1fd1a502011-03-30 16:55:562156 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562157 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582158 // web_ui might be NULL if the URL refers to a non-existent extension.
2159 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402160 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522161 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442162 }
2163 }
[email protected]1fd1a502011-03-30 16:55:562164 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442165 }
2166
[email protected]4e697b042011-07-08 06:44:562167 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322168 // Clear the status bubble. This is a workaround for a bug where WebKit
2169 // doesn't let us know that the cursor left an element during a
2170 // transition (this is also why the mouse cursor remains as a hand after
2171 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2172 // clear the bubble when a user navigates to a named anchor in the same
2173 // page.
[email protected]36fc0392011-12-25 03:59:512174 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322175 }
2176
[email protected]a6e82fc2010-02-24 22:28:142177 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472178 // Once the main frame is navigated, we're no longer considered to have
2179 // displayed insecure content.
2180 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172181 }
[email protected]ce5c4502009-05-06 16:46:112182
[email protected]3c9e1872010-11-18 16:17:492183 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252184 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042185 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322186}
2187
[email protected]b172aee2012-04-10 17:05:262188void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322189 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132190 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322191 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062192 // If we navigate off the page, reset JavaScript state. This does nothing
2193 // to prevent a malicious script from spamming messages, since the script
2194 // could just reload the page to stop blocking.
2195 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552196 dialog_creator_->ResetJavaScriptState(this);
2197 dialog_creator_ = NULL;
2198 }
[email protected]420ae012009-04-24 05:16:322199
[email protected]3c9e1872010-11-18 16:17:492200 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252201 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042202 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322203}
2204
[email protected]b172aee2012-04-10 17:05:262205void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462206 // If we are creating a RVH for a restored controller, then we need to make
2207 // sure the RenderView starts with a next_page_id_ larger than the number
2208 // of restored entries. This must be called before the RenderView starts
2209 // navigating (to avoid a race between the browser updating max_page_id and
2210 // the renderer updating next_page_id_). Because of this, we only call this
2211 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562212 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582213 if (max_restored_page_id >
2214 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2215 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2216 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322217}
2218
[email protected]b172aee2012-04-10 17:05:262219bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2220 const string16& title) {
[email protected]420ae012009-04-24 05:16:322221 // For file URLs without a title, use the pathname instead. In the case of a
2222 // synthesized title, we don't want the update to count toward the "one set
2223 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512224 string16 final_title;
[email protected]420ae012009-04-24 05:16:322225 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512226 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2227 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322228 explicit_set = false; // Don't count synthetic titles toward the set limit.
2229 } else {
[email protected]acafd272011-07-26 17:35:572230 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322231 explicit_set = true;
2232 }
2233
[email protected]987fc3a2011-05-26 14:18:092234 // If a page is created via window.open and never navigated,
2235 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552236 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092237 if (entry) {
[email protected]36fc0392011-12-25 03:59:512238 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092239 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322240
[email protected]36fc0392011-12-25 03:59:512241 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092242 } else {
2243 if (page_title_when_no_navigation_entry_ == final_title)
2244 return false; // Nothing changed, don't bother.
2245
2246 page_title_when_no_navigation_entry_ = final_title;
2247 }
[email protected]420ae012009-04-24 05:16:322248
[email protected]420ae012009-04-24 05:16:322249 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232250 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322251
[email protected]2bb171882012-03-07 02:09:462252 std::pair<content::NavigationEntry*, bool> details =
2253 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142254
[email protected]ad50def52011-10-19 23:17:072255 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442256 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2257 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462258 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042259
[email protected]420ae012009-04-24 05:16:322260 return true;
2261}
2262
[email protected]b172aee2012-04-10 17:05:262263void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322264 // After sending out a swap notification, we need to send a disconnect
2265 // notification so that clients that pick up a pointer to |this| can NULL the
2266 // pointer. See Bug 1230284.
2267 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072268 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202269 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2270 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072271 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322272}
2273
[email protected]b172aee2012-04-10 17:05:262274void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322275 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072276 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122277 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2278 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072279 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322280}
2281
[email protected]b172aee2012-04-10 17:05:262282void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322283 if (!notify_disconnection_)
2284 return;
2285
2286 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072287 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322288 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2289 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072290 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322291}
2292
[email protected]5a3bdf52012-05-24 15:12:572293RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2294 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322295}
2296
[email protected]8d3347f2009-07-09 22:00:212297RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262298WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212299 return &render_manager_;
2300}
2301
[email protected]b172aee2012-04-10 17:05:262302content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372303 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462304 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512305}
2306
[email protected]b172aee2012-04-10 17:05:262307WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172308 return this;
2309}
2310
[email protected]b172aee2012-04-10 17:05:262311gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172312 if (delegate_)
2313 return delegate_->GetRootWindowResizerRect();
2314 return gfx::Rect();
2315}
2316
[email protected]b172aee2012-04-10 17:05:262317void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442318 // Don't send notifications if we are just creating a swapped-out RVH for
2319 // the opener chain. These won't be used for view-source or WebUI, so it's
2320 // ok to return early.
2321 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2322 return;
2323
[email protected]ad50def52011-10-19 23:17:072324 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272325 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322326 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532327 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232328 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322329 if (!entry)
2330 return;
2331
2332 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352333 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562334 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582335 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322336
2337 if (entry->IsViewSourceMode()) {
2338 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582339 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2340 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322341 }
[email protected]0666aef2009-05-13 19:48:082342
[email protected]d487beefe2011-12-21 05:41:212343 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262344
2345 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252346 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322347}
2348
[email protected]b172aee2012-04-10 17:05:262349void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522350 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322351 // Don't notify the world, since this came from a renderer in the
2352 // background.
2353 return;
2354 }
2355
2356 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312357 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232358 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302359
2360 // Restore the focus to the tab (otherwise the focus will be on the top
2361 // window).
[email protected]484ae5912010-09-29 19:16:142362 if (was_crashed && !FocusLocationBarByDefault() &&
2363 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302364 Focus();
[email protected]484ae5912010-09-29 19:16:142365 }
[email protected]32ded2212011-11-10 18:51:432366
[email protected]d8c660432011-12-22 20:51:252367 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322368}
2369
[email protected]b172aee2012-04-10 17:05:262370void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2371 base::TerminationStatus status,
2372 int error_code) {
[email protected]151a63d2011-12-20 22:32:522373 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322374 // The pending page's RenderViewHost is gone.
2375 return;
2376 }
2377
2378 SetIsLoading(false, NULL);
2379 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232380 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312381 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322382
[email protected]d8c660432011-12-22 20:51:252383 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272384 observers_,
[email protected]be1f56ab2011-12-22 06:55:312385 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322386}
2387
[email protected]b172aee2012-04-10 17:05:262388void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482389 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252390 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062391}
2392
[email protected]b172aee2012-04-10 17:05:262393void WebContentsImpl::DidNavigate(
2394 RenderViewHost* rvh,
2395 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582396 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322397 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372398
[email protected]434f69f2012-02-06 21:56:522399 // Update the site of the SiteInstance if it doesn't have one yet, unless
2400 // this is for about:blank. In that case, the SiteInstance can still be
2401 // considered unused until a navigation to a real page.
2402 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2403 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332404 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522405 }
[email protected]420ae012009-04-24 05:16:322406
2407 // Need to update MIME type here because it's referred to in
2408 // UpdateNavigationCommands() called by RendererDidNavigate() to
2409 // determine whether or not to enable the encoding menu.
2410 // It's updated only for the main frame. For a subframe,
2411 // RenderView::UpdateURL does not set params.contents_mime_type.
2412 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2413 // TODO(jungshik): Add a test for the encoding menu to avoid
2414 // regressing it again.
[email protected]2905f742011-10-13 03:51:582415 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322416 contents_mime_type_ = params.contents_mime_type;
2417
[email protected]8286f51a2011-05-31 17:39:132418 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002419 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392420
[email protected]a9c0bfe2010-09-17 08:35:222421 // Send notification about committed provisional loads. This notification is
2422 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2423 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082424 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072425 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2426 // that is not recorded in the navigation history. For the purpose of
2427 // tracking navigation events, we treat this event as a sub frame navigation
2428 // event.
2429 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582430 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222431 // Whether or not a page transition was triggered by going backward or
2432 // forward in the history is only stored in the navigation controller's
2433 // entry list.
2434 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512435 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582436 content::PAGE_TRANSITION_FORWARD_BACK)) {
2437 transition_type = content::PageTransitionFromInt(
2438 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222439 }
[email protected]0d60f0192011-04-14 12:40:102440 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252441 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102442 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462443 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222444 }
2445
[email protected]76543b92009-08-31 17:27:452446 if (!did_navigate)
2447 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322448
2449 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2450 // for the appropriate notification (best) or you can add it to
2451 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2452 // necessary, please).
2453
2454 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002455 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322456 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512457 if (delegate_)
2458 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002459 }
[email protected]420ae012009-04-24 05:16:322460 DidNavigateAnyFramePostCommit(rvh, details, params);
2461}
2462
[email protected]b172aee2012-04-10 17:05:262463void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2464 int32 page_id,
2465 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152466 // Ensure that this state update comes from either the active RVH or one of
2467 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522468 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322469
2470 // We must be prepared to handle state updates for any page, these occur
2471 // when the user is scrolling and entering form data, as well as when we're
2472 // leaving a page, in which case our state may have already been moved to
2473 // the next page. The navigation controller will look up the appropriate
2474 // NavigationEntry and update it when it is notified via the delegate.
2475
2476 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582477 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322478 if (entry_index < 0)
2479 return;
[email protected]10f417c52011-12-28 21:04:232480 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322481
[email protected]36fc0392011-12-25 03:59:512482 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322483 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512484 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322485 controller_.NotifyEntryChanged(entry, entry_index);
2486}
2487
[email protected]b172aee2012-04-10 17:05:262488void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2489 int32 page_id,
2490 const string16& title,
2491 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322492 // If we have a title, that's a pretty good indication that we've started
2493 // getting useful data.
2494 SetNotWaitingForResponse();
2495
[email protected]73eb2602012-02-09 19:50:552496 // Try to find the navigation entry, which might not be the current one.
2497 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232498 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582499 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092500
[email protected]73eb2602012-02-09 19:50:552501 // We can handle title updates when we don't have an entry in
2502 // UpdateTitleForEntry, but only if the update is from the current RVH.
2503 if (!entry && rvh != GetRenderViewHost())
2504 return;
2505
[email protected]a49e10b2011-08-01 23:57:462506 // TODO(evan): make use of title_direction.
2507 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092508 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322509 return;
2510
2511 // Broadcast notifications when the UI should be updated.
2512 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462513 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322514}
2515
[email protected]b172aee2012-04-10 17:05:262516void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2517 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312518 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322519}
2520
[email protected]b172aee2012-04-10 17:05:262521void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512522 if (delegate_)
2523 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322524}
2525
[email protected]b172aee2012-04-10 17:05:262526void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292527 // The UI may be in an event-tracking loop, such as between the
2528 // mouse-down and mouse-up in text selection or a button click.
2529 // Defer the close until after tracking is complete, so that we
2530 // don't free objects out from under the UI.
2531 // TODO(shess): This could probably be integrated with the
2532 // IsDoingDrag() test below. Punting for now because I need more
2533 // research to understand how this impacts platforms other than Mac.
2534 // TODO(shess): This could get more fine-grained. For instance,
2535 // closing a tab in another window while selecting text in the
2536 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212537 if (GetView()->IsEventTracking()) {
2538 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292539 return;
2540 }
2541
[email protected]24a4d1062009-07-10 23:10:422542 // If we close the tab while we're in the middle of a drag, we'll crash.
2543 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212544 if (GetView()->IsDoingDrag()) {
2545 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422546 return;
2547 }
2548
[email protected]420ae012009-04-24 05:16:322549 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522550 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512551 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322552}
2553
[email protected]b172aee2012-04-10 17:05:262554void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522555 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512556 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572557}
2558
[email protected]b172aee2012-04-10 17:05:262559void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512560 if (delegate_ && delegate_->IsPopupOrPanel(this))
2561 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322562}
2563
[email protected]b172aee2012-04-10 17:05:262564void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322565 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492566
[email protected]82114f52012-03-20 22:53:412567 if (delegate_ && content_restrictions_)
2568 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492569
2570 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252571 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322572}
2573
[email protected]b172aee2012-04-10 17:05:262574void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322575 scoped_ptr<LoadNotificationDetails> details;
2576
[email protected]10f417c52011-12-28 21:04:232577 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322578 // An entry may not exist for a stop when loading an initial blank page or
2579 // if an iframe injected by script into a blank page finishes loading.
2580 if (entry) {
[email protected]420ae012009-04-24 05:16:322581 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2582
2583 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512584 entry->GetVirtualURL(),
2585 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322586 elapsed,
2587 &controller_,
2588 controller_.GetCurrentEntryIndex()));
2589 }
2590
[email protected]420ae012009-04-24 05:16:322591 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492592
2593 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252594 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322595}
2596
[email protected]b172aee2012-04-10 17:05:262597void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162598 controller_.DiscardNonCommittedEntries();
2599
2600 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462601 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162602}
2603
[email protected]b172aee2012-04-10 17:05:262604void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512605 if (delegate_)
2606 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402607}
2608
[email protected]87717d0e2012-04-26 02:58:432609void WebContentsImpl::DocumentAvailableInMainFrame(
2610 RenderViewHost* render_view_host) {
2611 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2612 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102613}
2614
[email protected]b172aee2012-04-10 17:05:262615void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082616 RenderViewHost* render_view_host,
2617 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072618 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272619 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322620 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532621 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082622}
2623
[email protected]196159d2012-05-04 17:26:542624void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2625 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262626 const content::Referrer& referrer,
2627 WindowOpenDisposition disposition,
2628 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542629 // If this came from a swapped out RenderViewHost, we only allow the request
2630 // if we are still in the same BrowsingInstance.
2631 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2632 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2633 return;
2634 }
2635
[email protected]4ad5d77d2011-12-03 02:00:482636 // Delegate to RequestTransferURL because this is just the generic
2637 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582638 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482639 GlobalRequestID());
2640}
2641
[email protected]b172aee2012-04-10 17:05:262642void WebContentsImpl::RequestTransferURL(
2643 const GURL& url,
2644 const content::Referrer& referrer,
2645 WindowOpenDisposition disposition,
2646 int64 source_frame_id,
2647 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202648 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582649 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582650 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352651 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322652 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2653 // generated suggestions).
2654 //
[email protected]e0112912011-02-02 22:54:352655 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162656 // want web sites to see a referrer of "chrome://blah" (and some
2657 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322658 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432659 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222660 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482661 false /* is_renderer_initiated */);
2662 params.transferred_global_request_id = old_request_id;
2663 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222664 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322665 } else {
[email protected]6bf6a6b52012-02-03 15:41:432666 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482667 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2668 params.transferred_global_request_id = old_request_id;
2669 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582670 }
2671 if (new_contents) {
2672 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252673 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582674 DidOpenRequestedURL(new_contents,
2675 url,
2676 referrer,
2677 disposition,
2678 transition_type,
2679 source_frame_id));
[email protected]420ae012009-04-24 05:16:322680 }
2681}
2682
[email protected]e1c3a552012-05-04 20:51:322683void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2684 // Tell the active RenderViewHost to run unload handlers and close, as long
2685 // as the request came from a RenderViewHost in the same BrowsingInstance.
2686 // In most cases, we receive this from a swapped out RenderViewHost.
2687 // It is possible to receive it from one that has just been swapped in,
2688 // in which case we might as well deliver the message anyway.
2689 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2690 GetRenderViewHost()->ClosePage();
2691}
2692
[email protected]f546640b2012-05-15 00:03:492693void WebContentsImpl::RouteMessageEvent(
2694 RenderViewHost* rvh,
2695 const ViewMsg_PostMessage_Params& params) {
2696 // Only deliver the message to the active RenderViewHost if the request
2697 // came from a RenderViewHost in the same BrowsingInstance.
2698 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2699 return;
2700
2701 ViewMsg_PostMessage_Params new_params(params);
2702
2703 // If there is a source_routing_id, translate it to the routing ID for
2704 // the equivalent swapped out RVH in the target process. If we need
2705 // to create a swapped out RVH for the source tab, we create its opener
2706 // chain as well, since those will also be accessible to the target page.
2707 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2708 // Try to look up the WebContents for the source page.
2709 WebContentsImpl* source_contents = NULL;
2710 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2711 rvh->GetProcess()->GetID(), params.source_routing_id);
2712 if (source_rvh) {
2713 source_contents = static_cast<WebContentsImpl*>(
2714 source_rvh->GetDelegate()->GetAsWebContents());
2715 }
2716
2717 if (source_contents) {
2718 new_params.source_routing_id =
2719 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2720 } else {
2721 // We couldn't find it, so don't pass a source frame.
2722 new_params.source_routing_id = MSG_ROUTING_NONE;
2723 }
2724 }
2725
2726 // In most cases, we receive this from a swapped out RenderViewHost.
2727 // It is possible to receive it from one that has just been swapped in,
2728 // in which case we might as well deliver the message anyway.
2729 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2730 GetRenderViewHost()->GetRoutingID(), new_params));
2731}
2732
[email protected]b172aee2012-04-10 17:05:262733void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342734 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412735 const string16& message,
2736 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322737 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142738 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322739 IPC::Message* reply_msg,
2740 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072741 // Suppress JavaScript dialogs when requested. Also suppress messages when
2742 // showing an interstitial as it's shown over the previous page and we don't
2743 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502744 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582745 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272746 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072747 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522748 delegate_->ShouldSuppressDialogs() ||
2749 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322750
2751 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432752 std::string accept_lang = content::GetContentClient()->browser()->
2753 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552754 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522755 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432756 this,
2757 frame_url.GetOrigin(),
2758 accept_lang,
2759 javascript_message_type,
2760 message,
[email protected]51da7e32012-01-30 19:24:522761 default_prompt,
[email protected]b172aee2012-04-10 17:05:262762 base::Bind(&WebContentsImpl::OnDialogClosed,
2763 base::Unretained(this),
2764 rvh,
2765 reply_msg),
[email protected]51da7e32012-01-30 19:24:522766 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322767 }
[email protected]3ab9cb82011-06-03 18:02:072768
2769 if (suppress_this_message) {
2770 // If we are suppressing messages, just reply as if the user immediately
2771 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342772 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072773 }
2774
2775 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322776}
2777
[email protected]b172aee2012-04-10 17:05:262778void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2779 const string16& message,
2780 bool is_reload,
2781 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582782 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512783 if (delegate_)
2784 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072785
2786 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582787 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072788 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522789 delegate_->ShouldSuppressDialogs() ||
2790 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152791 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342792 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582793 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502794 return;
2795 }
[email protected]3ab9cb82011-06-03 18:02:072796
[email protected]7ab1e7d62009-10-14 23:32:012797 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552798 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522799 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322800 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262801 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522802 reply_msg));
[email protected]420ae012009-04-24 05:16:322803}
2804
[email protected]a796f202012-05-30 14:14:252805bool WebContentsImpl::AddMessageToConsole(int32 level,
2806 const string16& message,
2807 int32 line_no,
2808 const string16& source_id) {
2809 if (!delegate_)
2810 return false;
2811 return delegate_->AddMessageToConsole(this, level, message, line_no,
2812 source_id);
2813}
2814
[email protected]b172aee2012-04-10 17:05:262815WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332816 // We want to base the page config off of the real URL, rather than the
2817 // display URL.
2818 GURL url = controller_.GetActiveEntry()
2819 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2820 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322821}
2822
[email protected]b172aee2012-04-10 17:05:262823void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272824 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252825 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222826
[email protected]ea114722012-03-12 01:11:252827 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172828 if (rdh) // NULL in unittests.
2829 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252830}
2831
[email protected]b172aee2012-04-10 17:05:262832void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442833 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252834 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2838 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152839 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522840 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152841 return;
2842
[email protected]9f76c1e2012-03-05 15:15:582843 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2844
[email protected]e5fc1632011-08-08 07:51:532845 // Ignore renderer unresponsive event if debugger is attached to the tab
2846 // since the event may be a result of the renderer sitting on a breakpoint.
2847 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442848 DevToolsAgentHost* agent =
2849 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2850 if (agent &&
2851 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532852 return;
2853
[email protected]420ae012009-04-24 05:16:322854 if (is_during_unload) {
2855 // Hang occurred while firing the beforeunload/unload handler.
2856 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582857 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322858
2859 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2860 return;
2861
2862 // If the tab hangs in the beforeunload/unload handler there's really
2863 // nothing we can do to recover. Pretend the unload listeners have
2864 // all fired and close the tab. If the hang is in the beforeunload handler
2865 // then the user will not have the option of cancelling the close.
2866 Close(rvh);
2867 return;
2868 }
2869
[email protected]9f76c1e2012-03-05 15:15:582870 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472871 return;
2872
[email protected]6934a702011-12-20 00:04:512873 if (delegate_)
2874 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322875}
2876
[email protected]b172aee2012-04-10 17:05:262877void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512878 if (delegate_)
2879 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322880}
2881
[email protected]b172aee2012-04-10 17:05:262882void WebContentsImpl::LoadStateChanged(
2883 const GURL& url,
2884 const net::LoadStateWithParam& load_state,
2885 uint64 upload_position,
2886 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322887 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562888 upload_position_ = upload_position;
2889 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502890 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202891 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302892 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212893 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322894 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462895 if (IsLoading()) {
2896 NotifyNavigationStateChanged(
2897 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2898 }
[email protected]420ae012009-04-24 05:16:322899}
2900
[email protected]b172aee2012-04-10 17:05:262901void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512902 if (delegate_)
2903 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252904}
2905
[email protected]b172aee2012-04-10 17:05:262906void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322907 bool proceed,
2908 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512909 if (delegate_)
2910 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]b172aee2012-04-10 17:05:262913void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542914 RenderViewHost* render_view_host) {
2915 DidStartLoading();
2916}
2917
[email protected]b172aee2012-04-10 17:05:262918void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542919 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232920 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2921 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542922}
2923
[email protected]b172aee2012-04-10 17:05:262924void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102925 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262926 gfx::Size size = view_->GetContainerSize();
2927 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2928 // here during container initialization and normal window size will be set
2929 // later. In case of tab duplication this resizing to 0x0 prevents setting
2930 // normal size later so just ignore it.
2931 if (!size.IsEmpty())
2932 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322933}
2934
[email protected]b172aee2012-04-10 17:05:262935void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542936 NotifySwapped();
2937}
2938
[email protected]14392a52012-05-02 20:28:442939int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2940 SiteInstance* instance) {
2941 if (!opener_)
2942 return MSG_ROUTING_NONE;
2943
2944 // Recursively create RenderViews for anything else in the opener chain.
2945 return opener_->CreateOpenerRenderViews(instance);
2946}
2947
2948int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2949 int opener_route_id = MSG_ROUTING_NONE;
2950
2951 // If this tab has an opener, ensure it has a RenderView in the given
2952 // SiteInstance as well.
2953 if (opener_)
2954 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2955
2956 // Create a swapped out RenderView in the given SiteInstance if none exists,
2957 // setting its opener to the given route_id. Return the new view's route_id.
2958 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2959}
2960
[email protected]b172aee2012-04-10 17:05:262961NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202962 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542963}
2964
[email protected]b172aee2012-04-10 17:05:262965WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562966 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322967}
2968
[email protected]10f417c52011-12-28 21:04:232969NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262970 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322971 return controller_.GetLastCommittedEntry();
2972}
2973
[email protected]b172aee2012-04-10 17:05:262974bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442975 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442976 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322977 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522978
[email protected]420ae012009-04-24 05:16:322979 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442980 if (rwh_view)
2981 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322982
[email protected]74ce1ad2011-12-16 21:51:462983 // Make sure we use the correct starting page_id in the new RenderView.
2984 UpdateMaxPageIDIfNecessary(render_view_host);
2985 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582986 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462987
[email protected]7900bfdb2012-05-24 19:31:242988 std::string embedder_channel_name;
2989 int embedder_container_id;
2990 GetBrowserPluginEmbedderInfo(render_view_host,
2991 &embedder_channel_name,
2992 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:582993 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492994 render_view_host)->CreateRenderView(string16(),
2995 opener_route_id,
2996 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:242997 embedder_channel_name,
2998 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:522999 return false;
[email protected]14392a52012-05-02 20:28:443000 }
[email protected]a4127722011-04-27 23:13:523001
[email protected]e60c0232011-11-11 19:56:353002#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503003 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3004 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443005 if (rwh_view) {
3006 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3007 render_widget_host->WasResized();
3008 }
[email protected]f8233cc2011-05-31 20:24:503009#endif
3010
[email protected]420ae012009-04-24 05:16:323011 return true;
3012}
3013
[email protected]b172aee2012-04-10 17:05:263014void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3015 IPC::Message* reply_msg,
3016 bool success,
3017 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543018 if (is_showing_before_unload_dialog_ && !success) {
3019 // If a beforeunload dialog is canceled, we need to stop the throbber from
3020 // spinning, since we forced it to start spinning in Navigate.
3021 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:353022 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543023
[email protected]3bbacc5b2012-04-17 17:46:153024 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543025 }
3026 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583027 static_cast<RenderViewHostImpl*>(
3028 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543029}
3030
[email protected]b172aee2012-04-10 17:05:263031void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123032 encoding_ = content::GetContentClient()->browser()->
3033 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103034}
[email protected]f45d2a72010-03-08 23:28:353035
[email protected]b172aee2012-04-10 17:05:263036void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463037 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263038 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573039 DownloadManager* dlm =
3040 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143041 if (!dlm)
3042 return;
3043 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263044 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143045 const NavigationEntry* entry = controller_.GetActiveEntry();
3046 if (entry)
3047 post_id = entry->GetPostID();
3048 }
[email protected]29a5ffc82012-03-13 19:35:583049 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143050 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143051 scoped_ptr<DownloadUrlParameters> params(
3052 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493053 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143054 params->set_post_id(post_id);
3055 params->set_prefer_cache(true);
3056 if (post_id >= 0)
3057 params->set_method("POST");
3058 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143059}
3060
[email protected]b172aee2012-04-10 17:05:263061void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213062 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443063 // Can be NULL during tests.
3064 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213065 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363066}
[email protected]9f76c1e2012-03-05 15:15:583067
[email protected]b172aee2012-04-10 17:05:263068RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583069 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3070}
[email protected]7900bfdb2012-05-24 19:31:243071
3072void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3073 content::RenderViewHost* render_view_host,
3074 std::string* embedder_channel_name,
3075 int* embedder_container_id) {
3076 content::RenderProcessHost* embedder_render_process_host =
3077 browser_plugin_host()->embedder_render_process_host();
3078 *embedder_container_id = browser_plugin_host()->instance_id();
3079 int embedder_process_id =
3080 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3081 if (embedder_process_id != -1) {
3082 *embedder_channel_name =
3083 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3084 embedder_process_id);
3085 }
3086}