blob: edb3fb0daf84f02c8dfc54af27aac19cd24b7793 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]14cf0f12012-06-18 17:15:5718#include "content/browser/browser_plugin/old/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5919#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4420#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0421#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4622#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1223#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1624#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3225#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5426#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0527#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0028#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5031#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2532#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5740#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2043#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1746#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1447#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4648#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1549#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0050#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2751#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0052#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3753#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1454#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3255#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3856#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4257#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2558#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1059#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5060#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2161#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4862#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1863#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5464#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0365#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1666#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2967#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5468#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3469#include "net/url_request/url_request_context_getter.h"
[email protected]302fe422012-06-11 14:49:1170#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
[email protected]8bd0fe62011-01-17 06:44:3771#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5672#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4173#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0174#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4175#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2476#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3677#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3178#include "webkit/glue/webpreferences.h"
79
[email protected]f66df822012-05-18 16:52:1780#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5081#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5783#endif
[email protected]3e45ba92009-02-20 21:09:0084
[email protected]420ae012009-04-24 05:16:3285// Cross-Site Navigations
86//
[email protected]b172aee2012-04-10 17:05:2687// If a WebContentsImpl is told to navigate to a different web site (as
88// determined by SiteInstance), it will replace its current RenderViewHost with
89// a new RenderViewHost dedicated to the new SiteInstance. This works as
90// follows:
[email protected]420ae012009-04-24 05:16:3291//
92// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4693// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3294// - The pending RVH is "suspended," so that no navigation messages are sent to
95// its renderer until the onbeforeunload JavaScript handler has a chance to
96// run in the current RVH.
97// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
98// that it has a pending cross-site request. ResourceDispatcherHost will
99// check for this when the response arrives.
100// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46101// cancel all the pending logic. Otherwise we allow the pending RVH to send
102// the navigation request to its renderer.
103// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
104// main resource load on the pending RVH. It checks CrossSiteRequestManager
105// to see that it is a cross-site request, and installs a
106// CrossSiteResourceHandler.
107// - When RDH receives a response, the BufferedResourceHandler determines
108// whether it is a download. If so, it sends a message to the new renderer
109// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26110// pending RVH remains until the next DidNavigate event for this
111// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32112// - After RDH receives a response and determines that it is safe and not a
113// download, it pauses the response to first run the old page's onunload
114// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26115// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32116// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15117// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32118// the ResourceDispatcherHost, who unpauses the response. Data is then sent
119// to the pending RVH.
120// - The pending renderer sends a FrameNavigate message that invokes the
121// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46122// pending RVH.
[email protected]992db4c2011-05-12 15:37:15123// - The previous renderer is kept swapped out in RenderViewHostManager in case
124// the user goes back. The process only stays live if another tab is using
125// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32126
[email protected]b441a8492012-06-06 14:55:57127using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44128using content::DevToolsAgentHost;
129using content::DevToolsAgentHostRegistry;
130using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17131using content::DownloadItem;
132using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14133using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20134using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56135using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13136using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27137using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54138using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50139using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23140using content::NavigationEntry;
141using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20142using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11143using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57144using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57145using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27146using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11147using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50148using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58149using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04150using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25151using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14152using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43153using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33154using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38155using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09156using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25157using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56158using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22159using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50160using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25161using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44162
[email protected]420ae012009-04-24 05:16:32163namespace {
164
165// Amount of time we wait between when a key event is received and the renderer
166// is queried for its state and pushed to the NavigationEntry.
167const int kQueryStateDelay = 5000;
168
[email protected]6ebdc9b2010-09-27 16:55:57169const int kSyncWaitDelay = 40;
170
[email protected]82114f52012-03-20 22:53:41171const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05172
[email protected]420ae012009-04-24 05:16:32173#if defined(OS_WIN)
174
175BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
176 // Note: erase is required to properly paint some widgets borders. This can
177 // be seen with textfields.
178 InvalidateRect(hwnd, NULL, TRUE);
179 return TRUE;
180}
181#endif
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23184 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16186 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47189 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47191 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16192 break; // Fall through to rest of function.
193 }
[email protected]5e369672009-11-03 23:48:30194
[email protected]59246c572012-02-10 13:32:13195 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
196 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23197 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13198 browser_context->DidLastSessionExitCleanly()) {
199 if (entry.GetHasPostData())
200 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13202 }
[email protected]5e369672009-11-03 23:48:30203
[email protected]2c5569662011-03-22 20:45:02204 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30205}
206
[email protected]10f417c52011-12-28 21:04:23207void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47208 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42209 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50210 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24211 const std::string& embedder_channel_name,
212 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16213 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51214 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54215 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55216 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
217 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51218 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36219 if (!entry.GetBaseURLForDataURL().is_empty()) {
220 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
221 params->history_url_for_data_url = entry.GetVirtualURL();
222 }
[email protected]36fc0392011-12-25 03:59:51223 params->referrer = entry.GetReferrer();
224 params->transition = entry.GetTransitionType();
225 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00226 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55227 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34228 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47229 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48230 params->transferred_request_child_id =
231 entry.transferred_global_request_id().child_id;
232 params->transferred_request_request_id =
233 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22234 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00235 // Avoid downloading when in view-source mode.
236 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24237 params->embedder_channel_name = embedder_channel_name;
238 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47239
240 if (delegate)
241 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34242}
243
[email protected]f98f5092012-05-19 00:08:14244int GetSwitchValueAsInt(
245 const CommandLine& command_line,
246 const std::string& switch_string,
247 int min_value) {
248 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
249 int int_value;
250 if (base::StringToInt(string_value, &int_value))
251 return std::max(min_value, int_value);
252 else
253 return min_value;
254}
255
[email protected]420ae012009-04-24 05:16:32256} // namespace
257
[email protected]a81343d232011-12-27 07:39:20258namespace content {
259
260WebContents* WebContents::Create(
261 BrowserContext* browser_context,
262 SiteInstance* site_instance,
263 int routing_id,
[email protected]b172aee2012-04-10 17:05:26264 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20265 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26266 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43267 browser_context,
268 site_instance,
269 routing_id,
[email protected]b172aee2012-04-10 17:05:26270 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44271 NULL,
[email protected]adbfb8df2012-02-24 01:19:43272 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20273}
[email protected]746d3052012-05-22 15:15:47274
[email protected]299d7f12012-05-23 05:31:15275WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47276 return rvh->GetDelegate()->GetAsWebContents();
277}
278
[email protected]a81343d232011-12-27 07:39:20279}
[email protected]f4f50ef2011-01-21 19:01:19280
[email protected]b172aee2012-04-10 17:05:26281// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32282
[email protected]b172aee2012-04-10 17:05:26283WebContentsImpl::WebContentsImpl(
284 content::BrowserContext* browser_context,
285 SiteInstance* site_instance,
286 int routing_id,
287 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44288 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26289 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42290 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07291 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37292 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57293 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44294 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05295 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34296 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23297 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
298 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34299 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21300 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56301 upload_size_(0),
302 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47303 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57304 capturing_contents_(false),
305 is_being_destroyed_(false),
306 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55307 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57308#if defined(OS_WIN)
309 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
310#endif
[email protected]7ab1e7d62009-10-14 23:32:01311 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56312 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38313 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25314 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01315 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25316 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01317 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00318 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43319 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20320 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37321 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32322
[email protected]38b098f2012-03-14 21:11:57323 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57324 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
325 if (view_.get()) {
326 CHECK(render_view_host_delegate_view_);
327 } else {
[email protected]38b098f2012-03-14 21:11:57328 content::WebContentsViewDelegate* delegate =
329 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
330 this);
[email protected]5a3bdf52012-05-24 15:12:57331 view_.reset(CreateWebContentsView(
332 this, delegate, &render_view_host_delegate_view_));
333 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57334 }
335 CHECK(view_.get());
336
[email protected]ca13a442012-04-17 14:00:12337 // We have the initial size of the view be based on the size of the view of
338 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26339 view_->CreateView(base_web_contents ?
340 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00341
[email protected]14392a52012-05-02 20:28:44342 // Listen for whether our opener gets destroyed.
343 if (opener_) {
344 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
345 content::Source<WebContents>(opener_));
346 }
347
[email protected]bafe6cd2012-05-23 23:09:50348 registrar_.Add(this,
349 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
350 content::NotificationService::AllBrowserContextsAndSources());
351
[email protected]483623eb2011-10-25 09:30:00352#if defined(ENABLE_JAVA_BRIDGE)
353 java_bridge_dispatcher_host_manager_.reset(
354 new JavaBridgeDispatcherHostManager(this));
355#endif
[email protected]172cf712012-05-23 15:07:39356
357 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35358}
initial.commit09911bf2008-07-26 23:55:29359
[email protected]b172aee2012-04-10 17:05:26360WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32361 is_being_destroyed_ = true;
362
[email protected]3ab9cb82011-06-03 18:02:07363 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55364 if (dialog_creator_)
365 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07366
[email protected]da8543762012-03-20 08:52:20367 if (color_chooser_)
368 color_chooser_->End();
369
[email protected]420ae012009-04-24 05:16:32370 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32371
[email protected]ca13a442012-04-17 14:00:12372 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07373 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09374 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
375 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32377
378 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07379#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32380 // If we still have a window handle, destroy it. GetNativeView can return
381 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42382 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52383 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58384 if (host && host->GetView())
385 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42386 }
[email protected]420ae012009-04-24 05:16:32387#endif
[email protected]7ab1e7d62009-10-14 23:32:01388
389 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15390 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01391 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15392 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01393 }
[email protected]b5a1d11c2011-02-17 03:09:42394
[email protected]2db9bd72012-04-13 20:20:56395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
397 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08398
[email protected]6934a702011-12-20 00:04:51399 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42400}
401
[email protected]b172aee2012-04-10 17:05:26402WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
403 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54404 WebPreferences prefs;
405
406 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
407
408 prefs.developer_extras_enabled = true;
409 prefs.javascript_enabled =
410 !command_line.HasSwitch(switches::kDisableJavaScript);
411 prefs.web_security_enabled =
412 !command_line.HasSwitch(switches::kDisableWebSecurity);
413 prefs.plugins_enabled =
414 !command_line.HasSwitch(switches::kDisablePlugins);
415 prefs.java_enabled =
416 !command_line.HasSwitch(switches::kDisableJava);
417
418 prefs.uses_page_cache =
419 command_line.HasSwitch(switches::kEnableFastback);
420 prefs.remote_fonts_enabled =
421 !command_line.HasSwitch(switches::kDisableRemoteFonts);
422 prefs.xss_auditor_enabled =
423 !command_line.HasSwitch(switches::kDisableXSSAuditor);
424 prefs.application_cache_enabled =
425 !command_line.HasSwitch(switches::kDisableApplicationCache);
426
427 prefs.local_storage_enabled =
428 !command_line.HasSwitch(switches::kDisableLocalStorage);
429 prefs.databases_enabled =
430 !command_line.HasSwitch(switches::kDisableDatabases);
431 prefs.webaudio_enabled =
432 !command_line.HasSwitch(switches::kDisableWebAudio);
433
434 prefs.experimental_webgl_enabled =
435 GpuProcessHost::gpu_enabled() &&
436 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07437#if defined(OS_ANDROID)
438 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
439#else
[email protected]64d69de42012-02-06 00:19:54440 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07441#endif
[email protected]64d69de42012-02-06 00:19:54442
[email protected]5a073092012-06-08 00:42:51443 prefs.flash_3d_enabled =
444 GpuProcessHost::gpu_enabled() &&
445 !command_line.HasSwitch(switches::kDisableFlash3d);
446 prefs.flash_stage3d_enabled =
447 GpuProcessHost::gpu_enabled() &&
448 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19449
[email protected]64d69de42012-02-06 00:19:54450 prefs.gl_multisampling_enabled =
451 !command_line.HasSwitch(switches::kDisableGLMultisampling);
452 prefs.privileged_webgl_extensions_enabled =
453 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
454 prefs.site_specific_quirks_enabled =
455 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
456 prefs.allow_file_access_from_file_urls =
457 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
458 prefs.show_composited_layer_borders =
459 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
460 prefs.show_composited_layer_tree =
461 command_line.HasSwitch(switches::kShowCompositedLayerTree);
462 prefs.show_fps_counter =
463 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19464 prefs.show_paint_rects =
465 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54466 prefs.accelerated_compositing_enabled =
467 GpuProcessHost::gpu_enabled() &&
468 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54469 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23470 command_line.HasSwitch(switches::kForceCompositingMode) &&
471 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54472 prefs.fixed_position_compositing_enabled =
473 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
474 prefs.accelerated_2d_canvas_enabled =
475 GpuProcessHost::gpu_enabled() &&
476 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58477 prefs.deferred_2d_canvas_enabled =
[email protected]7aca2362012-07-10 20:17:08478 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54479 prefs.accelerated_painting_enabled =
480 GpuProcessHost::gpu_enabled() &&
481 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
482 prefs.accelerated_filters_enabled =
483 GpuProcessHost::gpu_enabled() &&
484 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
485 prefs.accelerated_layers_enabled =
486 prefs.accelerated_animation_enabled =
487 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54488 prefs.accelerated_plugins_enabled =
489 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
490 prefs.accelerated_video_enabled =
491 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54492 prefs.fullscreen_enabled =
493 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16494 prefs.css_regions_enabled =
495 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29496 prefs.css_shaders_enabled =
497 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01498 prefs.css_variables_enabled =
499 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56500 prefs.device_supports_touch =
501 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]d849b122012-07-18 07:35:26502#if defined(OS_ANDROID)
503 prefs.device_supports_mouse = false;
504#endif
[email protected]64d69de42012-02-06 00:19:54505
506#if defined(OS_MACOSX)
507 bool default_enable_scroll_animator = true;
508#else
509 // On CrOS, the launcher always passes in the --enable flag.
510 bool default_enable_scroll_animator = false;
511#endif
512 prefs.enable_scroll_animator = default_enable_scroll_animator;
513 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
514 prefs.enable_scroll_animator = true;
515 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
516 prefs.enable_scroll_animator = false;
517
518 prefs.visual_word_movement_enabled =
519 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54520
521 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32522 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54523 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11524 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
525 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54526 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11527 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54528 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19529 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
530 prefs.flash_3d_enabled = false;
531 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
532 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11533 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54534 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11535 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54536 prefs.gl_multisampling_enabled = false;
537
538 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45539 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32540 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54541 prefs.accelerated_video_enabled = false;
542 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45543 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09544 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54545 }
546 }
547
[email protected]b9535422012-02-09 01:47:59548 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58549 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54550 prefs.loads_images_automatically = true;
551 prefs.javascript_enabled = true;
552 }
553
554 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
555
556 // Force accelerated compositing and 2d canvas off for chrome:, about: and
557 // chrome-devtools: pages (unless it's specifically allowed).
558 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54559 url.SchemeIs(chrome::kChromeUIScheme) ||
560 (url.SchemeIs(chrome::kAboutScheme) &&
561 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25562 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54563 prefs.accelerated_compositing_enabled = false;
564 prefs.accelerated_2d_canvas_enabled = false;
565 }
[email protected]43d9d782012-03-01 15:40:09566
[email protected]302fe422012-06-11 14:49:11567#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
568 prefs.threaded_animation_enabled =
569 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
570 prefs.per_tile_painting_enabled =
571 command_line.HasSwitch(switches::kEnablePerTilePainting);
572 prefs.partial_swap_enabled =
573 command_line.HasSwitch(switches::kEnablePartialSwap);
574#endif
575
[email protected]f98f5092012-05-19 00:08:14576 if (command_line.HasSwitch(switches::kDefaultTileWidth))
577 prefs.default_tile_width =
578 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
579 if (command_line.HasSwitch(switches::kDefaultTileHeight))
580 prefs.default_tile_height =
581 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
582 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
583 prefs.max_untiled_layer_width =
584 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
585 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
586 prefs.max_untiled_layer_height =
587 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
588
[email protected]2486dce2012-05-23 17:18:19589 if (gfx::Screen::IsDIPEnabled()) {
590 // Only apply when using DIP coordinate system as this setting interferes
591 // with fixed layout mode.
592 prefs.apply_default_device_scale_factor_in_compositor = true;
593 }
594
[email protected]96bcdc102012-05-24 23:42:10595 prefs.fixed_position_creates_stacking_context =
596 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
597
[email protected]6b4dcb072012-06-18 22:26:51598 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
599
[email protected]2e21fe292012-03-02 22:52:32600 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54601
602 return prefs;
603}
604
[email protected]b172aee2012-04-10 17:05:26605NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20606 return controller_;
607}
608
[email protected]b172aee2012-04-10 17:05:26609RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28610 return &render_manager_;
611}
612
[email protected]7bb761892012-07-20 09:32:47613bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
614 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56615 if (GetWebUI() &&
616 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17617 return true;
[email protected]d2353452012-01-19 19:53:56618 }
[email protected]f82d57b52011-04-27 19:13:17619
[email protected]d8c660432011-12-22 20:51:25620 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
621 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10622 while ((observer = it.GetNext()) != NULL)
623 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53624 return true;
[email protected]403415a2011-01-10 18:57:53625
[email protected]7bb761892012-07-20 09:32:47626 // Message handlers should be aware of which RenderViewHost sent the
627 // message, which is temporarily stored in message_source_.
628 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18629 bool handled = true;
630 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26631 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58632 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
633 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24634 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
635 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18636 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
637 OnDidLoadResourceFromMemoryCache)
638 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
639 OnDidDisplayInsecureContent)
640 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
641 OnDidRunInsecureContent)
642 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
643 OnDocumentLoadedInFrame)
644 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26645 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
646 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17647 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
648 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25649 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26650 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59651 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21652 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20653 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
654 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
655 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16656 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45657 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10658 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20659 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
660 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
661 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
662 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29663 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50664 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18665 IPC_MESSAGE_UNHANDLED(handled = false)
666 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47667 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18668
669 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38670 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18671 GetRenderProcessHost()->ReceivedBadMessage();
672 }
673
674 return handled;
675}
676
[email protected]b172aee2012-04-10 17:05:26677void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18678 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23679 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43680 if (delegate_)
681 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18682}
683
[email protected]b172aee2012-04-10 17:05:26684NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56685 return controller_;
686}
687
[email protected]b172aee2012-04-10 17:05:26688const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56689 return controller_;
690}
691
[email protected]b172aee2012-04-10 17:05:26692content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55693 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30694}
695
[email protected]b172aee2012-04-10 17:05:26696const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31697 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23698 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51699 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31700}
701
702
[email protected]b172aee2012-04-10 17:05:26703const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31704 return &property_bag_;
705}
706
[email protected]b172aee2012-04-10 17:05:26707base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31708 return &property_bag_;
709}
710
[email protected]b172aee2012-04-10 17:05:26711content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31712 return delegate_;
713}
714
[email protected]b172aee2012-04-10 17:05:26715void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31716 // TODO(cbentzel): remove this debugging code?
717 if (delegate == delegate_)
718 return;
719 if (delegate_)
720 delegate_->Detach(this);
721 delegate_ = delegate;
722 if (delegate_)
723 delegate_->Attach(this);
724}
725
[email protected]b172aee2012-04-10 17:05:26726content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41727 RenderViewHostImpl* host = render_manager_.current_host();
728 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16729}
730
[email protected]b172aee2012-04-10 17:05:26731RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31732 return render_manager_.current_host();
733}
734
[email protected]b172aee2012-04-10 17:05:26735RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31736 return render_manager_.GetRenderWidgetHostView();
737}
738
[email protected]b172aee2012-04-10 17:05:26739content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31740 return view_.get();
741}
742
[email protected]b172aee2012-04-10 17:05:26743content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50744 WebUIControllerFactory* factory =
745 content::GetContentClient()->browser()->GetWebUIControllerFactory();
746 if (!factory)
747 return NULL;
[email protected]d2353452012-01-19 19:53:56748 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22749 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50750 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22751 if (controller) {
752 web_ui->SetController(controller);
753 return web_ui;
754 }
755
756 delete web_ui;
757 return NULL;
758}
759
[email protected]b172aee2012-04-10 17:05:26760content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31761 return render_manager_.web_ui() ? render_manager_.web_ui()
762 : render_manager_.pending_web_ui();
763}
764
[email protected]b172aee2012-04-10 17:05:26765content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31766 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34767}
768
[email protected]86ef6a392012-05-11 22:03:11769void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22770 if (GetUserAgentOverride() == override)
771 return;
772
773 renderer_preferences_.user_agent_override = override;
774
775 // Send the new override string to the renderer.
776 RenderViewHost* host = GetRenderViewHost();
777 if (host)
778 host->SyncRendererPrefs();
779
780 // Reload the page if a load is currently in progress to avoid having
781 // different parts of the page loaded using different user agents.
782 NavigationEntry* entry = controller_.GetActiveEntry();
783 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
784 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11785}
786
787const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22788 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11789}
790
[email protected]b172aee2012-04-10 17:05:26791const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55792 // Transient entries take precedence. They are used for interstitial pages
793 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23794 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08795 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20796 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30797 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23798 if (entry) {
[email protected]b5cca982011-05-26 04:42:08799 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23800 }
[email protected]7ade2732011-02-10 00:13:58801 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
802 render_manager_.pending_web_ui() : render_manager_.web_ui();
803 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54804 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55805 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54806 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35807 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22808 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54809 if (!title.empty())
810 return title;
811 }
812 }
813
814 // We use the title for the last committed entry rather than a pending
815 // navigation entry. For example, when the user types in a URL, we want to
816 // keep the old page's title until the new load has committed and we get a new
817 // title.
[email protected]96d185d2009-04-24 03:28:54818 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23819 if (entry) {
[email protected]b5cca982011-05-26 04:42:08820 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23821 }
[email protected]987fc3a2011-05-26 14:18:09822
823 // |page_title_when_no_navigation_entry_| is finally used
824 // if no title cannot be retrieved.
825 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54826}
827
[email protected]b172aee2012-04-10 17:05:26828int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46829 return GetMaxPageIDForSiteInstance(GetSiteInstance());
830}
831
[email protected]b172aee2012-04-10 17:05:26832int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
833 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33834 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
835 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46836
[email protected]b6583592012-01-25 19:52:33837 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34838}
839
[email protected]b172aee2012-04-10 17:05:26840void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46841 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
842}
843
[email protected]b172aee2012-04-10 17:05:26844void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33845 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46846 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33847 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34848}
849
[email protected]b172aee2012-04-10 17:05:26850void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
851 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57852}
853
[email protected]b172aee2012-04-10 17:05:26854SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58855 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54856}
857
[email protected]b172aee2012-04-10 17:05:26858SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38859 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
860 render_manager_.pending_render_view_host() :
861 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58862 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38863}
864
[email protected]b172aee2012-04-10 17:05:26865bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49867}
868
[email protected]b172aee2012-04-10 17:05:26869bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31870 return waiting_for_response_;
871}
872
[email protected]b172aee2012-04-10 17:05:26873const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31874 return load_state_;
875}
876
[email protected]b172aee2012-04-10 17:05:26877const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31878 return load_state_host_;
879}
880
[email protected]b172aee2012-04-10 17:05:26881uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return upload_size_;
883}
884
[email protected]b172aee2012-04-10 17:05:26885uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return upload_position_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return encoding_;
891}
892
[email protected]b172aee2012-04-10 17:05:26893bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return displayed_insecure_content_;
895}
896
[email protected]b172aee2012-04-10 17:05:26897void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31898 capturing_contents_ = cap;
899}
900
[email protected]b172aee2012-04-10 17:05:26901bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
903 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
904 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49905}
906
[email protected]b172aee2012-04-10 17:05:26907void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
908 int error_code) {
[email protected]443b80e2010-12-14 00:42:23909 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34910 return;
911
[email protected]443b80e2010-12-14 00:42:23912 crashed_status_ = status;
913 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46914 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34915}
916
[email protected]b172aee2012-04-10 17:05:26917base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return crashed_status_;
919}
920
[email protected]b172aee2012-04-10 17:05:26921bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31922 return is_being_destroyed_;
923}
924
[email protected]b172aee2012-04-10 17:05:26925void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34926 if (delegate_)
927 delegate_->NavigationStateChanged(this, changed_flags);
928}
929
[email protected]3e324142012-06-25 18:26:33930base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
931 return last_selected_time_;
932}
933
934void WebContentsImpl::WasRestored() {
[email protected]96d185d2009-04-24 03:28:54935 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04936 RenderWidgetHostViewPort* rwhv =
937 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16938 if (rwhv) {
[email protected]3e324142012-06-25 18:26:33939 rwhv->WasRestored();
[email protected]789e9152009-08-04 21:59:43940#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16941 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43942#endif
943 }
[email protected]96d185d2009-04-24 03:28:54944
[email protected]5ac20162010-11-24 23:33:11945 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38946
[email protected]3e324142012-06-25 18:26:33947 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasRestored());
[email protected]b9769d82012-02-10 00:23:59948
949 // The resize rect might have changed while this was inactive -- send the new
950 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58951 RenderViewHostImpl* rvh =
952 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59953 if (rvh) {
954 rvh->ResizeRectChanged(GetRootWindowResizerRect());
955 }
[email protected]96d185d2009-04-24 03:28:54956
[email protected]3e324142012-06-25 18:26:33957 bool is_visible = true;
958 content::NotificationService::current()->Notify(
959 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
960 content::Source<WebContents>(this),
961 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31962}
963
[email protected]b172aee2012-04-10 17:05:26964void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31965 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52966 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
967 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26968 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52969 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33970 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52971 // calls us).
[email protected]c30585c2012-02-16 15:02:04972 RenderWidgetHostViewPort* rwhv =
973 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16974 if (rwhv)
975 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54976 }
977
[email protected]375fa1b2012-05-22 22:05:37978 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07979 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37980 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09981 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37982 content::Details<bool>(&is_visible));
983}
984
[email protected]b172aee2012-04-10 17:05:26985bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31986 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27987 return WillNotifyDisconnection() &&
988 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58989 !static_cast<RenderViewHostImpl*>(
990 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31991}
992
[email protected]b172aee2012-04-10 17:05:26993void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27994 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25995 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27996}
997
[email protected]b172aee2012-04-10 17:05:26998WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44999 // We use our current SiteInstance since the cloned entry will use it anyway.
1000 // We pass |this| for the |base_web_contents| to size the view correctly, and
1001 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:261002 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:441003 GetBrowserContext(), GetSiteInstance(),
1004 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:201005 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271006 return tc;
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::AddNewContents(WebContents* new_contents,
1010 WindowOpenDisposition disposition,
1011 const gfx::Rect& initial_pos,
1012 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271013 if (!delegate_)
1014 return;
1015
1016 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1017 user_gesture);
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271021 return view_->GetContentNativeView();
1022}
1023
[email protected]b172aee2012-04-10 17:05:261024gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271025 return view_->GetNativeView();
1026}
1027
[email protected]b172aee2012-04-10 17:05:261028void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271029 view_->GetContainerBounds(out);
1030}
1031
[email protected]b172aee2012-04-10 17:05:261032void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271033 view_->Focus();
1034}
1035
[email protected]14392a52012-05-02 20:28:441036void WebContentsImpl::Observe(int type,
1037 const content::NotificationSource& source,
1038 const content::NotificationDetails& details) {
1039 switch (type) {
1040 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1041 OnWebContentsDestroyed(
1042 content::Source<content::WebContents>(source).ptr());
1043 break;
[email protected]bafe6cd2012-05-23 23:09:501044 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1045 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1046 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1047 i != pending_widget_views_.end(); ++i) {
1048 if (host->GetView() == i->second) {
1049 pending_widget_views_.erase(i);
1050 break;
1051 }
1052 }
1053 break;
1054 }
[email protected]14392a52012-05-02 20:28:441055 default:
1056 NOTREACHED();
1057 }
1058}
1059
1060void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1061 // Clear the opener if it has been closed.
1062 if (web_contents == opener_) {
1063 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1064 content::Source<WebContents>(opener_));
1065 opener_ = NULL;
1066 }
1067}
1068
[email protected]b172aee2012-04-10 17:05:261069void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311070 observers_.AddObserver(observer);
1071}
1072
[email protected]b172aee2012-04-10 17:05:261073void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311074 observers_.RemoveObserver(observer);
1075}
1076
[email protected]b172aee2012-04-10 17:05:261077void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341078 if (delegate_)
1079 delegate_->ActivateContents(this);
1080}
1081
[email protected]b172aee2012-04-10 17:05:261082void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121083 if (delegate_)
1084 delegate_->DeactivateContents(this);
1085}
1086
[email protected]b172aee2012-04-10 17:05:261087void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481088 if (delegate_)
1089 delegate_->LostCapture();
1090}
1091
[email protected]b172aee2012-04-10 17:05:261092bool WebContentsImpl::PreHandleKeyboardEvent(
1093 const NativeWebKeyboardEvent& event,
1094 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481095 return delegate_ &&
1096 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1097}
1098
[email protected]b172aee2012-04-10 17:05:261099void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481100 if (delegate_)
1101 delegate_->HandleKeyboardEvent(event);
1102}
1103
[email protected]b172aee2012-04-10 17:05:261104void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431105 if (delegate_)
1106 delegate_->HandleMouseDown();
1107}
1108
[email protected]b172aee2012-04-10 17:05:261109void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481110 if (delegate_)
1111 delegate_->HandleMouseUp();
1112}
1113
[email protected]590a634e2012-07-19 16:38:231114void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481115 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231116 delegate_->HandlePointerActivate();
1117}
1118
1119void WebContentsImpl::HandleGestureBegin() {
1120 if (delegate_)
1121 delegate_->HandleGestureBegin();
1122}
1123
1124void WebContentsImpl::HandleGestureEnd() {
1125 if (delegate_)
1126 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471130 if (delegate_)
1131 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381135 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121136}
1137
[email protected]a9c81f02012-06-01 00:15:441138void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1139 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371140 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441141 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371142 } else {
1143 GotResponseToLockMouseRequest(false);
1144 }
1145}
1146
[email protected]b172aee2012-04-10 17:05:261147void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371148 if (delegate_)
1149 delegate_->LostMouseLock();
1150}
1151
[email protected]bafe6cd2012-05-23 23:09:501152void WebContentsImpl::CreateNewWindow(
1153 int route_id,
[email protected]97714c82012-06-06 10:15:131154 const ViewHostMsg_CreateWindow_Params& params,
1155 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501156 if (delegate_ && !delegate_->ShouldCreateWebContents(
1157 this, route_id, params.window_container_type, params.frame_name,
1158 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091159 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501160 return;
1161 }
1162
1163 // We usually create the new window in the same BrowsingInstance (group of
1164 // script-related windows), by passing in the current SiteInstance. However,
1165 // if the opener is being suppressed, we create a new SiteInstance in its own
1166 // BrowsingInstance.
1167 scoped_refptr<SiteInstance> site_instance =
1168 params.opener_suppressed ?
1169 SiteInstance::Create(GetBrowserContext()) :
1170 GetSiteInstance();
1171
1172 // Create the new web contents. This will automatically create the new
1173 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131174 WebContentsImpl* new_contents = new WebContentsImpl(
1175 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571176 site_instance,
1177 route_id,
1178 this,
1179 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131180 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501181 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1182
1183 if (!params.opener_suppressed) {
1184 content::WebContentsView* new_view = new_contents->GetView();
1185
1186 // TODO(brettw): It seems bogus that we have to call this function on the
1187 // newly created object and give it one of its own member variables.
1188 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1189
1190 // Save the created window associated with the route so we can show it
1191 // later.
1192 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1193 pending_contents_[route_id] = new_contents;
1194 }
1195
1196 if (delegate_) {
1197 delegate_->WebContentsCreated(
1198 this, params.opener_frame_id, params.target_url, new_contents);
1199 }
1200
1201 if (params.opener_suppressed) {
1202 // When the opener is suppressed, the original renderer cannot access the
1203 // new window. As a result, we need to show and navigate the window here.
1204 gfx::Rect initial_pos;
1205 AddNewContents(
1206 new_contents, params.disposition, initial_pos, params.user_gesture);
1207
1208 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1209 CURRENT_TAB,
1210 content::PAGE_TRANSITION_LINK,
1211 true /* is_renderer_initiated */);
1212 new_contents->OpenURL(open_params);
1213 }
1214}
1215
1216void WebContentsImpl::CreateNewWidget(int route_id,
1217 WebKit::WebPopupType popup_type) {
1218 CreateNewWidget(route_id, false, popup_type);
1219}
1220
1221void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1222 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1223}
1224
1225void WebContentsImpl::CreateNewWidget(int route_id,
1226 bool is_fullscreen,
1227 WebKit::WebPopupType popup_type) {
1228 content::RenderProcessHost* process = GetRenderProcessHost();
1229 RenderWidgetHostImpl* widget_host =
1230 new RenderWidgetHostImpl(this, process, route_id);
1231 RenderWidgetHostViewPort* widget_view =
1232 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1233 if (!is_fullscreen) {
1234 // Popups should not get activated.
1235 widget_view->SetPopupType(popup_type);
1236 }
1237 // Save the created widget associated with the route so we can show it later.
1238 pending_widget_views_[route_id] = widget_view;
1239
1240#if defined(OS_MACOSX)
1241 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1242 // to allow it to survive the trip without being hosted.
1243 base::mac::NSObjectRetain(widget_view->GetNativeView());
1244#endif
1245}
1246
1247void WebContentsImpl::ShowCreatedWindow(int route_id,
1248 WindowOpenDisposition disposition,
1249 const gfx::Rect& initial_pos,
1250 bool user_gesture) {
1251 WebContentsImpl* contents = GetCreatedWindow(route_id);
1252 if (contents)
1253 AddNewContents(contents, disposition, initial_pos, user_gesture);
1254}
1255
1256void WebContentsImpl::ShowCreatedWidget(int route_id,
1257 const gfx::Rect& initial_pos) {
1258 ShowCreatedWidget(route_id, false, initial_pos);
1259}
1260
1261void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1262 ShowCreatedWidget(route_id, true, gfx::Rect());
1263}
1264
1265void WebContentsImpl::ShowCreatedWidget(int route_id,
1266 bool is_fullscreen,
1267 const gfx::Rect& initial_pos) {
1268 if (delegate_)
1269 delegate_->RenderWidgetShowing();
1270
1271 RenderWidgetHostViewPort* widget_host_view =
1272 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1273 if (!widget_host_view)
1274 return;
1275 if (is_fullscreen) {
1276 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1277 } else {
1278 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1279 }
[email protected]89054502012-06-03 10:29:241280
1281 RenderWidgetHostImpl* render_widget_host_impl =
1282 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1283 render_widget_host_impl->Init();
1284 // Only allow privileged mouse lock for fullscreen render widget, which is
1285 // used to implement Pepper Flash fullscreen.
1286 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501287
1288#if defined(OS_MACOSX)
1289 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1290 // properly embedded (or purposefully ignored) we can release the retain we
1291 // took in CreateNewWidget().
1292 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1293#endif
1294}
1295
1296WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1297 PendingContents::iterator iter = pending_contents_.find(route_id);
1298
1299 // Certain systems can block the creation of new windows. If we didn't succeed
1300 // in creating one, just return NULL.
1301 if (iter == pending_contents_.end()) {
1302 return NULL;
1303 }
1304
1305 WebContentsImpl* new_contents = iter->second;
1306 pending_contents_.erase(route_id);
1307
1308 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1309 !new_contents->GetRenderViewHost()->GetView())
1310 return NULL;
1311
1312 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1313 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1314 return new_contents;
1315}
1316
1317RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1318 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1319 if (iter == pending_widget_views_.end()) {
1320 DCHECK(false);
1321 return NULL;
1322 }
1323
1324 RenderWidgetHostView* widget_host_view = iter->second;
1325 pending_widget_views_.erase(route_id);
1326
1327 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1328 if (!widget_host->GetProcess()->HasConnection()) {
1329 // The view has gone away or the renderer crashed. Nothing to do.
1330 return NULL;
1331 }
1332
1333 return widget_host_view;
1334}
1335
1336void WebContentsImpl::ShowContextMenu(
1337 const content::ContextMenuParams& params) {
1338 // Allow WebContentsDelegates to handle the context menu operation first.
1339 if (delegate_ && delegate_->HandleContextMenu(params))
1340 return;
1341
[email protected]5a3bdf52012-05-24 15:12:571342 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501343}
1344
[email protected]f13b4202012-06-12 23:53:231345void WebContentsImpl::RequestMediaAccessPermission(
1346 const content::MediaStreamRequest* request,
1347 const content::MediaResponseCallback& callback) {
1348 if (delegate_)
1349 delegate_->RequestMediaAccessPermission(this, request, callback);
1350 else
1351 callback.Run(content::MediaStreamDevices());
1352}
1353
[email protected]b172aee2012-04-10 17:05:261354void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231355 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331356 if (delegate_)
1357 delegate_->UpdatePreferredSize(this, pref_size);
1358}
1359
[email protected]b172aee2012-04-10 17:05:261360void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341361 if (delegate_)
1362 delegate_->ResizeDueToAutoResize(this, new_size);
1363}
1364
[email protected]b172aee2012-04-10 17:05:261365WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201366 if (!delegate_)
1367 return NULL;
[email protected]00c37fc2011-08-02 00:22:501368
[email protected]e5d549d2011-12-28 01:29:201369 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1370 // Notify observers.
1371 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1372 DidOpenURL(params.url, params.referrer,
1373 params.disposition, params.transition));
1374 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341375}
1376
[email protected]b172aee2012-04-10 17:05:261377bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501378 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251379 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231380 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251381 reload_type);
[email protected]876bc832010-09-07 16:29:541382}
[email protected]96d185d2009-04-24 03:28:541383
[email protected]ba45bfd2012-05-22 21:51:441384void WebContentsImpl::RenderViewForInterstitialPageCreated(
1385 content::RenderViewHost* render_view_host) {
1386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1387 RenderViewForInterstitialPageCreated(render_view_host));
1388}
1389
[email protected]b172aee2012-04-10 17:05:261390bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231391 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501392 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401393 // The renderer will reject IPC messages with URLs longer than
1394 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511395 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401396 return false;
1397
[email protected]9f76c1e2012-03-05 15:15:581398 RenderViewHostImpl* dest_render_view_host =
1399 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401400 if (!dest_render_view_host)
1401 return false; // Unable to create the desired render view host.
1402
[email protected]80a8fad2011-01-29 04:02:381403 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071404 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581405 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501406 WebUIControllerFactory* factory =
1407 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271408 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501409 bool is_allowed_in_web_ui_renderer =
1410 factory &&
[email protected]24e18252012-04-16 21:26:271411 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1412 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231413 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1414 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271415 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231416 content::GetContentClient()->SetActiveURL(entry.GetURL());
1417 CHECK(0);
1418 }
[email protected]54ec6472010-04-09 19:39:581419
[email protected]96d185d2009-04-24 03:28:541420 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441421 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521422 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441423 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511424 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541425
[email protected]7bb761892012-07-20 09:32:471426 // Notify observers that we will navigate in this RV.
1427 FOR_EACH_OBSERVER(WebContentsObserver,
1428 observers_,
1429 AboutToNavigateRenderView(dest_render_view_host));
1430
[email protected]96d185d2009-04-24 03:28:541431 // Used for page load time metrics.
1432 current_load_start_ = base::TimeTicks::Now();
1433
1434 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241435 std::string embedder_channel_name;
1436 int embedder_container_id;
1437 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1438 &embedder_channel_name,
1439 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341440 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271441 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241442 embedder_channel_name,
1443 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471444 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341445 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541446
[email protected]36fc0392011-12-25 03:59:511447 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541448 // HACK!! This code suppresses javascript: URLs from being added to
1449 // session history, which is what we want to do for javascript: URLs that
1450 // do not generate content. What we really need is a message from the
1451 // renderer telling us that a new page was not created. The same message
1452 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511453 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541454 return false;
1455 }
1456
[email protected]3c9e1872010-11-18 16:17:491457 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251458 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041459 observers_,
[email protected]36fc0392011-12-25 03:59:511460 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541461
[email protected]09b29342011-06-24 19:18:481462 if (delegate_)
1463 delegate_->DidNavigateToPendingEntry(this);
1464
[email protected]d5f942ba2008-09-26 19:30:341465 return true;
1466}
1467
[email protected]b172aee2012-04-10 17:05:261468void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331469 const SiteInstance* site_instance,
1470 int history_length,
1471 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411472 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1473 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191474 if (render_manager_.pending_render_view_host()) {
1475 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141476 return;
[email protected]9e1ad4b2011-08-14 16:49:191477 }
[email protected]9f76c1e2012-03-05 15:15:581478 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191479 if (!rvh) {
1480 NOTREACHED();
1481 return;
1482 }
[email protected]9f76c1e2012-03-05 15:15:581483 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191484 NOTREACHED();
1485 return;
1486 }
[email protected]9f76c1e2012-03-05 15:15:581487 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191488 history_length,
1489 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141490}
1491
[email protected]b172aee2012-04-10 17:05:261492void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271493 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541494 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1495 return;
1496 }
[email protected]9f76c1e2012-03-05 15:15:581497 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541498}
1499
[email protected]b172aee2012-04-10 17:05:261500bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271501 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541502}
1503
[email protected]b172aee2012-04-10 17:05:261504InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271505 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221506}
1507
[email protected]b172aee2012-04-10 17:05:261508bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161509 // WebKit creates Document object when MIME type is application/xhtml+xml,
1510 // so we also support this MIME type.
1511 return contents_mime_type_ == "text/html" ||
1512 contents_mime_type_ == "text/xml" ||
1513 contents_mime_type_ == "application/xhtml+xml" ||
1514 contents_mime_type_ == "text/plain" ||
1515 contents_mime_type_ == "text/css" ||
1516 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1517}
1518
[email protected]b172aee2012-04-10 17:05:261519void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591520 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161521 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481522 download_stats::RecordDownloadSource(
1523 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461524 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141525 return;
[email protected]c7dd2f62011-07-18 15:57:591526 }
1527
1528 Stop();
1529
1530 // Create the save package and possibly prompt the user for the name to save
1531 // the page as. The user prompt is an asynchronous operation that runs on
1532 // another thread.
1533 save_package_ = new SavePackage(this);
1534 save_package_->GetSaveInfo();
1535}
1536
1537// Used in automated testing to bypass prompting the user for file names.
1538// Instead, the names and paths are hard coded rather than running them through
1539// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261540bool WebContentsImpl::SavePage(const FilePath& main_file,
1541 const FilePath& dir_path,
1542 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591543 // Stop the page from navigating.
1544 Stop();
1545
1546 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271547 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591548}
1549
[email protected]b172aee2012-04-10 17:05:261550void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121551 const FilePath& file,
1552 const base::Callback<void(const FilePath&, int64)>& callback) {
1553 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1554}
1555
[email protected]b172aee2012-04-10 17:05:261556bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231557 NavigationEntryImpl* active_entry =
1558 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321559 return (active_entry != NULL &&
1560 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511561 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321562}
1563
[email protected]b172aee2012-04-10 17:05:261564const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271565 return contents_mime_type_;
1566}
1567
[email protected]b172aee2012-04-10 17:05:261568bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271569 return notify_disconnection_;
1570}
1571
[email protected]b172aee2012-04-10 17:05:261572void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311573 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581574 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1575 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161576}
1577
[email protected]b172aee2012-04-10 17:05:261578void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311579 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581580 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1581 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161582}
1583
[email protected]b172aee2012-04-10 17:05:261584content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271585 return &renderer_preferences_;
1586}
1587
[email protected]b172aee2012-04-10 17:05:261588void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271589 new_tab_start_time_ = time;
1590}
1591
[email protected]b172aee2012-04-10 17:05:261592base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271593 return new_tab_start_time_;
1594}
1595
[email protected]e35ccd52012-05-23 16:22:471596void WebContentsImpl::Close() {
1597 Close(GetRenderViewHost());
1598}
1599
[email protected]b172aee2012-04-10 17:05:261600void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151601 if (close_start_time_.is_null())
1602 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011603}
1604
[email protected]b172aee2012-04-10 17:05:261605bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191606#if defined(OS_CHROMEOS)
1607 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1608 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511609 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201610 return false;
1611 return true;
[email protected]46624bf2010-06-09 16:04:191612#else
1613 return true;
1614#endif
1615}
1616
[email protected]b172aee2012-04-10 17:05:261617void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521618 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581619 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511620 if (delegate_)
1621 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341622}
1623
[email protected]e35ccd52012-05-23 16:22:471624void WebContentsImpl::UserGestureDone() {
1625 OnUserGesture();
1626}
1627
[email protected]b172aee2012-04-10 17:05:261628void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271629 closed_by_user_gesture_ = value;
1630}
1631
[email protected]b172aee2012-04-10 17:05:261632bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271633 return closed_by_user_gesture_;
1634}
1635
[email protected]b172aee2012-04-10 17:05:261636double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051637 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561638 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251639 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171640 return 0;
[email protected]b75b8292010-10-01 07:28:251641
1642 double zoom_level;
1643 if (temporary_zoom_settings_) {
1644 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581645 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251646 } else {
[email protected]2ae88d12011-10-14 09:11:191647 GURL url;
[email protected]10f417c52011-12-28 21:04:231648 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191649 // Since zoom map is updated using rewritten URL, use rewritten URL
1650 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511651 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191652 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251653 }
[email protected]d0b8d092010-10-25 04:05:171654 return zoom_level;
1655}
[email protected]b75b8292010-10-01 07:28:251656
[email protected]b172aee2012-04-10 17:05:261657int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1658 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171659 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011660 // Calculate the zoom percent from the factor. Round up to the nearest whole
1661 // number.
[email protected]b75b8292010-10-01 07:28:251662 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011663 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251664 *enable_decrement = percent > minimum_zoom_percent_;
1665 *enable_increment = percent < maximum_zoom_percent_;
1666 return percent;
1667}
1668
[email protected]b172aee2012-04-10 17:05:261669void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501670 if (!delegate_)
1671 return;
1672
[email protected]10f417c52011-12-28 21:04:231673 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501674 if (!active_entry)
1675 return;
1676
[email protected]36fc0392011-12-25 03:59:511677 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121678}
1679
[email protected]b172aee2012-04-10 17:05:261680void WebContentsImpl::ViewFrameSource(const GURL& url,
1681 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271682 if (!delegate_)
1683 return;
1684
1685 delegate_->ViewSourceForFrame(this, url, content_state);
1686}
1687
[email protected]b172aee2012-04-10 17:05:261688int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271689 return minimum_zoom_percent_;
1690}
1691
[email protected]b172aee2012-04-10 17:05:261692int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271693 return maximum_zoom_percent_;
1694}
1695
[email protected]b172aee2012-04-10 17:05:261696gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231697 return preferred_size_;
1698}
1699
[email protected]b172aee2012-04-10 17:05:261700int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271701 return content_restrictions_;
1702}
1703
[email protected]b172aee2012-04-10 17:05:261704WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501705 WebUIControllerFactory* factory =
1706 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1707 if (!factory)
1708 return WebUI::kNoWebUI;
1709 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271710}
1711
[email protected]b172aee2012-04-10 17:05:261712content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271713 // When there is a pending navigation entry, we want to use the pending WebUI
1714 // that goes along with it to control the basic flags. For example, we want to
1715 // show the pending URL in the URL bar, so we want the display_url flag to
1716 // be from the pending entry.
1717 //
1718 // The confusion comes because there are multiple possibilities for the
1719 // initial load in a tab as a side effect of the way the RenderViewHostManager
1720 // works.
1721 //
1722 // - For the very first tab the load looks "normal". The new tab Web UI is
1723 // the pending one, and we want it to apply here.
1724 //
1725 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1726 // get switched to the one previously associated with the new tab pages.
1727 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1728 // have a committed Web UI in this case.
1729 //
1730 // This condition handles all of these cases:
1731 //
1732 // - First load in first tab: no committed nav entry + pending nav entry +
1733 // pending dom ui:
1734 // -> Use pending Web UI if any.
1735 //
1736 // - First load in second tab: no committed nav entry + pending nav entry +
1737 // no pending Web UI:
1738 // -> Use the committed Web UI if any.
1739 //
1740 // - Second navigation in any tab: committed nav entry + pending nav entry:
1741 // -> Use pending Web UI if any.
1742 //
1743 // - Normal state with no load: committed nav entry + no pending nav entry:
1744 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251745 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271746 (controller_.GetLastCommittedEntry() ||
1747 render_manager_.pending_web_ui()))
1748 return render_manager_.pending_web_ui();
1749 return render_manager_.web_ui();
1750}
1751
[email protected]b172aee2012-04-10 17:05:261752bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271753 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581754 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271755}
1756
[email protected]b172aee2012-04-10 17:05:261757bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441758 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501759}
1760
[email protected]b172aee2012-04-10 17:05:261761void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321762 SkColor color) {
[email protected]da8543762012-03-20 08:52:201763 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1764 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1765}
1766
[email protected]b172aee2012-04-10 17:05:261767void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201768 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1769 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1770 if (delegate_)
1771 delegate_->DidEndColorChooser();
1772 color_chooser_ = NULL;
1773}
1774
[email protected]b172aee2012-04-10 17:05:261775bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471776 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271777 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221778 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231779 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411780 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271781}
1782
[email protected]b172aee2012-04-10 17:05:261783void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271784 if (delegate_)
1785 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211786}
1787
[email protected]3a3b75a2012-06-01 08:38:361788void WebContentsImpl::OnRegisterIntentService(
1789 const webkit_glue::WebIntentServiceData& data,
1790 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431791 if (delegate_)
1792 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301793}
1794
[email protected]b172aee2012-04-10 17:05:261795void WebContentsImpl::OnWebIntentDispatch(
1796 const webkit_glue::WebIntentData& intent,
1797 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431798 if (!delegate_)
1799 return;
1800
[email protected]0d9989d2011-12-21 20:26:001801 WebIntentsDispatcherImpl* intents_dispatcher =
1802 new WebIntentsDispatcherImpl(this, intent, intent_id);
1803 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301804}
1805
[email protected]54047eb52012-05-08 21:45:571806void WebContentsImpl::DidStartProvisionalLoadForFrame(
1807 content::RenderViewHost* render_view_host,
1808 int64 frame_id,
1809 bool is_main_frame,
1810 const GURL& opener_url,
1811 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281812 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181813 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451814 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571815 content::RenderProcessHost* render_process_host =
1816 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541817 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571818 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451819 false,
[email protected]9f76c1e2012-03-05 15:15:581820 &validated_url);
[email protected]ef108e72012-06-20 14:03:541821 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571822 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451823 true,
1824 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181825
[email protected]0d60f0192011-04-14 12:40:101826 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251827 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101828 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571829 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541830
1831 if (is_main_frame) {
1832 // Notify observers about the provisional change in the main frame URL.
1833 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1834 ProvisionalChangeToMainFrameUrl(validated_url,
1835 validated_opener_url,
1836 render_view_host));
1837 }
1838}
1839
1840void WebContentsImpl::DidRedirectProvisionalLoad(
1841 content::RenderViewHost* render_view_host,
1842 int32 page_id,
1843 const GURL& opener_url,
1844 const GURL& source_url,
1845 const GURL& target_url) {
1846 // TODO(creis): Remove this method and have the pre-rendering code listen to
1847 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1848 // instead. See http://crbug.com/78512.
1849 GURL validated_source_url(source_url);
1850 GURL validated_target_url(target_url);
1851 GURL validated_opener_url(opener_url);
1852 content::RenderProcessHost* render_process_host =
1853 render_view_host->GetProcess();
1854 RenderViewHostImpl::FilterURL(
1855 ChildProcessSecurityPolicyImpl::GetInstance(),
1856 render_process_host->GetID(),
1857 false,
1858 &validated_source_url);
1859 RenderViewHostImpl::FilterURL(
1860 ChildProcessSecurityPolicyImpl::GetInstance(),
1861 render_process_host->GetID(),
1862 false,
1863 &validated_target_url);
1864 RenderViewHostImpl::FilterURL(
1865 ChildProcessSecurityPolicyImpl::GetInstance(),
1866 render_process_host->GetID(),
1867 true,
1868 &validated_opener_url);
1869 NavigationEntry* entry;
1870 if (page_id == -1) {
1871 entry = controller_.GetPendingEntry();
1872 } else {
1873 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1874 page_id);
1875 }
1876 if (!entry || entry->GetURL() != validated_source_url)
1877 return;
1878
1879 // Notify observers about the provisional change in the main frame URL.
1880 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1881 ProvisionalChangeToMainFrameUrl(validated_target_url,
1882 validated_opener_url,
1883 render_view_host));
[email protected]724159a2010-12-30 01:11:181884}
1885
[email protected]54047eb52012-05-08 21:45:571886void WebContentsImpl::DidFailProvisionalLoadWithError(
1887 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581888 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1889 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1890 << ", error_code: " << params.error_code
1891 << ", error_description: " << params.error_description
1892 << ", is_main_frame: " << params.is_main_frame
1893 << ", showing_repost_interstitial: " <<
1894 params.showing_repost_interstitial
1895 << ", frame_id: " << params.frame_id;
1896 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571897 content::RenderProcessHost* render_process_host =
1898 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541899 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571900 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451901 false,
[email protected]9f76c1e2012-03-05 15:15:581902 &validated_url);
[email protected]724159a2010-12-30 01:11:181903
[email protected]d7b175e2011-10-11 15:31:581904 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181905 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1906 // This means that the interstitial won't be torn down properly, which is
1907 // bad. But if we have an interstitial, go back to another tab type, and
1908 // then load the same interstitial again, we could end up getting the first
1909 // interstitial's "failed" message (as a result of the cancel) when we're on
1910 // the second one.
1911 //
1912 // We can't tell this apart, so we think we're tearing down the current page
1913 // which will cause a crash later one. There is also some code in
1914 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1915 // out because of this problem.
1916 //
1917 // http://code.google.com/p/chromium/issues/detail?id=2855
1918 // Because this will not tear down the interstitial properly, if "back" is
1919 // back to another tab type, the interstitial will still be somewhat alive
1920 // in the previous tab type. If you navigate somewhere that activates the
1921 // tab with the interstitial again, you'll see a flash before the new load
1922 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271923 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181924 LOG(WARNING) << "Discarding message during interstitial.";
1925 return;
1926 }
1927
[email protected]a16690732012-07-13 19:22:171928 // Do not clear the pending entry if one exists, so that the user's typed
1929 // URL is not lost when a navigation fails or is aborted. We'll allow
1930 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181931
[email protected]54047eb52012-05-08 21:45:571932 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181933 }
1934
[email protected]d8c660432011-12-22 20:51:251935 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581936 observers_,
1937 DidFailProvisionalLoad(params.frame_id,
1938 params.is_main_frame,
1939 validated_url,
1940 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461941 params.error_description,
1942 render_view_host));
[email protected]724159a2010-12-30 01:11:181943}
1944
[email protected]b172aee2012-04-10 17:05:261945void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181946 const GURL& url,
[email protected]70435962011-08-02 20:13:281947 const std::string& security_info,
1948 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181949 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281950 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191951 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181952 cache.Increment();
1953
1954 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081955 int cert_id = 0;
1956 net::CertStatus cert_status = 0;
1957 int security_bits = -1;
1958 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511959 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1960 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001961 content::LoadFromMemoryCacheDetails details(
1962 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1963 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181964
[email protected]ad50def52011-10-19 23:17:071965 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271966 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501967 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001968 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181969}
1970
[email protected]b172aee2012-04-10 17:05:261971void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381972 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181973 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201974 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181975}
1976
[email protected]b172aee2012-04-10 17:05:261977void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021978 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231979 LOG(INFO) << security_origin << " ran insecure content from "
1980 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381981 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411982 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1983 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181984 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411985 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201986 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181987}
1988
[email protected]b172aee2012-04-10 17:05:261989void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181990 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:471992 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:181993}
1994
[email protected]b172aee2012-04-10 17:05:261995void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311996 int64 frame_id,
1997 const GURL& validated_url,
1998 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251999 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472000 DidFinishLoad(frame_id, validated_url, is_main_frame,
2001 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312002}
2003
[email protected]b172aee2012-04-10 17:05:262004void WebContentsImpl::OnDidFailLoadWithError(
2005 int64 frame_id,
2006 const GURL& validated_url,
2007 bool is_main_frame,
2008 int error_code,
2009 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252010 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312011 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472012 error_code, error_description,
2013 message_source_));
[email protected]724159a2010-12-30 01:11:182014}
2015
[email protected]b172aee2012-04-10 17:05:262016void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272017 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432018 if (delegate_)
2019 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172020}
2021
[email protected]b172aee2012-04-10 17:05:262022void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262023 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232024 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252025 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262026 if (!entry)
2027 return;
2028 // Note that we don't call NavigationController::GotToOffset() as we don't
2029 // want to create a pending navigation entry (it might end up lingering
2030 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252031 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582032 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512033 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582034 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472035 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572036
2037 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2038 // it in now that we know. This allows us to find the entry when it commits.
2039 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232040 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332041 entry->set_site_instance(
2042 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572043 }
[email protected]216813952011-05-19 22:21:262044 }
2045}
2046
[email protected]b172aee2012-04-10 17:05:262047void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2048 int maximum_percent,
2049 bool remember) {
[email protected]216813952011-05-19 22:21:262050 minimum_zoom_percent_ = minimum_percent;
2051 maximum_zoom_percent_ = maximum_percent;
2052 temporary_zoom_settings_ = !remember;
2053}
2054
[email protected]20b433a2012-05-15 21:23:462055void WebContentsImpl::OnSaveURL(const GURL& url,
2056 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482057 download_stats::RecordDownloadSource(
2058 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262059 // Check if the URL to save matches the URL of the main frame. Since this
2060 // message originates from Pepper plugins, it may not be the case if the
2061 // plugin is an embedded element.
2062 GURL main_frame_url = GetURL();
2063 if (!main_frame_url.is_valid())
2064 return;
2065 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462066 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::OnEnumerateDirectory(int request_id,
2070 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432071 if (!delegate_)
2072 return;
2073
[email protected]b9535422012-02-09 01:47:592074 ChildProcessSecurityPolicyImpl* policy =
2075 ChildProcessSecurityPolicyImpl::GetInstance();
2076 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2077 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212078}
2079
[email protected]b172aee2012-04-10 17:05:262080void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432081 if (delegate_)
2082 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2086 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362087 const string16& title,
2088 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432089 if (!delegate_)
2090 return;
2091
[email protected]b9535422012-02-09 01:47:592092 ChildProcessSecurityPolicyImpl* policy =
2093 ChildProcessSecurityPolicyImpl::GetInstance();
2094 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2095 return;
[email protected]3a3b75a2012-06-01 08:38:362096 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202097}
2098
[email protected]b172aee2012-04-10 17:05:262099void WebContentsImpl::OnFindReply(int request_id,
2100 int number_of_matches,
2101 const gfx::Rect& selection_rect,
2102 int active_match_ordinal,
2103 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432104 if (delegate_) {
2105 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2106 active_match_ordinal, final_update);
2107 }
2108
[email protected]4e6239c2011-09-23 00:11:002109 // Send a notification to the renderer that we are ready to receive more
2110 // results from the scoping effort of the Find operation. The FindInPage
2111 // scoping is asynchronous and periodically sends results back up to the
2112 // browser using IPC. In an effort to not spam the browser we have the
2113 // browser send an ACK for each FindReply message and have the renderer
2114 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582115 GetRenderViewHostImpl()->Send(
2116 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162117}
2118
[email protected]b172aee2012-04-10 17:05:262119void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442120 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2121 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452122}
2123
[email protected]b172aee2012-04-10 17:05:262124void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2125 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102126 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252127 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102128 AppCacheAccessed(manifest_url, blocked_by_policy));
2129}
2130
[email protected]b172aee2012-04-10 17:05:262131void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322132 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432133 color_chooser_ = delegate_ ?
2134 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202135}
2136
[email protected]b172aee2012-04-10 17:05:262137void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202138 if (color_chooser_ &&
2139 color_chooser_id == color_chooser_->identifier())
2140 color_chooser_->End();
2141}
2142
[email protected]b172aee2012-04-10 17:05:262143void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322144 SkColor color) {
[email protected]da8543762012-03-20 08:52:202145 if (color_chooser_ &&
2146 color_chooser_id == color_chooser_->identifier())
2147 color_chooser_->SetSelectedColor(color);
2148}
2149
[email protected]9f2a9d72012-04-16 16:02:222150void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2151 const FilePath& path,
2152 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2154 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292155}
2156
[email protected]d0759f492012-04-19 22:50:502157// This exists for render views that don't have a WebUI, but do have WebUI
2158// bindings enabled.
2159void WebContentsImpl::OnWebUISend(const GURL& source_url,
2160 const std::string& name,
2161 const base::ListValue& args) {
2162 if (delegate_)
2163 delegate_->WebUISend(this, source_url, name, args);
2164}
2165
[email protected]96d185d2009-04-24 03:28:542166// Notifies the RenderWidgetHost instance about the fact that the page is
2167// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262168void WebContentsImpl::SetIsLoading(bool is_loading,
2169 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542170 if (is_loading == is_loading_)
2171 return;
2172
2173 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212174 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542175 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562176 upload_size_ = 0;
2177 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542178 }
2179
2180 render_manager_.SetIsLoading(is_loading);
2181
2182 is_loading_ = is_loading;
2183 waiting_for_response_ = is_loading;
2184
[email protected]6ebdc9b2010-09-27 16:55:572185 if (delegate_)
2186 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462187 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542188
[email protected]432115822011-07-10 15:52:272189 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2190 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072191 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542192 if (details)
[email protected]6c2381d2011-10-19 02:52:532193 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072194 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502195 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542196 det);
2197}
2198
[email protected]b172aee2012-04-10 17:05:262199void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132200 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322201 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562202 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382203 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442204 // that opened the window, as long as both renderers have the same
2205 // privileges.
[email protected]1fd1a502011-03-30 16:55:562206 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562207 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582208 // web_ui might be NULL if the URL refers to a non-existent extension.
2209 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402210 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522211 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442212 }
2213 }
[email protected]1fd1a502011-03-30 16:55:562214 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442215 }
2216
[email protected]4e697b042011-07-08 06:44:562217 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322218 // Clear the status bubble. This is a workaround for a bug where WebKit
2219 // doesn't let us know that the cursor left an element during a
2220 // transition (this is also why the mouse cursor remains as a hand after
2221 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2222 // clear the bubble when a user navigates to a named anchor in the same
2223 // page.
[email protected]36fc0392011-12-25 03:59:512224 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322225 }
2226
[email protected]a6e82fc2010-02-24 22:28:142227 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472228 // Once the main frame is navigated, we're no longer considered to have
2229 // displayed insecure content.
2230 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172231 }
[email protected]ce5c4502009-05-06 16:46:112232
[email protected]3c9e1872010-11-18 16:17:492233 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252234 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042235 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322239 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132240 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322241 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062242 // If we navigate off the page, reset JavaScript state. This does nothing
2243 // to prevent a malicious script from spamming messages, since the script
2244 // could just reload the page to stop blocking.
2245 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552246 dialog_creator_->ResetJavaScriptState(this);
2247 dialog_creator_ = NULL;
2248 }
[email protected]420ae012009-04-24 05:16:322249
[email protected]3c9e1872010-11-18 16:17:492250 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252251 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042252 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322253}
2254
[email protected]b172aee2012-04-10 17:05:262255void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462256 // If we are creating a RVH for a restored controller, then we need to make
2257 // sure the RenderView starts with a next_page_id_ larger than the number
2258 // of restored entries. This must be called before the RenderView starts
2259 // navigating (to avoid a race between the browser updating max_page_id and
2260 // the renderer updating next_page_id_). Because of this, we only call this
2261 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562262 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582263 if (max_restored_page_id >
2264 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2265 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2266 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322267}
2268
[email protected]b172aee2012-04-10 17:05:262269bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2270 const string16& title) {
[email protected]420ae012009-04-24 05:16:322271 // For file URLs without a title, use the pathname instead. In the case of a
2272 // synthesized title, we don't want the update to count toward the "one set
2273 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512274 string16 final_title;
[email protected]420ae012009-04-24 05:16:322275 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512276 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2277 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322278 explicit_set = false; // Don't count synthetic titles toward the set limit.
2279 } else {
[email protected]acafd272011-07-26 17:35:572280 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322281 explicit_set = true;
2282 }
2283
[email protected]987fc3a2011-05-26 14:18:092284 // If a page is created via window.open and never navigated,
2285 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552286 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092287 if (entry) {
[email protected]36fc0392011-12-25 03:59:512288 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092289 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322290
[email protected]36fc0392011-12-25 03:59:512291 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092292 } else {
2293 if (page_title_when_no_navigation_entry_ == final_title)
2294 return false; // Nothing changed, don't bother.
2295
2296 page_title_when_no_navigation_entry_ = final_title;
2297 }
[email protected]420ae012009-04-24 05:16:322298
[email protected]420ae012009-04-24 05:16:322299 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232300 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322301
[email protected]2bb171882012-03-07 02:09:462302 std::pair<content::NavigationEntry*, bool> details =
2303 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142304
[email protected]ad50def52011-10-19 23:17:072305 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442306 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2307 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462308 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042309
[email protected]420ae012009-04-24 05:16:322310 return true;
2311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322314 // After sending out a swap notification, we need to send a disconnect
2315 // notification so that clients that pick up a pointer to |this| can NULL the
2316 // pointer. See Bug 1230284.
2317 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072318 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202319 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2320 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072321 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322322}
2323
[email protected]b172aee2012-04-10 17:05:262324void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322325 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072326 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122327 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2328 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072329 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322333 if (!notify_disconnection_)
2334 return;
2335
2336 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072337 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322338 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2339 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072340 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322341}
2342
[email protected]5a3bdf52012-05-24 15:12:572343RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2344 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322345}
2346
[email protected]8d3347f2009-07-09 22:00:212347RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262348WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212349 return &render_manager_;
2350}
2351
[email protected]b172aee2012-04-10 17:05:262352content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372353 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462354 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512355}
2356
[email protected]b172aee2012-04-10 17:05:262357WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172358 return this;
2359}
2360
[email protected]b172aee2012-04-10 17:05:262361gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172362 if (delegate_)
2363 return delegate_->GetRootWindowResizerRect();
2364 return gfx::Rect();
2365}
2366
[email protected]b172aee2012-04-10 17:05:262367void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442368 // Don't send notifications if we are just creating a swapped-out RVH for
2369 // the opener chain. These won't be used for view-source or WebUI, so it's
2370 // ok to return early.
2371 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2372 return;
2373
[email protected]ad50def52011-10-19 23:17:072374 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302375 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322376 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532377 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232378 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322379 if (!entry)
2380 return;
2381
2382 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352383 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562384 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582385 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322386
2387 if (entry->IsViewSourceMode()) {
2388 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582389 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2390 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322391 }
[email protected]0666aef2009-05-13 19:48:082392
[email protected]d487beefe2011-12-21 05:41:212393 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262394
2395 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252396 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322397}
2398
[email protected]b172aee2012-04-10 17:05:262399void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522400 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322401 // Don't notify the world, since this came from a renderer in the
2402 // background.
2403 return;
2404 }
2405
2406 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312407 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232408 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302409
2410 // Restore the focus to the tab (otherwise the focus will be on the top
2411 // window).
[email protected]484ae5912010-09-29 19:16:142412 if (was_crashed && !FocusLocationBarByDefault() &&
2413 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302414 Focus();
[email protected]484ae5912010-09-29 19:16:142415 }
[email protected]32ded2212011-11-10 18:51:432416
[email protected]d8c660432011-12-22 20:51:252417 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322418}
2419
[email protected]b172aee2012-04-10 17:05:262420void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2421 base::TerminationStatus status,
2422 int error_code) {
[email protected]151a63d2011-12-20 22:32:522423 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322424 // The pending page's RenderViewHost is gone.
2425 return;
2426 }
2427
2428 SetIsLoading(false, NULL);
2429 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232430 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312431 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322432
[email protected]d8c660432011-12-22 20:51:252433 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272434 observers_,
[email protected]be1f56ab2011-12-22 06:55:312435 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322436}
2437
[email protected]b172aee2012-04-10 17:05:262438void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482439 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252440 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062441}
2442
[email protected]b172aee2012-04-10 17:05:262443void WebContentsImpl::DidNavigate(
2444 RenderViewHost* rvh,
2445 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582446 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322447 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372448
[email protected]434f69f2012-02-06 21:56:522449 // Update the site of the SiteInstance if it doesn't have one yet, unless
2450 // this is for about:blank. In that case, the SiteInstance can still be
2451 // considered unused until a navigation to a real page.
2452 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2453 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332454 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522455 }
[email protected]420ae012009-04-24 05:16:322456
2457 // Need to update MIME type here because it's referred to in
2458 // UpdateNavigationCommands() called by RendererDidNavigate() to
2459 // determine whether or not to enable the encoding menu.
2460 // It's updated only for the main frame. For a subframe,
2461 // RenderView::UpdateURL does not set params.contents_mime_type.
2462 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2463 // TODO(jungshik): Add a test for the encoding menu to avoid
2464 // regressing it again.
[email protected]2905f742011-10-13 03:51:582465 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322466 contents_mime_type_ = params.contents_mime_type;
2467
[email protected]8286f51a2011-05-31 17:39:132468 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002469 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392470
[email protected]a9c0bfe2010-09-17 08:35:222471 // Send notification about committed provisional loads. This notification is
2472 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2473 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082474 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072475 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2476 // that is not recorded in the navigation history. For the purpose of
2477 // tracking navigation events, we treat this event as a sub frame navigation
2478 // event.
2479 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582480 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222481 // Whether or not a page transition was triggered by going backward or
2482 // forward in the history is only stored in the navigation controller's
2483 // entry list.
2484 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512485 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582486 content::PAGE_TRANSITION_FORWARD_BACK)) {
2487 transition_type = content::PageTransitionFromInt(
2488 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222489 }
[email protected]0d60f0192011-04-14 12:40:102490 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252491 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102492 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462493 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222494 }
2495
[email protected]76543b92009-08-31 17:27:452496 if (!did_navigate)
2497 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322498
2499 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2500 // for the appropriate notification (best) or you can add it to
2501 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2502 // necessary, please).
2503
2504 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002505 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322506 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512507 if (delegate_)
2508 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002509 }
[email protected]420ae012009-04-24 05:16:322510 DidNavigateAnyFramePostCommit(rvh, details, params);
2511}
2512
[email protected]b172aee2012-04-10 17:05:262513void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2514 int32 page_id,
2515 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152516 // Ensure that this state update comes from either the active RVH or one of
2517 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522518 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322519
2520 // We must be prepared to handle state updates for any page, these occur
2521 // when the user is scrolling and entering form data, as well as when we're
2522 // leaving a page, in which case our state may have already been moved to
2523 // the next page. The navigation controller will look up the appropriate
2524 // NavigationEntry and update it when it is notified via the delegate.
2525
2526 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582527 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322528 if (entry_index < 0)
2529 return;
[email protected]10f417c52011-12-28 21:04:232530 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322531
[email protected]36fc0392011-12-25 03:59:512532 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322533 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512534 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322535 controller_.NotifyEntryChanged(entry, entry_index);
2536}
2537
[email protected]b172aee2012-04-10 17:05:262538void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2539 int32 page_id,
2540 const string16& title,
2541 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322542 // If we have a title, that's a pretty good indication that we've started
2543 // getting useful data.
2544 SetNotWaitingForResponse();
2545
[email protected]73eb2602012-02-09 19:50:552546 // Try to find the navigation entry, which might not be the current one.
2547 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232548 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582549 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092550
[email protected]73eb2602012-02-09 19:50:552551 // We can handle title updates when we don't have an entry in
2552 // UpdateTitleForEntry, but only if the update is from the current RVH.
2553 if (!entry && rvh != GetRenderViewHost())
2554 return;
2555
[email protected]a49e10b2011-08-01 23:57:462556 // TODO(evan): make use of title_direction.
2557 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092558 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322559 return;
2560
2561 // Broadcast notifications when the UI should be updated.
2562 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462563 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2567 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312568 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512572 if (delegate_)
2573 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292577 // The UI may be in an event-tracking loop, such as between the
2578 // mouse-down and mouse-up in text selection or a button click.
2579 // Defer the close until after tracking is complete, so that we
2580 // don't free objects out from under the UI.
2581 // TODO(shess): This could probably be integrated with the
2582 // IsDoingDrag() test below. Punting for now because I need more
2583 // research to understand how this impacts platforms other than Mac.
2584 // TODO(shess): This could get more fine-grained. For instance,
2585 // closing a tab in another window while selecting text in the
2586 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212587 if (GetView()->IsEventTracking()) {
2588 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292589 return;
2590 }
2591
[email protected]24a4d1062009-07-10 23:10:422592 // If we close the tab while we're in the middle of a drag, we'll crash.
2593 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212594 if (GetView()->IsDoingDrag()) {
2595 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422596 return;
2597 }
2598
[email protected]420ae012009-04-24 05:16:322599 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522600 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512601 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322602}
2603
[email protected]b172aee2012-04-10 17:05:262604void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522605 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512606 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512610 if (delegate_ && delegate_->IsPopupOrPanel(this))
2611 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322612}
2613
[email protected]89793072012-07-23 22:25:292614void WebContentsImpl::DidStartLoading(
2615 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322616 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492617
[email protected]82114f52012-03-20 22:53:412618 if (delegate_ && content_restrictions_)
2619 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492620
2621 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292622 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2623 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322624}
2625
[email protected]89793072012-07-23 22:25:292626void WebContentsImpl::DidStopLoading(
2627 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322628 scoped_ptr<LoadNotificationDetails> details;
2629
[email protected]10f417c52011-12-28 21:04:232630 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322631 // An entry may not exist for a stop when loading an initial blank page or
2632 // if an iframe injected by script into a blank page finishes loading.
2633 if (entry) {
[email protected]420ae012009-04-24 05:16:322634 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2635
2636 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512637 entry->GetVirtualURL(),
2638 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322639 elapsed,
2640 &controller_,
2641 controller_.GetCurrentEntryIndex()));
2642 }
2643
[email protected]420ae012009-04-24 05:16:322644 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492645
2646 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292647 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2648 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322649}
2650
[email protected]b172aee2012-04-10 17:05:262651void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162652 controller_.DiscardNonCommittedEntries();
2653
2654 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462655 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162656}
2657
[email protected]b172aee2012-04-10 17:05:262658void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512659 if (delegate_)
2660 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402661}
2662
[email protected]87717d0e2012-04-26 02:58:432663void WebContentsImpl::DocumentAvailableInMainFrame(
2664 RenderViewHost* render_view_host) {
2665 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2666 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102667}
2668
[email protected]b172aee2012-04-10 17:05:262669void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082670 RenderViewHost* render_view_host,
2671 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072672 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272673 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322674 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532675 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082676}
2677
[email protected]196159d2012-05-04 17:26:542678void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2679 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262680 const content::Referrer& referrer,
2681 WindowOpenDisposition disposition,
2682 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542683 // If this came from a swapped out RenderViewHost, we only allow the request
2684 // if we are still in the same BrowsingInstance.
2685 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2686 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2687 return;
2688 }
2689
[email protected]4ad5d77d2011-12-03 02:00:482690 // Delegate to RequestTransferURL because this is just the generic
2691 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582692 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482693 GlobalRequestID());
2694}
2695
[email protected]b172aee2012-04-10 17:05:262696void WebContentsImpl::RequestTransferURL(
2697 const GURL& url,
2698 const content::Referrer& referrer,
2699 WindowOpenDisposition disposition,
2700 int64 source_frame_id,
2701 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202702 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582703 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582704 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352705 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322706 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2707 // generated suggestions).
2708 //
[email protected]e0112912011-02-02 22:54:352709 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162710 // want web sites to see a referrer of "chrome://blah" (and some
2711 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322712 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432713 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222714 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482715 false /* is_renderer_initiated */);
2716 params.transferred_global_request_id = old_request_id;
2717 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222718 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322719 } else {
[email protected]6bf6a6b52012-02-03 15:41:432720 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482721 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2722 params.transferred_global_request_id = old_request_id;
2723 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582724 }
2725 if (new_contents) {
2726 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252727 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582728 DidOpenRequestedURL(new_contents,
2729 url,
2730 referrer,
2731 disposition,
2732 transition_type,
2733 source_frame_id));
[email protected]420ae012009-04-24 05:16:322734 }
2735}
2736
[email protected]e1c3a552012-05-04 20:51:322737void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2738 // Tell the active RenderViewHost to run unload handlers and close, as long
2739 // as the request came from a RenderViewHost in the same BrowsingInstance.
2740 // In most cases, we receive this from a swapped out RenderViewHost.
2741 // It is possible to receive it from one that has just been swapped in,
2742 // in which case we might as well deliver the message anyway.
2743 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2744 GetRenderViewHost()->ClosePage();
2745}
2746
[email protected]f546640b2012-05-15 00:03:492747void WebContentsImpl::RouteMessageEvent(
2748 RenderViewHost* rvh,
2749 const ViewMsg_PostMessage_Params& params) {
2750 // Only deliver the message to the active RenderViewHost if the request
2751 // came from a RenderViewHost in the same BrowsingInstance.
2752 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2753 return;
2754
2755 ViewMsg_PostMessage_Params new_params(params);
2756
2757 // If there is a source_routing_id, translate it to the routing ID for
2758 // the equivalent swapped out RVH in the target process. If we need
2759 // to create a swapped out RVH for the source tab, we create its opener
2760 // chain as well, since those will also be accessible to the target page.
2761 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2762 // Try to look up the WebContents for the source page.
2763 WebContentsImpl* source_contents = NULL;
2764 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2765 rvh->GetProcess()->GetID(), params.source_routing_id);
2766 if (source_rvh) {
2767 source_contents = static_cast<WebContentsImpl*>(
2768 source_rvh->GetDelegate()->GetAsWebContents());
2769 }
2770
2771 if (source_contents) {
2772 new_params.source_routing_id =
2773 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2774 } else {
2775 // We couldn't find it, so don't pass a source frame.
2776 new_params.source_routing_id = MSG_ROUTING_NONE;
2777 }
2778 }
2779
2780 // In most cases, we receive this from a swapped out RenderViewHost.
2781 // It is possible to receive it from one that has just been swapped in,
2782 // in which case we might as well deliver the message anyway.
2783 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2784 GetRenderViewHost()->GetRoutingID(), new_params));
2785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342788 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412789 const string16& message,
2790 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322791 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142792 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322793 IPC::Message* reply_msg,
2794 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072795 // Suppress JavaScript dialogs when requested. Also suppress messages when
2796 // showing an interstitial as it's shown over the previous page and we don't
2797 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502798 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582799 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272800 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072801 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522802 delegate_->ShouldSuppressDialogs() ||
2803 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322804
2805 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432806 std::string accept_lang = content::GetContentClient()->browser()->
2807 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552808 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522809 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432810 this,
2811 frame_url.GetOrigin(),
2812 accept_lang,
2813 javascript_message_type,
2814 message,
[email protected]51da7e32012-01-30 19:24:522815 default_prompt,
[email protected]b172aee2012-04-10 17:05:262816 base::Bind(&WebContentsImpl::OnDialogClosed,
2817 base::Unretained(this),
2818 rvh,
2819 reply_msg),
[email protected]51da7e32012-01-30 19:24:522820 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322821 }
[email protected]3ab9cb82011-06-03 18:02:072822
2823 if (suppress_this_message) {
2824 // If we are suppressing messages, just reply as if the user immediately
2825 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342826 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072827 }
2828
2829 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322830}
2831
[email protected]b172aee2012-04-10 17:05:262832void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2833 const string16& message,
2834 bool is_reload,
2835 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582836 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512837 if (delegate_)
2838 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072839
2840 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582841 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072842 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522843 delegate_->ShouldSuppressDialogs() ||
2844 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152845 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342846 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582847 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502848 return;
2849 }
[email protected]3ab9cb82011-06-03 18:02:072850
[email protected]7ab1e7d62009-10-14 23:32:012851 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552852 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522853 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322854 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262855 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522856 reply_msg));
[email protected]420ae012009-04-24 05:16:322857}
2858
[email protected]a796f202012-05-30 14:14:252859bool WebContentsImpl::AddMessageToConsole(int32 level,
2860 const string16& message,
2861 int32 line_no,
2862 const string16& source_id) {
2863 if (!delegate_)
2864 return false;
2865 return delegate_->AddMessageToConsole(this, level, message, line_no,
2866 source_id);
2867}
2868
[email protected]b172aee2012-04-10 17:05:262869WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332870 // We want to base the page config off of the real URL, rather than the
2871 // display URL.
2872 GURL url = controller_.GetActiveEntry()
2873 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2874 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322875}
2876
[email protected]b172aee2012-04-10 17:05:262877void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272878 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252879 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222880
[email protected]ea114722012-03-12 01:11:252881 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172882 if (rdh) // NULL in unittests.
2883 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252884}
2885
[email protected]b172aee2012-04-10 17:05:262886void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442887 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252888 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442889}
2890
[email protected]b172aee2012-04-10 17:05:262891void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2892 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152893 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522894 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152895 return;
2896
[email protected]9f76c1e2012-03-05 15:15:582897 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2898
[email protected]e5fc1632011-08-08 07:51:532899 // Ignore renderer unresponsive event if debugger is attached to the tab
2900 // since the event may be a result of the renderer sitting on a breakpoint.
2901 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442902 DevToolsAgentHost* agent =
2903 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2904 if (agent &&
2905 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532906 return;
2907
[email protected]420ae012009-04-24 05:16:322908 if (is_during_unload) {
2909 // Hang occurred while firing the beforeunload/unload handler.
2910 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582911 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322912
2913 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2914 return;
2915
2916 // If the tab hangs in the beforeunload/unload handler there's really
2917 // nothing we can do to recover. Pretend the unload listeners have
2918 // all fired and close the tab. If the hang is in the beforeunload handler
2919 // then the user will not have the option of cancelling the close.
2920 Close(rvh);
2921 return;
2922 }
2923
[email protected]9f76c1e2012-03-05 15:15:582924 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472925 return;
2926
[email protected]6934a702011-12-20 00:04:512927 if (delegate_)
2928 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322929}
2930
[email protected]b172aee2012-04-10 17:05:262931void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512932 if (delegate_)
2933 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322934}
2935
[email protected]b172aee2012-04-10 17:05:262936void WebContentsImpl::LoadStateChanged(
2937 const GURL& url,
2938 const net::LoadStateWithParam& load_state,
2939 uint64 upload_position,
2940 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322941 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562942 upload_position_ = upload_position;
2943 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502944 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202945 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302946 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212947 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322948 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462949 if (IsLoading()) {
2950 NotifyNavigationStateChanged(
2951 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2952 }
[email protected]420ae012009-04-24 05:16:322953}
2954
[email protected]b172aee2012-04-10 17:05:262955void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512956 if (delegate_)
2957 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252958}
2959
[email protected]b172aee2012-04-10 17:05:262960void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322961 bool proceed,
2962 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512963 if (delegate_)
2964 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322965}
2966
[email protected]b172aee2012-04-10 17:05:262967void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542968 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232969 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2970 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542971}
2972
[email protected]b172aee2012-04-10 17:05:262973void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102974 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262975 gfx::Size size = view_->GetContainerSize();
2976 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2977 // here during container initialization and normal window size will be set
2978 // later. In case of tab duplication this resizing to 0x0 prevents setting
2979 // normal size later so just ignore it.
2980 if (!size.IsEmpty())
2981 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322982}
2983
[email protected]b172aee2012-04-10 17:05:262984void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542985 NotifySwapped();
2986}
2987
[email protected]14392a52012-05-02 20:28:442988int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2989 SiteInstance* instance) {
2990 if (!opener_)
2991 return MSG_ROUTING_NONE;
2992
2993 // Recursively create RenderViews for anything else in the opener chain.
2994 return opener_->CreateOpenerRenderViews(instance);
2995}
2996
2997int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2998 int opener_route_id = MSG_ROUTING_NONE;
2999
3000 // If this tab has an opener, ensure it has a RenderView in the given
3001 // SiteInstance as well.
3002 if (opener_)
3003 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3004
3005 // Create a swapped out RenderView in the given SiteInstance if none exists,
3006 // setting its opener to the given route_id. Return the new view's route_id.
3007 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3008}
3009
[email protected]b172aee2012-04-10 17:05:263010NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:203011 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:543012}
3013
[email protected]b172aee2012-04-10 17:05:263014WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563015 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323016}
3017
[email protected]10f417c52011-12-28 21:04:233018NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263019 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323020 return controller_.GetLastCommittedEntry();
3021}
3022
[email protected]b172aee2012-04-10 17:05:263023bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443024 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443025 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323026 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523027
[email protected]420ae012009-04-24 05:16:323028 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443029 if (rwh_view)
3030 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323031
[email protected]74ce1ad2011-12-16 21:51:463032 // Make sure we use the correct starting page_id in the new RenderView.
3033 UpdateMaxPageIDIfNecessary(render_view_host);
3034 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583035 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463036
[email protected]7900bfdb2012-05-24 19:31:243037 std::string embedder_channel_name;
3038 int embedder_container_id;
3039 GetBrowserPluginEmbedderInfo(render_view_host,
3040 &embedder_channel_name,
3041 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583042 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493043 render_view_host)->CreateRenderView(string16(),
3044 opener_route_id,
3045 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243046 embedder_channel_name,
3047 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523048 return false;
[email protected]14392a52012-05-02 20:28:443049 }
[email protected]a4127722011-04-27 23:13:523050
[email protected]e60c0232011-11-11 19:56:353051#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503052 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3053 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443054 if (rwh_view) {
3055 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3056 render_widget_host->WasResized();
3057 }
[email protected]f8233cc2011-05-31 20:24:503058#endif
3059
[email protected]420ae012009-04-24 05:16:323060 return true;
3061}
3062
[email protected]b172aee2012-04-10 17:05:263063void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3064 IPC::Message* reply_msg,
3065 bool success,
3066 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543067 if (is_showing_before_unload_dialog_ && !success) {
3068 // If a beforeunload dialog is canceled, we need to stop the throbber from
3069 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293070 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353071 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543072
[email protected]3bbacc5b2012-04-17 17:46:153073 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543074 }
3075 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583076 static_cast<RenderViewHostImpl*>(
3077 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543078}
3079
[email protected]b172aee2012-04-10 17:05:263080void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123081 encoding_ = content::GetContentClient()->browser()->
3082 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103083}
[email protected]f45d2a72010-03-08 23:28:353084
[email protected]b172aee2012-04-10 17:05:263085void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463086 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263087 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573088 DownloadManager* dlm =
3089 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143090 if (!dlm)
3091 return;
3092 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263093 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143094 const NavigationEntry* entry = controller_.GetActiveEntry();
3095 if (entry)
3096 post_id = entry->GetPostID();
3097 }
[email protected]29a5ffc82012-03-13 19:35:583098 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143099 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143100 scoped_ptr<DownloadUrlParameters> params(
3101 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493102 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143103 params->set_post_id(post_id);
3104 params->set_prefer_cache(true);
3105 if (post_id >= 0)
3106 params->set_method("POST");
3107 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143108}
3109
[email protected]b172aee2012-04-10 17:05:263110void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213111 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443112 // Can be NULL during tests.
3113 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213114 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363115}
[email protected]9f76c1e2012-03-05 15:15:583116
[email protected]b172aee2012-04-10 17:05:263117RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583118 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3119}
[email protected]7900bfdb2012-05-24 19:31:243120
3121void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3122 content::RenderViewHost* render_view_host,
3123 std::string* embedder_channel_name,
3124 int* embedder_container_id) {
3125 content::RenderProcessHost* embedder_render_process_host =
3126 browser_plugin_host()->embedder_render_process_host();
3127 *embedder_container_id = browser_plugin_host()->instance_id();
3128 int embedder_process_id =
3129 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3130 if (embedder_process_id != -1) {
3131 *embedder_channel_name =
3132 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3133 embedder_process_id);
3134 }
3135}