blob: 6d5453aa662cdf1de7d2aa4fec73f9603ce147bf [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]64d69de42012-02-06 00:19:54492
493#if defined(OS_MACOSX)
494 bool default_enable_scroll_animator = true;
495#else
496 // On CrOS, the launcher always passes in the --enable flag.
497 bool default_enable_scroll_animator = false;
498#endif
499 prefs.enable_scroll_animator = default_enable_scroll_animator;
500 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
501 prefs.enable_scroll_animator = true;
502 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
503 prefs.enable_scroll_animator = false;
504
505 prefs.visual_word_movement_enabled =
506 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54507
508 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32509 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54510 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11511 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
512 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54513 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11514 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54515 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19516 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
517 prefs.flash_3d_enabled = false;
518 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
519 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11520 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54521 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11522 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54523 prefs.gl_multisampling_enabled = false;
524
525 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45526 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32527 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54528 prefs.accelerated_video_enabled = false;
529 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45530 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09531 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54532 }
533 }
534
[email protected]b9535422012-02-09 01:47:59535 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58536 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54537 prefs.loads_images_automatically = true;
538 prefs.javascript_enabled = true;
539 }
540
541 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
542
543 // Force accelerated compositing and 2d canvas off for chrome:, about: and
544 // chrome-devtools: pages (unless it's specifically allowed).
545 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54546 url.SchemeIs(chrome::kChromeUIScheme) ||
547 (url.SchemeIs(chrome::kAboutScheme) &&
548 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25549 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54550 prefs.accelerated_compositing_enabled = false;
551 prefs.accelerated_2d_canvas_enabled = false;
552 }
[email protected]43d9d782012-03-01 15:40:09553
[email protected]302fe422012-06-11 14:49:11554#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
555 prefs.threaded_animation_enabled =
556 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
557 prefs.per_tile_painting_enabled =
558 command_line.HasSwitch(switches::kEnablePerTilePainting);
559 prefs.partial_swap_enabled =
560 command_line.HasSwitch(switches::kEnablePartialSwap);
561#endif
562
[email protected]f98f5092012-05-19 00:08:14563 if (command_line.HasSwitch(switches::kDefaultTileWidth))
564 prefs.default_tile_width =
565 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
566 if (command_line.HasSwitch(switches::kDefaultTileHeight))
567 prefs.default_tile_height =
568 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
569 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
570 prefs.max_untiled_layer_width =
571 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
572 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
573 prefs.max_untiled_layer_height =
574 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
575
[email protected]2486dce2012-05-23 17:18:19576 if (gfx::Screen::IsDIPEnabled()) {
577 // Only apply when using DIP coordinate system as this setting interferes
578 // with fixed layout mode.
579 prefs.apply_default_device_scale_factor_in_compositor = true;
580 }
581
[email protected]96bcdc102012-05-24 23:42:10582 prefs.fixed_position_creates_stacking_context =
583 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
584
[email protected]6b4dcb072012-06-18 22:26:51585 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
586
[email protected]2e21fe292012-03-02 22:52:32587 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54588
589 return prefs;
590}
591
[email protected]b172aee2012-04-10 17:05:26592NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20593 return controller_;
594}
595
[email protected]b172aee2012-04-10 17:05:26596RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28597 return &render_manager_;
598}
599
[email protected]b172aee2012-04-10 17:05:26600bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56601 if (GetWebUI() &&
602 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17603 return true;
[email protected]d2353452012-01-19 19:53:56604 }
[email protected]f82d57b52011-04-27 19:13:17605
[email protected]d8c660432011-12-22 20:51:25606 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
607 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10608 while ((observer = it.GetNext()) != NULL)
609 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53610 return true;
[email protected]403415a2011-01-10 18:57:53611
[email protected]724159a2010-12-30 01:11:18612 bool handled = true;
613 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26614 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58615 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
616 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24617 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
618 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18619 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
620 OnDidLoadResourceFromMemoryCache)
621 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
622 OnDidDisplayInsecureContent)
623 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
624 OnDidRunInsecureContent)
625 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
626 OnDocumentLoadedInFrame)
627 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26628 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
629 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17630 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
631 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25632 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26633 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59634 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21635 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20636 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
637 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
638 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16639 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45640 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10641 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20642 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
643 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
644 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
645 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29646 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50647 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18648 IPC_MESSAGE_UNHANDLED(handled = false)
649 IPC_END_MESSAGE_MAP_EX()
650
651 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38652 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18653 GetRenderProcessHost()->ReceivedBadMessage();
654 }
655
656 return handled;
657}
658
[email protected]b172aee2012-04-10 17:05:26659void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18660 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23661 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51662 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18663}
664
[email protected]b172aee2012-04-10 17:05:26665NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56666 return controller_;
667}
668
[email protected]b172aee2012-04-10 17:05:26669const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56670 return controller_;
671}
672
[email protected]b172aee2012-04-10 17:05:26673content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55674 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30675}
676
[email protected]b172aee2012-04-10 17:05:26677const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31678 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23679 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51680 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31681}
682
683
[email protected]b172aee2012-04-10 17:05:26684const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31685 return &property_bag_;
686}
687
[email protected]b172aee2012-04-10 17:05:26688base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31689 return &property_bag_;
690}
691
[email protected]b172aee2012-04-10 17:05:26692content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31693 return delegate_;
694}
695
[email protected]b172aee2012-04-10 17:05:26696void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31697 // TODO(cbentzel): remove this debugging code?
698 if (delegate == delegate_)
699 return;
700 if (delegate_)
701 delegate_->Detach(this);
702 delegate_ = delegate;
703 if (delegate_)
704 delegate_->Attach(this);
705}
706
[email protected]b172aee2012-04-10 17:05:26707content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41708 RenderViewHostImpl* host = render_manager_.current_host();
709 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16710}
711
[email protected]b172aee2012-04-10 17:05:26712RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31713 return render_manager_.current_host();
714}
715
[email protected]b172aee2012-04-10 17:05:26716RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return render_manager_.GetRenderWidgetHostView();
718}
719
[email protected]b172aee2012-04-10 17:05:26720content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31721 return view_.get();
722}
723
[email protected]b172aee2012-04-10 17:05:26724content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50725 WebUIControllerFactory* factory =
726 content::GetContentClient()->browser()->GetWebUIControllerFactory();
727 if (!factory)
728 return NULL;
[email protected]d2353452012-01-19 19:53:56729 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22730 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50731 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22732 if (controller) {
733 web_ui->SetController(controller);
734 return web_ui;
735 }
736
737 delete web_ui;
738 return NULL;
739}
740
[email protected]b172aee2012-04-10 17:05:26741content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31742 return render_manager_.web_ui() ? render_manager_.web_ui()
743 : render_manager_.pending_web_ui();
744}
745
[email protected]b172aee2012-04-10 17:05:26746content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31747 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34748}
749
[email protected]86ef6a392012-05-11 22:03:11750void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22751 if (GetUserAgentOverride() == override)
752 return;
753
754 renderer_preferences_.user_agent_override = override;
755
756 // Send the new override string to the renderer.
757 RenderViewHost* host = GetRenderViewHost();
758 if (host)
759 host->SyncRendererPrefs();
760
761 // Reload the page if a load is currently in progress to avoid having
762 // different parts of the page loaded using different user agents.
763 NavigationEntry* entry = controller_.GetActiveEntry();
764 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
765 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11766}
767
768const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22769 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11770}
771
[email protected]b172aee2012-04-10 17:05:26772const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55773 // Transient entries take precedence. They are used for interstitial pages
774 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23775 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08776 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20777 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30778 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23779 if (entry) {
[email protected]b5cca982011-05-26 04:42:08780 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23781 }
[email protected]7ade2732011-02-10 00:13:58782 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
783 render_manager_.pending_web_ui() : render_manager_.web_ui();
784 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54785 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55786 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54787 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35788 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22789 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54790 if (!title.empty())
791 return title;
792 }
793 }
794
795 // We use the title for the last committed entry rather than a pending
796 // navigation entry. For example, when the user types in a URL, we want to
797 // keep the old page's title until the new load has committed and we get a new
798 // title.
[email protected]96d185d2009-04-24 03:28:54799 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23800 if (entry) {
[email protected]b5cca982011-05-26 04:42:08801 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23802 }
[email protected]987fc3a2011-05-26 14:18:09803
804 // |page_title_when_no_navigation_entry_| is finally used
805 // if no title cannot be retrieved.
806 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54807}
808
[email protected]b172aee2012-04-10 17:05:26809int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46810 return GetMaxPageIDForSiteInstance(GetSiteInstance());
811}
812
[email protected]b172aee2012-04-10 17:05:26813int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
814 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33815 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
816 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46817
[email protected]b6583592012-01-25 19:52:33818 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34819}
820
[email protected]b172aee2012-04-10 17:05:26821void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46822 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
823}
824
[email protected]b172aee2012-04-10 17:05:26825void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33826 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46827 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33828 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34829}
830
[email protected]b172aee2012-04-10 17:05:26831void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
832 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57833}
834
[email protected]b172aee2012-04-10 17:05:26835SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58836 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54837}
838
[email protected]b172aee2012-04-10 17:05:26839SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38840 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
841 render_manager_.pending_render_view_host() :
842 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58843 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38844}
845
[email protected]b172aee2012-04-10 17:05:26846bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49848}
849
[email protected]b172aee2012-04-10 17:05:26850bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return waiting_for_response_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return load_state_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return load_state_host_;
860}
861
[email protected]b172aee2012-04-10 17:05:26862uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31863 return upload_size_;
864}
865
[email protected]b172aee2012-04-10 17:05:26866uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return upload_position_;
868}
869
[email protected]b172aee2012-04-10 17:05:26870const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return encoding_;
872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return displayed_insecure_content_;
876}
877
[email protected]b172aee2012-04-10 17:05:26878void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31879 capturing_contents_ = cap;
880}
881
[email protected]b172aee2012-04-10 17:05:26882bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
884 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
885 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49886}
887
[email protected]b172aee2012-04-10 17:05:26888void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
889 int error_code) {
[email protected]443b80e2010-12-14 00:42:23890 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34891 return;
892
[email protected]443b80e2010-12-14 00:42:23893 crashed_status_ = status;
894 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46895 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34896}
897
[email protected]b172aee2012-04-10 17:05:26898base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31899 return crashed_status_;
900}
901
[email protected]b172aee2012-04-10 17:05:26902bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31903 return is_being_destroyed_;
904}
905
[email protected]b172aee2012-04-10 17:05:26906void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34907 if (delegate_)
908 delegate_->NavigationStateChanged(this, changed_flags);
909}
910
[email protected]3e324142012-06-25 18:26:33911base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
912 return last_selected_time_;
913}
914
915void WebContentsImpl::WasRestored() {
[email protected]96d185d2009-04-24 03:28:54916 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04917 RenderWidgetHostViewPort* rwhv =
918 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16919 if (rwhv) {
[email protected]3e324142012-06-25 18:26:33920 rwhv->WasRestored();
[email protected]789e9152009-08-04 21:59:43921#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16922 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43923#endif
924 }
[email protected]96d185d2009-04-24 03:28:54925
[email protected]5ac20162010-11-24 23:33:11926 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38927
[email protected]3e324142012-06-25 18:26:33928 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasRestored());
[email protected]b9769d82012-02-10 00:23:59929
930 // The resize rect might have changed while this was inactive -- send the new
931 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58932 RenderViewHostImpl* rvh =
933 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59934 if (rvh) {
935 rvh->ResizeRectChanged(GetRootWindowResizerRect());
936 }
[email protected]96d185d2009-04-24 03:28:54937
[email protected]3e324142012-06-25 18:26:33938 bool is_visible = true;
939 content::NotificationService::current()->Notify(
940 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
941 content::Source<WebContents>(this),
942 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31943}
944
[email protected]b172aee2012-04-10 17:05:26945void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31946 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52947 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
948 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26949 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52950 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33951 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52952 // calls us).
[email protected]c30585c2012-02-16 15:02:04953 RenderWidgetHostViewPort* rwhv =
954 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16955 if (rwhv)
956 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54957 }
958
[email protected]375fa1b2012-05-22 22:05:37959 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07960 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37961 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09962 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37963 content::Details<bool>(&is_visible));
964}
965
[email protected]b172aee2012-04-10 17:05:26966bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31967 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27968 return WillNotifyDisconnection() &&
969 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58970 !static_cast<RenderViewHostImpl*>(
971 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31972}
973
[email protected]b172aee2012-04-10 17:05:26974void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27975 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25976 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27977}
978
[email protected]b172aee2012-04-10 17:05:26979WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44980 // We use our current SiteInstance since the cloned entry will use it anyway.
981 // We pass |this| for the |base_web_contents| to size the view correctly, and
982 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26983 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44984 GetBrowserContext(), GetSiteInstance(),
985 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20986 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27987 return tc;
988}
989
[email protected]b172aee2012-04-10 17:05:26990void WebContentsImpl::AddNewContents(WebContents* new_contents,
991 WindowOpenDisposition disposition,
992 const gfx::Rect& initial_pos,
993 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27994 if (!delegate_)
995 return;
996
997 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
998 user_gesture);
999}
1000
[email protected]b172aee2012-04-10 17:05:261001gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271002 return view_->GetContentNativeView();
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271006 return view_->GetNativeView();
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271010 view_->GetContainerBounds(out);
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271014 view_->Focus();
1015}
1016
[email protected]14392a52012-05-02 20:28:441017void WebContentsImpl::Observe(int type,
1018 const content::NotificationSource& source,
1019 const content::NotificationDetails& details) {
1020 switch (type) {
1021 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1022 OnWebContentsDestroyed(
1023 content::Source<content::WebContents>(source).ptr());
1024 break;
[email protected]bafe6cd2012-05-23 23:09:501025 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1026 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1027 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1028 i != pending_widget_views_.end(); ++i) {
1029 if (host->GetView() == i->second) {
1030 pending_widget_views_.erase(i);
1031 break;
1032 }
1033 }
1034 break;
1035 }
[email protected]14392a52012-05-02 20:28:441036 default:
1037 NOTREACHED();
1038 }
1039}
1040
1041void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1042 // Clear the opener if it has been closed.
1043 if (web_contents == opener_) {
1044 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1045 content::Source<WebContents>(opener_));
1046 opener_ = NULL;
1047 }
1048}
1049
[email protected]b172aee2012-04-10 17:05:261050void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311051 observers_.AddObserver(observer);
1052}
1053
[email protected]b172aee2012-04-10 17:05:261054void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311055 observers_.RemoveObserver(observer);
1056}
1057
[email protected]b172aee2012-04-10 17:05:261058void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341059 if (delegate_)
1060 delegate_->ActivateContents(this);
1061}
1062
[email protected]b172aee2012-04-10 17:05:261063void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121064 if (delegate_)
1065 delegate_->DeactivateContents(this);
1066}
1067
[email protected]b172aee2012-04-10 17:05:261068void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481069 if (delegate_)
1070 delegate_->LostCapture();
1071}
1072
[email protected]b172aee2012-04-10 17:05:261073bool WebContentsImpl::PreHandleKeyboardEvent(
1074 const NativeWebKeyboardEvent& event,
1075 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481076 return delegate_ &&
1077 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1078}
1079
[email protected]b172aee2012-04-10 17:05:261080void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481081 if (delegate_)
1082 delegate_->HandleKeyboardEvent(event);
1083}
1084
[email protected]b172aee2012-04-10 17:05:261085void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431086 if (delegate_)
1087 delegate_->HandleMouseDown();
1088}
1089
[email protected]b172aee2012-04-10 17:05:261090void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481091 if (delegate_)
1092 delegate_->HandleMouseUp();
1093}
1094
[email protected]b172aee2012-04-10 17:05:261095void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481096 if (delegate_)
1097 delegate_->HandleMouseActivate();
1098}
1099
[email protected]b172aee2012-04-10 17:05:261100void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471101 if (delegate_)
1102 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1103}
1104
[email protected]b172aee2012-04-10 17:05:261105bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381106 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121107}
1108
[email protected]a9c81f02012-06-01 00:15:441109void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1110 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371111 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441112 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371113 } else {
1114 GotResponseToLockMouseRequest(false);
1115 }
1116}
1117
[email protected]b172aee2012-04-10 17:05:261118void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371119 if (delegate_)
1120 delegate_->LostMouseLock();
1121}
1122
[email protected]bafe6cd2012-05-23 23:09:501123void WebContentsImpl::CreateNewWindow(
1124 int route_id,
[email protected]97714c82012-06-06 10:15:131125 const ViewHostMsg_CreateWindow_Params& params,
1126 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501127 if (delegate_ && !delegate_->ShouldCreateWebContents(
1128 this, route_id, params.window_container_type, params.frame_name,
1129 params.target_url)) {
1130 return;
1131 }
1132
1133 // We usually create the new window in the same BrowsingInstance (group of
1134 // script-related windows), by passing in the current SiteInstance. However,
1135 // if the opener is being suppressed, we create a new SiteInstance in its own
1136 // BrowsingInstance.
1137 scoped_refptr<SiteInstance> site_instance =
1138 params.opener_suppressed ?
1139 SiteInstance::Create(GetBrowserContext()) :
1140 GetSiteInstance();
1141
1142 // Create the new web contents. This will automatically create the new
1143 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131144 WebContentsImpl* new_contents = new WebContentsImpl(
1145 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571146 site_instance,
1147 route_id,
1148 this,
1149 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131150 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501151 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1152
1153 if (!params.opener_suppressed) {
1154 content::WebContentsView* new_view = new_contents->GetView();
1155
1156 // TODO(brettw): It seems bogus that we have to call this function on the
1157 // newly created object and give it one of its own member variables.
1158 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1159
1160 // Save the created window associated with the route so we can show it
1161 // later.
1162 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1163 pending_contents_[route_id] = new_contents;
1164 }
1165
1166 if (delegate_) {
1167 delegate_->WebContentsCreated(
1168 this, params.opener_frame_id, params.target_url, new_contents);
1169 }
1170
1171 if (params.opener_suppressed) {
1172 // When the opener is suppressed, the original renderer cannot access the
1173 // new window. As a result, we need to show and navigate the window here.
1174 gfx::Rect initial_pos;
1175 AddNewContents(
1176 new_contents, params.disposition, initial_pos, params.user_gesture);
1177
1178 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1179 CURRENT_TAB,
1180 content::PAGE_TRANSITION_LINK,
1181 true /* is_renderer_initiated */);
1182 new_contents->OpenURL(open_params);
1183 }
1184}
1185
1186void WebContentsImpl::CreateNewWidget(int route_id,
1187 WebKit::WebPopupType popup_type) {
1188 CreateNewWidget(route_id, false, popup_type);
1189}
1190
1191void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1192 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1193}
1194
1195void WebContentsImpl::CreateNewWidget(int route_id,
1196 bool is_fullscreen,
1197 WebKit::WebPopupType popup_type) {
1198 content::RenderProcessHost* process = GetRenderProcessHost();
1199 RenderWidgetHostImpl* widget_host =
1200 new RenderWidgetHostImpl(this, process, route_id);
1201 RenderWidgetHostViewPort* widget_view =
1202 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1203 if (!is_fullscreen) {
1204 // Popups should not get activated.
1205 widget_view->SetPopupType(popup_type);
1206 }
1207 // Save the created widget associated with the route so we can show it later.
1208 pending_widget_views_[route_id] = widget_view;
1209
1210#if defined(OS_MACOSX)
1211 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1212 // to allow it to survive the trip without being hosted.
1213 base::mac::NSObjectRetain(widget_view->GetNativeView());
1214#endif
1215}
1216
1217void WebContentsImpl::ShowCreatedWindow(int route_id,
1218 WindowOpenDisposition disposition,
1219 const gfx::Rect& initial_pos,
1220 bool user_gesture) {
1221 WebContentsImpl* contents = GetCreatedWindow(route_id);
1222 if (contents)
1223 AddNewContents(contents, disposition, initial_pos, user_gesture);
1224}
1225
1226void WebContentsImpl::ShowCreatedWidget(int route_id,
1227 const gfx::Rect& initial_pos) {
1228 ShowCreatedWidget(route_id, false, initial_pos);
1229}
1230
1231void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1232 ShowCreatedWidget(route_id, true, gfx::Rect());
1233}
1234
1235void WebContentsImpl::ShowCreatedWidget(int route_id,
1236 bool is_fullscreen,
1237 const gfx::Rect& initial_pos) {
1238 if (delegate_)
1239 delegate_->RenderWidgetShowing();
1240
1241 RenderWidgetHostViewPort* widget_host_view =
1242 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1243 if (!widget_host_view)
1244 return;
1245 if (is_fullscreen) {
1246 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1247 } else {
1248 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1249 }
[email protected]89054502012-06-03 10:29:241250
1251 RenderWidgetHostImpl* render_widget_host_impl =
1252 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1253 render_widget_host_impl->Init();
1254 // Only allow privileged mouse lock for fullscreen render widget, which is
1255 // used to implement Pepper Flash fullscreen.
1256 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501257
1258#if defined(OS_MACOSX)
1259 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1260 // properly embedded (or purposefully ignored) we can release the retain we
1261 // took in CreateNewWidget().
1262 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1263#endif
1264}
1265
1266WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1267 PendingContents::iterator iter = pending_contents_.find(route_id);
1268
1269 // Certain systems can block the creation of new windows. If we didn't succeed
1270 // in creating one, just return NULL.
1271 if (iter == pending_contents_.end()) {
1272 return NULL;
1273 }
1274
1275 WebContentsImpl* new_contents = iter->second;
1276 pending_contents_.erase(route_id);
1277
1278 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1279 !new_contents->GetRenderViewHost()->GetView())
1280 return NULL;
1281
1282 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1283 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1284 return new_contents;
1285}
1286
1287RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1288 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1289 if (iter == pending_widget_views_.end()) {
1290 DCHECK(false);
1291 return NULL;
1292 }
1293
1294 RenderWidgetHostView* widget_host_view = iter->second;
1295 pending_widget_views_.erase(route_id);
1296
1297 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1298 if (!widget_host->GetProcess()->HasConnection()) {
1299 // The view has gone away or the renderer crashed. Nothing to do.
1300 return NULL;
1301 }
1302
1303 return widget_host_view;
1304}
1305
1306void WebContentsImpl::ShowContextMenu(
1307 const content::ContextMenuParams& params) {
1308 // Allow WebContentsDelegates to handle the context menu operation first.
1309 if (delegate_ && delegate_->HandleContextMenu(params))
1310 return;
1311
[email protected]5a3bdf52012-05-24 15:12:571312 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501313}
1314
[email protected]f13b4202012-06-12 23:53:231315void WebContentsImpl::RequestMediaAccessPermission(
1316 const content::MediaStreamRequest* request,
1317 const content::MediaResponseCallback& callback) {
1318 if (delegate_)
1319 delegate_->RequestMediaAccessPermission(this, request, callback);
1320 else
1321 callback.Run(content::MediaStreamDevices());
1322}
1323
[email protected]b172aee2012-04-10 17:05:261324void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231325 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331326 if (delegate_)
1327 delegate_->UpdatePreferredSize(this, pref_size);
1328}
1329
[email protected]b172aee2012-04-10 17:05:261330void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341331 if (delegate_)
1332 delegate_->ResizeDueToAutoResize(this, new_size);
1333}
1334
[email protected]b172aee2012-04-10 17:05:261335WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201336 if (!delegate_)
1337 return NULL;
[email protected]00c37fc2011-08-02 00:22:501338
[email protected]e5d549d2011-12-28 01:29:201339 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1340 // Notify observers.
1341 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1342 DidOpenURL(params.url, params.referrer,
1343 params.disposition, params.transition));
1344 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341345}
1346
[email protected]b172aee2012-04-10 17:05:261347bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501348 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251349 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231350 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251351 reload_type);
[email protected]876bc832010-09-07 16:29:541352}
[email protected]96d185d2009-04-24 03:28:541353
[email protected]ba45bfd2012-05-22 21:51:441354void WebContentsImpl::RenderViewForInterstitialPageCreated(
1355 content::RenderViewHost* render_view_host) {
1356 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1357 RenderViewForInterstitialPageCreated(render_view_host));
1358}
1359
[email protected]b172aee2012-04-10 17:05:261360bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231361 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501362 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401363 // The renderer will reject IPC messages with URLs longer than
1364 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511365 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401366 return false;
1367
[email protected]9f76c1e2012-03-05 15:15:581368 RenderViewHostImpl* dest_render_view_host =
1369 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401370 if (!dest_render_view_host)
1371 return false; // Unable to create the desired render view host.
1372
[email protected]80a8fad2011-01-29 04:02:381373 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071374 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581375 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501376 WebUIControllerFactory* factory =
1377 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271378 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501379 bool is_allowed_in_web_ui_renderer =
1380 factory &&
[email protected]24e18252012-04-16 21:26:271381 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1382 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231383 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1384 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271385 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231386 content::GetContentClient()->SetActiveURL(entry.GetURL());
1387 CHECK(0);
1388 }
[email protected]54ec6472010-04-09 19:39:581389
[email protected]96d185d2009-04-24 03:28:541390 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441391 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521392 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441393 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511394 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541395
1396 // Used for page load time metrics.
1397 current_load_start_ = base::TimeTicks::Now();
1398
1399 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241400 std::string embedder_channel_name;
1401 int embedder_container_id;
1402 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1403 &embedder_channel_name,
1404 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341405 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271406 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241407 embedder_channel_name,
1408 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471409 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341410 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541411
[email protected]36fc0392011-12-25 03:59:511412 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541413 // HACK!! This code suppresses javascript: URLs from being added to
1414 // session history, which is what we want to do for javascript: URLs that
1415 // do not generate content. What we really need is a message from the
1416 // renderer telling us that a new page was not created. The same message
1417 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511418 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541419 return false;
1420 }
1421
[email protected]3c9e1872010-11-18 16:17:491422 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251423 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041424 observers_,
[email protected]36fc0392011-12-25 03:59:511425 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541426
[email protected]09b29342011-06-24 19:18:481427 if (delegate_)
1428 delegate_->DidNavigateToPendingEntry(this);
1429
[email protected]d5f942ba2008-09-26 19:30:341430 return true;
1431}
1432
[email protected]b172aee2012-04-10 17:05:261433void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331434 const SiteInstance* site_instance,
1435 int history_length,
1436 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411437 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1438 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191439 if (render_manager_.pending_render_view_host()) {
1440 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141441 return;
[email protected]9e1ad4b2011-08-14 16:49:191442 }
[email protected]9f76c1e2012-03-05 15:15:581443 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191444 if (!rvh) {
1445 NOTREACHED();
1446 return;
1447 }
[email protected]9f76c1e2012-03-05 15:15:581448 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191449 NOTREACHED();
1450 return;
1451 }
[email protected]9f76c1e2012-03-05 15:15:581452 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191453 history_length,
1454 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141455}
1456
[email protected]b172aee2012-04-10 17:05:261457void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271458 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541459 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1460 return;
1461 }
[email protected]9f76c1e2012-03-05 15:15:581462 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541463}
1464
[email protected]b172aee2012-04-10 17:05:261465bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271466 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541467}
1468
[email protected]b172aee2012-04-10 17:05:261469InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271470 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221471}
1472
[email protected]b172aee2012-04-10 17:05:261473bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161474 // WebKit creates Document object when MIME type is application/xhtml+xml,
1475 // so we also support this MIME type.
1476 return contents_mime_type_ == "text/html" ||
1477 contents_mime_type_ == "text/xml" ||
1478 contents_mime_type_ == "application/xhtml+xml" ||
1479 contents_mime_type_ == "text/plain" ||
1480 contents_mime_type_ == "text/css" ||
1481 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1482}
1483
[email protected]b172aee2012-04-10 17:05:261484void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591485 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161486 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481487 download_stats::RecordDownloadSource(
1488 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461489 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141490 return;
[email protected]c7dd2f62011-07-18 15:57:591491 }
1492
1493 Stop();
1494
1495 // Create the save package and possibly prompt the user for the name to save
1496 // the page as. The user prompt is an asynchronous operation that runs on
1497 // another thread.
1498 save_package_ = new SavePackage(this);
1499 save_package_->GetSaveInfo();
1500}
1501
1502// Used in automated testing to bypass prompting the user for file names.
1503// Instead, the names and paths are hard coded rather than running them through
1504// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261505bool WebContentsImpl::SavePage(const FilePath& main_file,
1506 const FilePath& dir_path,
1507 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591508 // Stop the page from navigating.
1509 Stop();
1510
1511 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271512 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591513}
1514
[email protected]b172aee2012-04-10 17:05:261515void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121516 const FilePath& file,
1517 const base::Callback<void(const FilePath&, int64)>& callback) {
1518 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1519}
1520
[email protected]b172aee2012-04-10 17:05:261521bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231522 NavigationEntryImpl* active_entry =
1523 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321524 return (active_entry != NULL &&
1525 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511526 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321527}
1528
[email protected]b172aee2012-04-10 17:05:261529const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271530 return contents_mime_type_;
1531}
1532
[email protected]b172aee2012-04-10 17:05:261533bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271534 return notify_disconnection_;
1535}
1536
[email protected]b172aee2012-04-10 17:05:261537void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311538 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581539 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1540 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161541}
1542
[email protected]b172aee2012-04-10 17:05:261543void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311544 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581545 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1546 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161547}
1548
[email protected]b172aee2012-04-10 17:05:261549content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271550 return &renderer_preferences_;
1551}
1552
[email protected]b172aee2012-04-10 17:05:261553void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271554 new_tab_start_time_ = time;
1555}
1556
[email protected]b172aee2012-04-10 17:05:261557base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271558 return new_tab_start_time_;
1559}
1560
[email protected]e35ccd52012-05-23 16:22:471561void WebContentsImpl::Close() {
1562 Close(GetRenderViewHost());
1563}
1564
[email protected]b172aee2012-04-10 17:05:261565void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151566 if (close_start_time_.is_null())
1567 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011568}
1569
[email protected]b172aee2012-04-10 17:05:261570bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191571#if defined(OS_CHROMEOS)
1572 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1573 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511574 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201575 return false;
1576 return true;
[email protected]46624bf2010-06-09 16:04:191577#else
1578 return true;
1579#endif
1580}
1581
[email protected]b172aee2012-04-10 17:05:261582void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521583 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581584 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511585 if (delegate_)
1586 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341587}
1588
[email protected]e35ccd52012-05-23 16:22:471589void WebContentsImpl::UserGestureDone() {
1590 OnUserGesture();
1591}
1592
[email protected]b172aee2012-04-10 17:05:261593void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271594 closed_by_user_gesture_ = value;
1595}
1596
[email protected]b172aee2012-04-10 17:05:261597bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271598 return closed_by_user_gesture_;
1599}
1600
[email protected]b172aee2012-04-10 17:05:261601double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051602 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561603 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251604 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171605 return 0;
[email protected]b75b8292010-10-01 07:28:251606
1607 double zoom_level;
1608 if (temporary_zoom_settings_) {
1609 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581610 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251611 } else {
[email protected]2ae88d12011-10-14 09:11:191612 GURL url;
[email protected]10f417c52011-12-28 21:04:231613 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191614 // Since zoom map is updated using rewritten URL, use rewritten URL
1615 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511616 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191617 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251618 }
[email protected]d0b8d092010-10-25 04:05:171619 return zoom_level;
1620}
[email protected]b75b8292010-10-01 07:28:251621
[email protected]b172aee2012-04-10 17:05:261622int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1623 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171624 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011625 // Calculate the zoom percent from the factor. Round up to the nearest whole
1626 // number.
[email protected]b75b8292010-10-01 07:28:251627 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011628 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251629 *enable_decrement = percent > minimum_zoom_percent_;
1630 *enable_increment = percent < maximum_zoom_percent_;
1631 return percent;
1632}
1633
[email protected]b172aee2012-04-10 17:05:261634void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501635 if (!delegate_)
1636 return;
1637
[email protected]10f417c52011-12-28 21:04:231638 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501639 if (!active_entry)
1640 return;
1641
[email protected]36fc0392011-12-25 03:59:511642 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121643}
1644
[email protected]b172aee2012-04-10 17:05:261645void WebContentsImpl::ViewFrameSource(const GURL& url,
1646 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271647 if (!delegate_)
1648 return;
1649
1650 delegate_->ViewSourceForFrame(this, url, content_state);
1651}
1652
[email protected]b172aee2012-04-10 17:05:261653int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271654 return minimum_zoom_percent_;
1655}
1656
[email protected]b172aee2012-04-10 17:05:261657int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271658 return maximum_zoom_percent_;
1659}
1660
[email protected]b172aee2012-04-10 17:05:261661gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231662 return preferred_size_;
1663}
1664
[email protected]b172aee2012-04-10 17:05:261665int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271666 return content_restrictions_;
1667}
1668
[email protected]b172aee2012-04-10 17:05:261669WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501670 WebUIControllerFactory* factory =
1671 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1672 if (!factory)
1673 return WebUI::kNoWebUI;
1674 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271675}
1676
[email protected]b172aee2012-04-10 17:05:261677content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271678 // When there is a pending navigation entry, we want to use the pending WebUI
1679 // that goes along with it to control the basic flags. For example, we want to
1680 // show the pending URL in the URL bar, so we want the display_url flag to
1681 // be from the pending entry.
1682 //
1683 // The confusion comes because there are multiple possibilities for the
1684 // initial load in a tab as a side effect of the way the RenderViewHostManager
1685 // works.
1686 //
1687 // - For the very first tab the load looks "normal". The new tab Web UI is
1688 // the pending one, and we want it to apply here.
1689 //
1690 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1691 // get switched to the one previously associated with the new tab pages.
1692 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1693 // have a committed Web UI in this case.
1694 //
1695 // This condition handles all of these cases:
1696 //
1697 // - First load in first tab: no committed nav entry + pending nav entry +
1698 // pending dom ui:
1699 // -> Use pending Web UI if any.
1700 //
1701 // - First load in second tab: no committed nav entry + pending nav entry +
1702 // no pending Web UI:
1703 // -> Use the committed Web UI if any.
1704 //
1705 // - Second navigation in any tab: committed nav entry + pending nav entry:
1706 // -> Use pending Web UI if any.
1707 //
1708 // - Normal state with no load: committed nav entry + no pending nav entry:
1709 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251710 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271711 (controller_.GetLastCommittedEntry() ||
1712 render_manager_.pending_web_ui()))
1713 return render_manager_.pending_web_ui();
1714 return render_manager_.web_ui();
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271718 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581719 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271720}
1721
[email protected]b172aee2012-04-10 17:05:261722bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441723 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321727 SkColor color) {
[email protected]da8543762012-03-20 08:52:201728 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1729 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1730}
1731
[email protected]b172aee2012-04-10 17:05:261732void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201733 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1734 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1735 if (delegate_)
1736 delegate_->DidEndColorChooser();
1737 color_chooser_ = NULL;
1738}
1739
[email protected]b172aee2012-04-10 17:05:261740bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471741 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271742 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221743 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231744 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411745 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271746}
1747
[email protected]b172aee2012-04-10 17:05:261748void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271749 if (delegate_)
1750 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211751}
1752
[email protected]3a3b75a2012-06-01 08:38:361753void WebContentsImpl::OnRegisterIntentService(
1754 const webkit_glue::WebIntentServiceData& data,
1755 bool user_gesture) {
1756 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301757}
1758
[email protected]b172aee2012-04-10 17:05:261759void WebContentsImpl::OnWebIntentDispatch(
1760 const webkit_glue::WebIntentData& intent,
1761 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001762 WebIntentsDispatcherImpl* intents_dispatcher =
1763 new WebIntentsDispatcherImpl(this, intent, intent_id);
1764 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301765}
1766
[email protected]54047eb52012-05-08 21:45:571767void WebContentsImpl::DidStartProvisionalLoadForFrame(
1768 content::RenderViewHost* render_view_host,
1769 int64 frame_id,
1770 bool is_main_frame,
1771 const GURL& opener_url,
1772 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281773 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181774 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451775 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571776 content::RenderProcessHost* render_process_host =
1777 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541778 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571779 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451780 false,
[email protected]9f76c1e2012-03-05 15:15:581781 &validated_url);
[email protected]ef108e72012-06-20 14:03:541782 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571783 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451784 true,
1785 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181786
[email protected]0d60f0192011-04-14 12:40:101787 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251788 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101789 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571790 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541791
1792 if (is_main_frame) {
1793 // Notify observers about the provisional change in the main frame URL.
1794 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1795 ProvisionalChangeToMainFrameUrl(validated_url,
1796 validated_opener_url,
1797 render_view_host));
1798 }
1799}
1800
1801void WebContentsImpl::DidRedirectProvisionalLoad(
1802 content::RenderViewHost* render_view_host,
1803 int32 page_id,
1804 const GURL& opener_url,
1805 const GURL& source_url,
1806 const GURL& target_url) {
1807 // TODO(creis): Remove this method and have the pre-rendering code listen to
1808 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1809 // instead. See http://crbug.com/78512.
1810 GURL validated_source_url(source_url);
1811 GURL validated_target_url(target_url);
1812 GURL validated_opener_url(opener_url);
1813 content::RenderProcessHost* render_process_host =
1814 render_view_host->GetProcess();
1815 RenderViewHostImpl::FilterURL(
1816 ChildProcessSecurityPolicyImpl::GetInstance(),
1817 render_process_host->GetID(),
1818 false,
1819 &validated_source_url);
1820 RenderViewHostImpl::FilterURL(
1821 ChildProcessSecurityPolicyImpl::GetInstance(),
1822 render_process_host->GetID(),
1823 false,
1824 &validated_target_url);
1825 RenderViewHostImpl::FilterURL(
1826 ChildProcessSecurityPolicyImpl::GetInstance(),
1827 render_process_host->GetID(),
1828 true,
1829 &validated_opener_url);
1830 NavigationEntry* entry;
1831 if (page_id == -1) {
1832 entry = controller_.GetPendingEntry();
1833 } else {
1834 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1835 page_id);
1836 }
1837 if (!entry || entry->GetURL() != validated_source_url)
1838 return;
1839
1840 // Notify observers about the provisional change in the main frame URL.
1841 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1842 ProvisionalChangeToMainFrameUrl(validated_target_url,
1843 validated_opener_url,
1844 render_view_host));
[email protected]724159a2010-12-30 01:11:181845}
1846
[email protected]54047eb52012-05-08 21:45:571847void WebContentsImpl::DidFailProvisionalLoadWithError(
1848 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581849 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1850 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1851 << ", error_code: " << params.error_code
1852 << ", error_description: " << params.error_description
1853 << ", is_main_frame: " << params.is_main_frame
1854 << ", showing_repost_interstitial: " <<
1855 params.showing_repost_interstitial
1856 << ", frame_id: " << params.frame_id;
1857 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571858 content::RenderProcessHost* render_process_host =
1859 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541860 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571861 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451862 false,
[email protected]9f76c1e2012-03-05 15:15:581863 &validated_url);
[email protected]724159a2010-12-30 01:11:181864
[email protected]d7b175e2011-10-11 15:31:581865 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181866 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1867 // This means that the interstitial won't be torn down properly, which is
1868 // bad. But if we have an interstitial, go back to another tab type, and
1869 // then load the same interstitial again, we could end up getting the first
1870 // interstitial's "failed" message (as a result of the cancel) when we're on
1871 // the second one.
1872 //
1873 // We can't tell this apart, so we think we're tearing down the current page
1874 // which will cause a crash later one. There is also some code in
1875 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1876 // out because of this problem.
1877 //
1878 // http://code.google.com/p/chromium/issues/detail?id=2855
1879 // Because this will not tear down the interstitial properly, if "back" is
1880 // back to another tab type, the interstitial will still be somewhat alive
1881 // in the previous tab type. If you navigate somewhere that activates the
1882 // tab with the interstitial again, you'll see a flash before the new load
1883 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271884 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181885 LOG(WARNING) << "Discarding message during interstitial.";
1886 return;
1887 }
1888
[email protected]a16690732012-07-13 19:22:171889 // Do not clear the pending entry if one exists, so that the user's typed
1890 // URL is not lost when a navigation fails or is aborted. We'll allow
1891 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181892
[email protected]54047eb52012-05-08 21:45:571893 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181894 }
1895
[email protected]d8c660432011-12-22 20:51:251896 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581897 observers_,
1898 DidFailProvisionalLoad(params.frame_id,
1899 params.is_main_frame,
1900 validated_url,
1901 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461902 params.error_description,
1903 render_view_host));
[email protected]724159a2010-12-30 01:11:181904}
1905
[email protected]b172aee2012-04-10 17:05:261906void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181907 const GURL& url,
[email protected]70435962011-08-02 20:13:281908 const std::string& security_info,
1909 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181910 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281911 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191912 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181913 cache.Increment();
1914
1915 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081916 int cert_id = 0;
1917 net::CertStatus cert_status = 0;
1918 int security_bits = -1;
1919 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511920 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1921 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001922 content::LoadFromMemoryCacheDetails details(
1923 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1924 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181925
[email protected]ad50def52011-10-19 23:17:071926 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271927 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501928 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001929 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181930}
1931
[email protected]b172aee2012-04-10 17:05:261932void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381933 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181934 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201935 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181936}
1937
[email protected]b172aee2012-04-10 17:05:261938void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021939 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231940 LOG(INFO) << security_origin << " ran insecure content from "
1941 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381942 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411943 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1944 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181945 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411946 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201947 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181951 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251952 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101953 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181954}
1955
[email protected]b172aee2012-04-10 17:05:261956void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311957 int64 frame_id,
1958 const GURL& validated_url,
1959 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251960 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311961 DidFinishLoad(frame_id, validated_url, is_main_frame));
1962}
1963
[email protected]b172aee2012-04-10 17:05:261964void WebContentsImpl::OnDidFailLoadWithError(
1965 int64 frame_id,
1966 const GURL& validated_url,
1967 bool is_main_frame,
1968 int error_code,
1969 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251970 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311971 DidFailLoad(frame_id, validated_url, is_main_frame,
1972 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181973}
1974
[email protected]b172aee2012-04-10 17:05:261975void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271976 content_restrictions_ = restrictions;
1977 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171978}
1979
[email protected]b172aee2012-04-10 17:05:261980void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261981 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231982 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251983 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261984 if (!entry)
1985 return;
1986 // Note that we don't call NavigationController::GotToOffset() as we don't
1987 // want to create a pending navigation entry (it might end up lingering
1988 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251989 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581990 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511991 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581992 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471993 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571994
1995 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1996 // it in now that we know. This allows us to find the entry when it commits.
1997 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231998 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331999 entry->set_site_instance(
2000 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572001 }
[email protected]216813952011-05-19 22:21:262002 }
2003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2006 int maximum_percent,
2007 bool remember) {
[email protected]216813952011-05-19 22:21:262008 minimum_zoom_percent_ = minimum_percent;
2009 maximum_zoom_percent_ = maximum_percent;
2010 temporary_zoom_settings_ = !remember;
2011}
2012
[email protected]20b433a2012-05-15 21:23:462013void WebContentsImpl::OnSaveURL(const GURL& url,
2014 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482015 download_stats::RecordDownloadSource(
2016 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262017 // Check if the URL to save matches the URL of the main frame. Since this
2018 // message originates from Pepper plugins, it may not be the case if the
2019 // plugin is an embedded element.
2020 GURL main_frame_url = GetURL();
2021 if (!main_frame_url.is_valid())
2022 return;
2023 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462024 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::OnEnumerateDirectory(int request_id,
2028 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592029 ChildProcessSecurityPolicyImpl* policy =
2030 ChildProcessSecurityPolicyImpl::GetInstance();
2031 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2032 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212033}
2034
[email protected]b172aee2012-04-10 17:05:262035void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512036 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202037}
2038
[email protected]b172aee2012-04-10 17:05:262039void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2040 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362041 const string16& title,
2042 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592043 ChildProcessSecurityPolicyImpl* policy =
2044 ChildProcessSecurityPolicyImpl::GetInstance();
2045 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2046 return;
[email protected]3a3b75a2012-06-01 08:38:362047 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202048}
2049
[email protected]b172aee2012-04-10 17:05:262050void WebContentsImpl::OnFindReply(int request_id,
2051 int number_of_matches,
2052 const gfx::Rect& selection_rect,
2053 int active_match_ordinal,
2054 bool final_update) {
[email protected]6934a702011-12-20 00:04:512055 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2056 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002057 // Send a notification to the renderer that we are ready to receive more
2058 // results from the scoping effort of the Find operation. The FindInPage
2059 // scoping is asynchronous and periodically sends results back up to the
2060 // browser using IPC. In an effort to not spam the browser we have the
2061 // browser send an ACK for each FindReply message and have the renderer
2062 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582063 GetRenderViewHostImpl()->Send(
2064 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162065}
2066
[email protected]b172aee2012-04-10 17:05:262067void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442068 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2069 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452070}
2071
[email protected]b172aee2012-04-10 17:05:262072void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2073 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102074 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252075 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102076 AppCacheAccessed(manifest_url, blocked_by_policy));
2077}
2078
[email protected]b172aee2012-04-10 17:05:262079void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322080 SkColor color) {
[email protected]da8543762012-03-20 08:52:202081 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2082}
2083
[email protected]b172aee2012-04-10 17:05:262084void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202085 if (color_chooser_ &&
2086 color_chooser_id == color_chooser_->identifier())
2087 color_chooser_->End();
2088}
2089
[email protected]b172aee2012-04-10 17:05:262090void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322091 SkColor color) {
[email protected]da8543762012-03-20 08:52:202092 if (color_chooser_ &&
2093 color_chooser_id == color_chooser_->identifier())
2094 color_chooser_->SetSelectedColor(color);
2095}
2096
[email protected]9f2a9d72012-04-16 16:02:222097void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2098 const FilePath& path,
2099 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442100 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2101 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292102}
2103
[email protected]d0759f492012-04-19 22:50:502104// This exists for render views that don't have a WebUI, but do have WebUI
2105// bindings enabled.
2106void WebContentsImpl::OnWebUISend(const GURL& source_url,
2107 const std::string& name,
2108 const base::ListValue& args) {
2109 if (delegate_)
2110 delegate_->WebUISend(this, source_url, name, args);
2111}
2112
[email protected]96d185d2009-04-24 03:28:542113// Notifies the RenderWidgetHost instance about the fact that the page is
2114// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262115void WebContentsImpl::SetIsLoading(bool is_loading,
2116 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542117 if (is_loading == is_loading_)
2118 return;
2119
2120 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212121 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542122 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562123 upload_size_ = 0;
2124 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542125 }
2126
2127 render_manager_.SetIsLoading(is_loading);
2128
2129 is_loading_ = is_loading;
2130 waiting_for_response_ = is_loading;
2131
[email protected]6ebdc9b2010-09-27 16:55:572132 if (delegate_)
2133 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462134 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542135
[email protected]432115822011-07-10 15:52:272136 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2137 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072138 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542139 if (details)
[email protected]6c2381d2011-10-19 02:52:532140 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072141 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502142 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542143 det);
2144}
2145
[email protected]b172aee2012-04-10 17:05:262146void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132147 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322148 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562149 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382150 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442151 // that opened the window, as long as both renderers have the same
2152 // privileges.
[email protected]1fd1a502011-03-30 16:55:562153 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562154 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582155 // web_ui might be NULL if the URL refers to a non-existent extension.
2156 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402157 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522158 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442159 }
2160 }
[email protected]1fd1a502011-03-30 16:55:562161 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442162 }
2163
[email protected]4e697b042011-07-08 06:44:562164 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322165 // Clear the status bubble. This is a workaround for a bug where WebKit
2166 // doesn't let us know that the cursor left an element during a
2167 // transition (this is also why the mouse cursor remains as a hand after
2168 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2169 // clear the bubble when a user navigates to a named anchor in the same
2170 // page.
[email protected]36fc0392011-12-25 03:59:512171 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322172 }
2173
[email protected]a6e82fc2010-02-24 22:28:142174 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472175 // Once the main frame is navigated, we're no longer considered to have
2176 // displayed insecure content.
2177 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172178 }
[email protected]ce5c4502009-05-06 16:46:112179
[email protected]3c9e1872010-11-18 16:17:492180 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252181 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042182 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322183}
2184
[email protected]b172aee2012-04-10 17:05:262185void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322186 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132187 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322188 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062189 // If we navigate off the page, reset JavaScript state. This does nothing
2190 // to prevent a malicious script from spamming messages, since the script
2191 // could just reload the page to stop blocking.
2192 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552193 dialog_creator_->ResetJavaScriptState(this);
2194 dialog_creator_ = NULL;
2195 }
[email protected]420ae012009-04-24 05:16:322196
[email protected]3c9e1872010-11-18 16:17:492197 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252198 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042199 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322200}
2201
[email protected]b172aee2012-04-10 17:05:262202void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462203 // If we are creating a RVH for a restored controller, then we need to make
2204 // sure the RenderView starts with a next_page_id_ larger than the number
2205 // of restored entries. This must be called before the RenderView starts
2206 // navigating (to avoid a race between the browser updating max_page_id and
2207 // the renderer updating next_page_id_). Because of this, we only call this
2208 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562209 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582210 if (max_restored_page_id >
2211 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2212 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2213 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322214}
2215
[email protected]b172aee2012-04-10 17:05:262216bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2217 const string16& title) {
[email protected]420ae012009-04-24 05:16:322218 // For file URLs without a title, use the pathname instead. In the case of a
2219 // synthesized title, we don't want the update to count toward the "one set
2220 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512221 string16 final_title;
[email protected]420ae012009-04-24 05:16:322222 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512223 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2224 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322225 explicit_set = false; // Don't count synthetic titles toward the set limit.
2226 } else {
[email protected]acafd272011-07-26 17:35:572227 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322228 explicit_set = true;
2229 }
2230
[email protected]987fc3a2011-05-26 14:18:092231 // If a page is created via window.open and never navigated,
2232 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552233 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092234 if (entry) {
[email protected]36fc0392011-12-25 03:59:512235 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092236 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322237
[email protected]36fc0392011-12-25 03:59:512238 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092239 } else {
2240 if (page_title_when_no_navigation_entry_ == final_title)
2241 return false; // Nothing changed, don't bother.
2242
2243 page_title_when_no_navigation_entry_ = final_title;
2244 }
[email protected]420ae012009-04-24 05:16:322245
[email protected]420ae012009-04-24 05:16:322246 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232247 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322248
[email protected]2bb171882012-03-07 02:09:462249 std::pair<content::NavigationEntry*, bool> details =
2250 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142251
[email protected]ad50def52011-10-19 23:17:072252 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442253 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2254 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462255 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042256
[email protected]420ae012009-04-24 05:16:322257 return true;
2258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322261 // After sending out a swap notification, we need to send a disconnect
2262 // notification so that clients that pick up a pointer to |this| can NULL the
2263 // pointer. See Bug 1230284.
2264 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072265 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202266 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2267 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072268 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322269}
2270
[email protected]b172aee2012-04-10 17:05:262271void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322272 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072273 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122274 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2275 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072276 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322280 if (!notify_disconnection_)
2281 return;
2282
2283 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072284 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322285 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2286 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072287 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322288}
2289
[email protected]5a3bdf52012-05-24 15:12:572290RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2291 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322292}
2293
[email protected]8d3347f2009-07-09 22:00:212294RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262295WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212296 return &render_manager_;
2297}
2298
[email protected]b172aee2012-04-10 17:05:262299content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372300 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462301 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512302}
2303
[email protected]b172aee2012-04-10 17:05:262304WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172305 return this;
2306}
2307
[email protected]b172aee2012-04-10 17:05:262308gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172309 if (delegate_)
2310 return delegate_->GetRootWindowResizerRect();
2311 return gfx::Rect();
2312}
2313
[email protected]b172aee2012-04-10 17:05:262314void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442315 // Don't send notifications if we are just creating a swapped-out RVH for
2316 // the opener chain. These won't be used for view-source or WebUI, so it's
2317 // ok to return early.
2318 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2319 return;
2320
[email protected]ad50def52011-10-19 23:17:072321 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272322 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322323 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532324 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232325 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322326 if (!entry)
2327 return;
2328
2329 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352330 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562331 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582332 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322333
2334 if (entry->IsViewSourceMode()) {
2335 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582336 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2337 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322338 }
[email protected]0666aef2009-05-13 19:48:082339
[email protected]d487beefe2011-12-21 05:41:212340 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262341
2342 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252343 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522347 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322348 // Don't notify the world, since this came from a renderer in the
2349 // background.
2350 return;
2351 }
2352
2353 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312354 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232355 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302356
2357 // Restore the focus to the tab (otherwise the focus will be on the top
2358 // window).
[email protected]484ae5912010-09-29 19:16:142359 if (was_crashed && !FocusLocationBarByDefault() &&
2360 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302361 Focus();
[email protected]484ae5912010-09-29 19:16:142362 }
[email protected]32ded2212011-11-10 18:51:432363
[email protected]d8c660432011-12-22 20:51:252364 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322365}
2366
[email protected]b172aee2012-04-10 17:05:262367void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2368 base::TerminationStatus status,
2369 int error_code) {
[email protected]151a63d2011-12-20 22:32:522370 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322371 // The pending page's RenderViewHost is gone.
2372 return;
2373 }
2374
2375 SetIsLoading(false, NULL);
2376 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232377 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312378 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322379
[email protected]d8c660432011-12-22 20:51:252380 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272381 observers_,
[email protected]be1f56ab2011-12-22 06:55:312382 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322383}
2384
[email protected]b172aee2012-04-10 17:05:262385void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482386 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252387 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::DidNavigate(
2391 RenderViewHost* rvh,
2392 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582393 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322394 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372395
[email protected]434f69f2012-02-06 21:56:522396 // Update the site of the SiteInstance if it doesn't have one yet, unless
2397 // this is for about:blank. In that case, the SiteInstance can still be
2398 // considered unused until a navigation to a real page.
2399 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2400 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332401 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522402 }
[email protected]420ae012009-04-24 05:16:322403
2404 // Need to update MIME type here because it's referred to in
2405 // UpdateNavigationCommands() called by RendererDidNavigate() to
2406 // determine whether or not to enable the encoding menu.
2407 // It's updated only for the main frame. For a subframe,
2408 // RenderView::UpdateURL does not set params.contents_mime_type.
2409 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2410 // TODO(jungshik): Add a test for the encoding menu to avoid
2411 // regressing it again.
[email protected]2905f742011-10-13 03:51:582412 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322413 contents_mime_type_ = params.contents_mime_type;
2414
[email protected]8286f51a2011-05-31 17:39:132415 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002416 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392417
[email protected]a9c0bfe2010-09-17 08:35:222418 // Send notification about committed provisional loads. This notification is
2419 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2420 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082421 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072422 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2423 // that is not recorded in the navigation history. For the purpose of
2424 // tracking navigation events, we treat this event as a sub frame navigation
2425 // event.
2426 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582427 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222428 // Whether or not a page transition was triggered by going backward or
2429 // forward in the history is only stored in the navigation controller's
2430 // entry list.
2431 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512432 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582433 content::PAGE_TRANSITION_FORWARD_BACK)) {
2434 transition_type = content::PageTransitionFromInt(
2435 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222436 }
[email protected]0d60f0192011-04-14 12:40:102437 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252438 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102439 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462440 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222441 }
2442
[email protected]76543b92009-08-31 17:27:452443 if (!did_navigate)
2444 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322445
2446 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2447 // for the appropriate notification (best) or you can add it to
2448 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2449 // necessary, please).
2450
2451 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002452 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322453 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512454 if (delegate_)
2455 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002456 }
[email protected]420ae012009-04-24 05:16:322457 DidNavigateAnyFramePostCommit(rvh, details, params);
2458}
2459
[email protected]b172aee2012-04-10 17:05:262460void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2461 int32 page_id,
2462 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152463 // Ensure that this state update comes from either the active RVH or one of
2464 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522465 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322466
2467 // We must be prepared to handle state updates for any page, these occur
2468 // when the user is scrolling and entering form data, as well as when we're
2469 // leaving a page, in which case our state may have already been moved to
2470 // the next page. The navigation controller will look up the appropriate
2471 // NavigationEntry and update it when it is notified via the delegate.
2472
2473 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582474 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322475 if (entry_index < 0)
2476 return;
[email protected]10f417c52011-12-28 21:04:232477 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322478
[email protected]36fc0392011-12-25 03:59:512479 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322480 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512481 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322482 controller_.NotifyEntryChanged(entry, entry_index);
2483}
2484
[email protected]b172aee2012-04-10 17:05:262485void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2486 int32 page_id,
2487 const string16& title,
2488 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322489 // If we have a title, that's a pretty good indication that we've started
2490 // getting useful data.
2491 SetNotWaitingForResponse();
2492
[email protected]73eb2602012-02-09 19:50:552493 // Try to find the navigation entry, which might not be the current one.
2494 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232495 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582496 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092497
[email protected]73eb2602012-02-09 19:50:552498 // We can handle title updates when we don't have an entry in
2499 // UpdateTitleForEntry, but only if the update is from the current RVH.
2500 if (!entry && rvh != GetRenderViewHost())
2501 return;
2502
[email protected]a49e10b2011-08-01 23:57:462503 // TODO(evan): make use of title_direction.
2504 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092505 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322506 return;
2507
2508 // Broadcast notifications when the UI should be updated.
2509 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462510 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322511}
2512
[email protected]b172aee2012-04-10 17:05:262513void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2514 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312515 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512519 if (delegate_)
2520 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322521}
2522
[email protected]b172aee2012-04-10 17:05:262523void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292524 // The UI may be in an event-tracking loop, such as between the
2525 // mouse-down and mouse-up in text selection or a button click.
2526 // Defer the close until after tracking is complete, so that we
2527 // don't free objects out from under the UI.
2528 // TODO(shess): This could probably be integrated with the
2529 // IsDoingDrag() test below. Punting for now because I need more
2530 // research to understand how this impacts platforms other than Mac.
2531 // TODO(shess): This could get more fine-grained. For instance,
2532 // closing a tab in another window while selecting text in the
2533 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212534 if (GetView()->IsEventTracking()) {
2535 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292536 return;
2537 }
2538
[email protected]24a4d1062009-07-10 23:10:422539 // If we close the tab while we're in the middle of a drag, we'll crash.
2540 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212541 if (GetView()->IsDoingDrag()) {
2542 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422543 return;
2544 }
2545
[email protected]420ae012009-04-24 05:16:322546 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522547 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512548 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322549}
2550
[email protected]b172aee2012-04-10 17:05:262551void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522552 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512553 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572554}
2555
[email protected]b172aee2012-04-10 17:05:262556void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512557 if (delegate_ && delegate_->IsPopupOrPanel(this))
2558 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322559}
2560
[email protected]b172aee2012-04-10 17:05:262561void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322562 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492563
[email protected]82114f52012-03-20 22:53:412564 if (delegate_ && content_restrictions_)
2565 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492566
2567 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252568 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322572 scoped_ptr<LoadNotificationDetails> details;
2573
[email protected]10f417c52011-12-28 21:04:232574 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322575 // An entry may not exist for a stop when loading an initial blank page or
2576 // if an iframe injected by script into a blank page finishes loading.
2577 if (entry) {
[email protected]420ae012009-04-24 05:16:322578 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2579
2580 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512581 entry->GetVirtualURL(),
2582 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322583 elapsed,
2584 &controller_,
2585 controller_.GetCurrentEntryIndex()));
2586 }
2587
[email protected]420ae012009-04-24 05:16:322588 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492589
2590 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252591 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322592}
2593
[email protected]b172aee2012-04-10 17:05:262594void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162595 controller_.DiscardNonCommittedEntries();
2596
2597 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462598 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162599}
2600
[email protected]b172aee2012-04-10 17:05:262601void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512602 if (delegate_)
2603 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402604}
2605
[email protected]87717d0e2012-04-26 02:58:432606void WebContentsImpl::DocumentAvailableInMainFrame(
2607 RenderViewHost* render_view_host) {
2608 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2609 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102610}
2611
[email protected]b172aee2012-04-10 17:05:262612void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082613 RenderViewHost* render_view_host,
2614 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072615 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272616 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322617 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532618 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082619}
2620
[email protected]196159d2012-05-04 17:26:542621void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2622 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262623 const content::Referrer& referrer,
2624 WindowOpenDisposition disposition,
2625 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542626 // If this came from a swapped out RenderViewHost, we only allow the request
2627 // if we are still in the same BrowsingInstance.
2628 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2629 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2630 return;
2631 }
2632
[email protected]4ad5d77d2011-12-03 02:00:482633 // Delegate to RequestTransferURL because this is just the generic
2634 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582635 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482636 GlobalRequestID());
2637}
2638
[email protected]b172aee2012-04-10 17:05:262639void WebContentsImpl::RequestTransferURL(
2640 const GURL& url,
2641 const content::Referrer& referrer,
2642 WindowOpenDisposition disposition,
2643 int64 source_frame_id,
2644 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202645 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582646 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582647 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352648 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322649 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2650 // generated suggestions).
2651 //
[email protected]e0112912011-02-02 22:54:352652 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162653 // want web sites to see a referrer of "chrome://blah" (and some
2654 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322655 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432656 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222657 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482658 false /* is_renderer_initiated */);
2659 params.transferred_global_request_id = old_request_id;
2660 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222661 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322662 } else {
[email protected]6bf6a6b52012-02-03 15:41:432663 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482664 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2665 params.transferred_global_request_id = old_request_id;
2666 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582667 }
2668 if (new_contents) {
2669 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252670 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582671 DidOpenRequestedURL(new_contents,
2672 url,
2673 referrer,
2674 disposition,
2675 transition_type,
2676 source_frame_id));
[email protected]420ae012009-04-24 05:16:322677 }
2678}
2679
[email protected]e1c3a552012-05-04 20:51:322680void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2681 // Tell the active RenderViewHost to run unload handlers and close, as long
2682 // as the request came from a RenderViewHost in the same BrowsingInstance.
2683 // In most cases, we receive this from a swapped out RenderViewHost.
2684 // It is possible to receive it from one that has just been swapped in,
2685 // in which case we might as well deliver the message anyway.
2686 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2687 GetRenderViewHost()->ClosePage();
2688}
2689
[email protected]f546640b2012-05-15 00:03:492690void WebContentsImpl::RouteMessageEvent(
2691 RenderViewHost* rvh,
2692 const ViewMsg_PostMessage_Params& params) {
2693 // Only deliver the message to the active RenderViewHost if the request
2694 // came from a RenderViewHost in the same BrowsingInstance.
2695 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2696 return;
2697
2698 ViewMsg_PostMessage_Params new_params(params);
2699
2700 // If there is a source_routing_id, translate it to the routing ID for
2701 // the equivalent swapped out RVH in the target process. If we need
2702 // to create a swapped out RVH for the source tab, we create its opener
2703 // chain as well, since those will also be accessible to the target page.
2704 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2705 // Try to look up the WebContents for the source page.
2706 WebContentsImpl* source_contents = NULL;
2707 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2708 rvh->GetProcess()->GetID(), params.source_routing_id);
2709 if (source_rvh) {
2710 source_contents = static_cast<WebContentsImpl*>(
2711 source_rvh->GetDelegate()->GetAsWebContents());
2712 }
2713
2714 if (source_contents) {
2715 new_params.source_routing_id =
2716 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2717 } else {
2718 // We couldn't find it, so don't pass a source frame.
2719 new_params.source_routing_id = MSG_ROUTING_NONE;
2720 }
2721 }
2722
2723 // In most cases, we receive this from a swapped out RenderViewHost.
2724 // It is possible to receive it from one that has just been swapped in,
2725 // in which case we might as well deliver the message anyway.
2726 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2727 GetRenderViewHost()->GetRoutingID(), new_params));
2728}
2729
[email protected]b172aee2012-04-10 17:05:262730void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342731 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412732 const string16& message,
2733 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322734 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142735 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322736 IPC::Message* reply_msg,
2737 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072738 // Suppress JavaScript dialogs when requested. Also suppress messages when
2739 // showing an interstitial as it's shown over the previous page and we don't
2740 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502741 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582742 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272743 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072744 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522745 delegate_->ShouldSuppressDialogs() ||
2746 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322747
2748 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432749 std::string accept_lang = content::GetContentClient()->browser()->
2750 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552751 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522752 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432753 this,
2754 frame_url.GetOrigin(),
2755 accept_lang,
2756 javascript_message_type,
2757 message,
[email protected]51da7e32012-01-30 19:24:522758 default_prompt,
[email protected]b172aee2012-04-10 17:05:262759 base::Bind(&WebContentsImpl::OnDialogClosed,
2760 base::Unretained(this),
2761 rvh,
2762 reply_msg),
[email protected]51da7e32012-01-30 19:24:522763 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322764 }
[email protected]3ab9cb82011-06-03 18:02:072765
2766 if (suppress_this_message) {
2767 // If we are suppressing messages, just reply as if the user immediately
2768 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342769 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072770 }
2771
2772 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322773}
2774
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2776 const string16& message,
2777 bool is_reload,
2778 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582779 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512780 if (delegate_)
2781 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072782
2783 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582784 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072785 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522786 delegate_->ShouldSuppressDialogs() ||
2787 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152788 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342789 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582790 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502791 return;
2792 }
[email protected]3ab9cb82011-06-03 18:02:072793
[email protected]7ab1e7d62009-10-14 23:32:012794 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552795 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522796 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322797 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262798 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522799 reply_msg));
[email protected]420ae012009-04-24 05:16:322800}
2801
[email protected]a796f202012-05-30 14:14:252802bool WebContentsImpl::AddMessageToConsole(int32 level,
2803 const string16& message,
2804 int32 line_no,
2805 const string16& source_id) {
2806 if (!delegate_)
2807 return false;
2808 return delegate_->AddMessageToConsole(this, level, message, line_no,
2809 source_id);
2810}
2811
[email protected]b172aee2012-04-10 17:05:262812WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332813 // We want to base the page config off of the real URL, rather than the
2814 // display URL.
2815 GURL url = controller_.GetActiveEntry()
2816 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2817 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322818}
2819
[email protected]b172aee2012-04-10 17:05:262820void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272821 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252822 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222823
[email protected]ea114722012-03-12 01:11:252824 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172825 if (rdh) // NULL in unittests.
2826 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252827}
2828
[email protected]b172aee2012-04-10 17:05:262829void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442830 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252831 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442832}
2833
[email protected]b172aee2012-04-10 17:05:262834void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2835 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152836 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522837 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152838 return;
2839
[email protected]9f76c1e2012-03-05 15:15:582840 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2841
[email protected]e5fc1632011-08-08 07:51:532842 // Ignore renderer unresponsive event if debugger is attached to the tab
2843 // since the event may be a result of the renderer sitting on a breakpoint.
2844 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442845 DevToolsAgentHost* agent =
2846 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2847 if (agent &&
2848 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532849 return;
2850
[email protected]420ae012009-04-24 05:16:322851 if (is_during_unload) {
2852 // Hang occurred while firing the beforeunload/unload handler.
2853 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582854 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322855
2856 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2857 return;
2858
2859 // If the tab hangs in the beforeunload/unload handler there's really
2860 // nothing we can do to recover. Pretend the unload listeners have
2861 // all fired and close the tab. If the hang is in the beforeunload handler
2862 // then the user will not have the option of cancelling the close.
2863 Close(rvh);
2864 return;
2865 }
2866
[email protected]9f76c1e2012-03-05 15:15:582867 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472868 return;
2869
[email protected]6934a702011-12-20 00:04:512870 if (delegate_)
2871 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322872}
2873
[email protected]b172aee2012-04-10 17:05:262874void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512875 if (delegate_)
2876 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322877}
2878
[email protected]b172aee2012-04-10 17:05:262879void WebContentsImpl::LoadStateChanged(
2880 const GURL& url,
2881 const net::LoadStateWithParam& load_state,
2882 uint64 upload_position,
2883 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322884 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562885 upload_position_ = upload_position;
2886 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502887 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202888 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302889 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212890 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322891 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462892 if (IsLoading()) {
2893 NotifyNavigationStateChanged(
2894 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2895 }
[email protected]420ae012009-04-24 05:16:322896}
2897
[email protected]b172aee2012-04-10 17:05:262898void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512899 if (delegate_)
2900 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252901}
2902
[email protected]b172aee2012-04-10 17:05:262903void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322904 bool proceed,
2905 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512906 if (delegate_)
2907 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322908}
2909
[email protected]b172aee2012-04-10 17:05:262910void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542911 RenderViewHost* render_view_host) {
2912 DidStartLoading();
2913}
2914
[email protected]b172aee2012-04-10 17:05:262915void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542916 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232917 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2918 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542919}
2920
[email protected]b172aee2012-04-10 17:05:262921void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102922 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262923 gfx::Size size = view_->GetContainerSize();
2924 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2925 // here during container initialization and normal window size will be set
2926 // later. In case of tab duplication this resizing to 0x0 prevents setting
2927 // normal size later so just ignore it.
2928 if (!size.IsEmpty())
2929 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322930}
2931
[email protected]b172aee2012-04-10 17:05:262932void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542933 NotifySwapped();
2934}
2935
[email protected]14392a52012-05-02 20:28:442936int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2937 SiteInstance* instance) {
2938 if (!opener_)
2939 return MSG_ROUTING_NONE;
2940
2941 // Recursively create RenderViews for anything else in the opener chain.
2942 return opener_->CreateOpenerRenderViews(instance);
2943}
2944
2945int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2946 int opener_route_id = MSG_ROUTING_NONE;
2947
2948 // If this tab has an opener, ensure it has a RenderView in the given
2949 // SiteInstance as well.
2950 if (opener_)
2951 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2952
2953 // Create a swapped out RenderView in the given SiteInstance if none exists,
2954 // setting its opener to the given route_id. Return the new view's route_id.
2955 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2956}
2957
[email protected]b172aee2012-04-10 17:05:262958NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202959 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542960}
2961
[email protected]b172aee2012-04-10 17:05:262962WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562963 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322964}
2965
[email protected]10f417c52011-12-28 21:04:232966NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262967 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322968 return controller_.GetLastCommittedEntry();
2969}
2970
[email protected]b172aee2012-04-10 17:05:262971bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442972 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442973 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322974 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522975
[email protected]420ae012009-04-24 05:16:322976 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442977 if (rwh_view)
2978 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322979
[email protected]74ce1ad2011-12-16 21:51:462980 // Make sure we use the correct starting page_id in the new RenderView.
2981 UpdateMaxPageIDIfNecessary(render_view_host);
2982 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582983 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462984
[email protected]7900bfdb2012-05-24 19:31:242985 std::string embedder_channel_name;
2986 int embedder_container_id;
2987 GetBrowserPluginEmbedderInfo(render_view_host,
2988 &embedder_channel_name,
2989 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:582990 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492991 render_view_host)->CreateRenderView(string16(),
2992 opener_route_id,
2993 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:242994 embedder_channel_name,
2995 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:522996 return false;
[email protected]14392a52012-05-02 20:28:442997 }
[email protected]a4127722011-04-27 23:13:522998
[email protected]e60c0232011-11-11 19:56:352999#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503000 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3001 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443002 if (rwh_view) {
3003 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3004 render_widget_host->WasResized();
3005 }
[email protected]f8233cc2011-05-31 20:24:503006#endif
3007
[email protected]420ae012009-04-24 05:16:323008 return true;
3009}
3010
[email protected]b172aee2012-04-10 17:05:263011void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3012 IPC::Message* reply_msg,
3013 bool success,
3014 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543015 if (is_showing_before_unload_dialog_ && !success) {
3016 // If a beforeunload dialog is canceled, we need to stop the throbber from
3017 // spinning, since we forced it to start spinning in Navigate.
3018 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:353019 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543020
[email protected]3bbacc5b2012-04-17 17:46:153021 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543022 }
3023 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583024 static_cast<RenderViewHostImpl*>(
3025 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543026}
3027
[email protected]b172aee2012-04-10 17:05:263028void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123029 encoding_ = content::GetContentClient()->browser()->
3030 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103031}
[email protected]f45d2a72010-03-08 23:28:353032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463034 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263035 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573036 DownloadManager* dlm =
3037 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143038 if (!dlm)
3039 return;
3040 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263041 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143042 const NavigationEntry* entry = controller_.GetActiveEntry();
3043 if (entry)
3044 post_id = entry->GetPostID();
3045 }
[email protected]29a5ffc82012-03-13 19:35:583046 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143047 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143048 scoped_ptr<DownloadUrlParameters> params(
3049 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493050 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143051 params->set_post_id(post_id);
3052 params->set_prefer_cache(true);
3053 if (post_id >= 0)
3054 params->set_method("POST");
3055 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143056}
3057
[email protected]b172aee2012-04-10 17:05:263058void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213059 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443060 // Can be NULL during tests.
3061 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213062 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363063}
[email protected]9f76c1e2012-03-05 15:15:583064
[email protected]b172aee2012-04-10 17:05:263065RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583066 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3067}
[email protected]7900bfdb2012-05-24 19:31:243068
3069void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3070 content::RenderViewHost* render_view_host,
3071 std::string* embedder_channel_name,
3072 int* embedder_container_id) {
3073 content::RenderProcessHost* embedder_render_process_host =
3074 browser_plugin_host()->embedder_render_process_host();
3075 *embedder_container_id = browser_plugin_host()->instance_id();
3076 int embedder_process_id =
3077 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3078 if (embedder_process_id != -1) {
3079 *embedder_channel_name =
3080 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3081 embedder_process_id);
3082 }
3083}