blob: baa4e19055455d5d6a1a300f0c5ff78cdeb6cae4 [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]66bd5512012-08-01 02:02:5276#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2477#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3678#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3179#include "webkit/glue/webpreferences.h"
80
[email protected]f66df822012-05-18 16:52:1781#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5082#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5784#endif
[email protected]3e45ba92009-02-20 21:09:0085
[email protected]420ae012009-04-24 05:16:3286// Cross-Site Navigations
87//
[email protected]b172aee2012-04-10 17:05:2688// If a WebContentsImpl is told to navigate to a different web site (as
89// determined by SiteInstance), it will replace its current RenderViewHost with
90// a new RenderViewHost dedicated to the new SiteInstance. This works as
91// follows:
[email protected]420ae012009-04-24 05:16:3292//
93// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4694// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3295// - The pending RVH is "suspended," so that no navigation messages are sent to
96// its renderer until the onbeforeunload JavaScript handler has a chance to
97// run in the current RVH.
98// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
99// that it has a pending cross-site request. ResourceDispatcherHost will
100// check for this when the response arrives.
101// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46102// cancel all the pending logic. Otherwise we allow the pending RVH to send
103// the navigation request to its renderer.
104// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
105// main resource load on the pending RVH. It checks CrossSiteRequestManager
106// to see that it is a cross-site request, and installs a
107// CrossSiteResourceHandler.
108// - When RDH receives a response, the BufferedResourceHandler determines
109// whether it is a download. If so, it sends a message to the new renderer
110// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26111// pending RVH remains until the next DidNavigate event for this
112// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32113// - After RDH receives a response and determines that it is safe and not a
114// download, it pauses the response to first run the old page's onunload
115// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26116// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32117// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15118// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32119// the ResourceDispatcherHost, who unpauses the response. Data is then sent
120// to the pending RVH.
121// - The pending renderer sends a FrameNavigate message that invokes the
122// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46123// pending RVH.
[email protected]992db4c2011-05-12 15:37:15124// - The previous renderer is kept swapped out in RenderViewHostManager in case
125// the user goes back. The process only stays live if another tab is using
126// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32127
[email protected]b441a8492012-06-06 14:55:57128using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44129using content::DevToolsAgentHost;
130using content::DevToolsAgentHostRegistry;
131using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17132using content::DownloadItem;
133using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14134using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20135using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56136using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13137using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27138using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54139using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50140using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23141using content::NavigationEntry;
142using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20143using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57145using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57146using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27147using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11148using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50149using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58150using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04151using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25152using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14153using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43154using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33155using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38156using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09157using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25158using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56159using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22160using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50161using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25162using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44163
[email protected]420ae012009-04-24 05:16:32164namespace {
165
166// Amount of time we wait between when a key event is received and the renderer
167// is queried for its state and pushed to the NavigationEntry.
168const int kQueryStateDelay = 5000;
169
[email protected]6ebdc9b2010-09-27 16:55:57170const int kSyncWaitDelay = 40;
171
[email protected]82114f52012-03-20 22:53:41172const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05173
[email protected]420ae012009-04-24 05:16:32174#if defined(OS_WIN)
175
176BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
177 // Note: erase is required to properly paint some widgets borders. This can
178 // be seen with textfields.
179 InvalidateRect(hwnd, NULL, TRUE);
180 return TRUE;
181}
182#endif
183
[email protected]2c5569662011-03-22 20:45:02184ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23185 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50186 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16187 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47190 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23192 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
193 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47194 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16195 break; // Fall through to rest of function.
196 }
[email protected]5e369672009-11-03 23:48:30197
[email protected]59246c572012-02-10 13:32:13198 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
199 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23200 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13201 browser_context->DidLastSessionExitCleanly()) {
202 if (entry.GetHasPostData())
203 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02204 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13205 }
[email protected]5e369672009-11-03 23:48:30206
[email protected]2c5569662011-03-22 20:45:02207 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30208}
209
[email protected]10f417c52011-12-28 21:04:23210void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47211 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42212 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50213 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24214 const std::string& embedder_channel_name,
215 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16216 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51217 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54218 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55219 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
220 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36221 if (!entry.GetBaseURLForDataURL().is_empty()) {
222 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
223 params->history_url_for_data_url = entry.GetVirtualURL();
224 }
[email protected]36fc0392011-12-25 03:59:51225 params->referrer = entry.GetReferrer();
226 params->transition = entry.GetTransitionType();
227 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00228 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55229 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34230 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47231 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48232 params->transferred_request_child_id =
233 entry.transferred_global_request_id().child_id;
234 params->transferred_request_request_id =
235 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22236 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00237 // Avoid downloading when in view-source mode.
238 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24239 params->embedder_channel_name = embedder_channel_name;
240 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44241 params->is_post = entry.GetHasPostData();
242 if(entry.GetBrowserInitiatedPostData()) {
243 params->browser_initiated_post_data.assign(
244 entry.GetBrowserInitiatedPostData()->front(),
245 entry.GetBrowserInitiatedPostData()->front() +
246 entry.GetBrowserInitiatedPostData()->size());
247
248 }
[email protected]6c6b02d2011-09-02 03:36:47249
[email protected]7c16976c2012-08-04 02:38:23250 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
251 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
252 // We may have been redirected when navigating to the current URL.
253 // Use the URL the user originally intended to visit, if it's valid and if a
254 // POST wasn't involved; the latter case avoids issues with sending data to
255 // the wrong page.
256 params->url = entry.GetOriginalRequestURL();
257 } else {
258 params->url = entry.GetURL();
259 }
260
[email protected]6c6b02d2011-09-02 03:36:47261 if (delegate)
262 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34263}
264
[email protected]f98f5092012-05-19 00:08:14265int GetSwitchValueAsInt(
266 const CommandLine& command_line,
267 const std::string& switch_string,
268 int min_value) {
269 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
270 int int_value;
271 if (base::StringToInt(string_value, &int_value))
272 return std::max(min_value, int_value);
273 else
274 return min_value;
275}
276
[email protected]420ae012009-04-24 05:16:32277} // namespace
278
[email protected]a81343d232011-12-27 07:39:20279namespace content {
280
281WebContents* WebContents::Create(
282 BrowserContext* browser_context,
283 SiteInstance* site_instance,
284 int routing_id,
[email protected]b172aee2012-04-10 17:05:26285 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20286 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26287 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43288 browser_context,
289 site_instance,
290 routing_id,
[email protected]b172aee2012-04-10 17:05:26291 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44292 NULL,
[email protected]adbfb8df2012-02-24 01:19:43293 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20294}
[email protected]746d3052012-05-22 15:15:47295
[email protected]299d7f12012-05-23 05:31:15296WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47297 return rvh->GetDelegate()->GetAsWebContents();
298}
299
[email protected]a81343d232011-12-27 07:39:20300}
[email protected]f4f50ef2011-01-21 19:01:19301
[email protected]b172aee2012-04-10 17:05:26302// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32303
[email protected]b172aee2012-04-10 17:05:26304WebContentsImpl::WebContentsImpl(
305 content::BrowserContext* browser_context,
306 SiteInstance* site_instance,
307 int routing_id,
308 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44309 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26310 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42311 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07312 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37313 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57314 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44315 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05316 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34317 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23318 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
319 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34320 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21321 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56322 upload_size_(0),
323 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47324 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57325 capturing_contents_(false),
326 is_being_destroyed_(false),
327 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55328 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57329#if defined(OS_WIN)
330 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
331#endif
[email protected]7ab1e7d62009-10-14 23:32:01332 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56333 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38334 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25335 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01336 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25337 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01338 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00339 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43340 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20341 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37342 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32343
[email protected]38b098f2012-03-14 21:11:57344 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57345 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
346 if (view_.get()) {
347 CHECK(render_view_host_delegate_view_);
348 } else {
[email protected]38b098f2012-03-14 21:11:57349 content::WebContentsViewDelegate* delegate =
350 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
351 this);
[email protected]5a3bdf52012-05-24 15:12:57352 view_.reset(CreateWebContentsView(
353 this, delegate, &render_view_host_delegate_view_));
354 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57355 }
356 CHECK(view_.get());
357
[email protected]ca13a442012-04-17 14:00:12358 // We have the initial size of the view be based on the size of the view of
359 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26360 view_->CreateView(base_web_contents ?
361 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00362
[email protected]14392a52012-05-02 20:28:44363 // Listen for whether our opener gets destroyed.
364 if (opener_) {
365 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
366 content::Source<WebContents>(opener_));
367 }
368
[email protected]bafe6cd2012-05-23 23:09:50369 registrar_.Add(this,
370 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
371 content::NotificationService::AllBrowserContextsAndSources());
372
[email protected]483623eb2011-10-25 09:30:00373#if defined(ENABLE_JAVA_BRIDGE)
374 java_bridge_dispatcher_host_manager_.reset(
375 new JavaBridgeDispatcherHostManager(this));
376#endif
[email protected]172cf712012-05-23 15:07:39377
[email protected]cb25aa12012-08-07 19:13:43378 browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35379}
initial.commit09911bf2008-07-26 23:55:29380
[email protected]b172aee2012-04-10 17:05:26381WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32382 is_being_destroyed_ = true;
383
[email protected]3ab9cb82011-06-03 18:02:07384 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55385 if (dialog_creator_)
386 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07387
[email protected]da8543762012-03-20 08:52:20388 if (color_chooser_)
389 color_chooser_->End();
390
[email protected]420ae012009-04-24 05:16:32391 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32392
[email protected]ca13a442012-04-17 14:00:12393 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07394 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09395 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
396 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07397 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32398
399 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07400#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32401 // If we still have a window handle, destroy it. GetNativeView can return
402 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42403 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52404 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58405 if (host && host->GetView())
406 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42407 }
[email protected]420ae012009-04-24 05:16:32408#endif
[email protected]7ab1e7d62009-10-14 23:32:01409
410 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15411 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01412 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15413 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01414 }
[email protected]b5a1d11c2011-02-17 03:09:42415
[email protected]2db9bd72012-04-13 20:20:56416 FOR_EACH_OBSERVER(WebContentsObserver,
417 observers_,
418 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08419
[email protected]6934a702011-12-20 00:04:51420 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42421}
422
[email protected]b172aee2012-04-10 17:05:26423WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
424 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54425 WebPreferences prefs;
426
427 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
428
429 prefs.developer_extras_enabled = true;
430 prefs.javascript_enabled =
431 !command_line.HasSwitch(switches::kDisableJavaScript);
432 prefs.web_security_enabled =
433 !command_line.HasSwitch(switches::kDisableWebSecurity);
434 prefs.plugins_enabled =
435 !command_line.HasSwitch(switches::kDisablePlugins);
436 prefs.java_enabled =
437 !command_line.HasSwitch(switches::kDisableJava);
438
439 prefs.uses_page_cache =
440 command_line.HasSwitch(switches::kEnableFastback);
441 prefs.remote_fonts_enabled =
442 !command_line.HasSwitch(switches::kDisableRemoteFonts);
443 prefs.xss_auditor_enabled =
444 !command_line.HasSwitch(switches::kDisableXSSAuditor);
445 prefs.application_cache_enabled =
446 !command_line.HasSwitch(switches::kDisableApplicationCache);
447
448 prefs.local_storage_enabled =
449 !command_line.HasSwitch(switches::kDisableLocalStorage);
450 prefs.databases_enabled =
451 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01452#if defined(OS_ANDROID)
453 prefs.webaudio_enabled =
454 command_line.HasSwitch(switches::kEnableWebAudio);
455#else
[email protected]64d69de42012-02-06 00:19:54456 prefs.webaudio_enabled =
457 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01458#endif
[email protected]64d69de42012-02-06 00:19:54459
460 prefs.experimental_webgl_enabled =
461 GpuProcessHost::gpu_enabled() &&
462 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07463#if defined(OS_ANDROID)
464 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
465#else
[email protected]64d69de42012-02-06 00:19:54466 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07467#endif
[email protected]64d69de42012-02-06 00:19:54468
[email protected]5a073092012-06-08 00:42:51469 prefs.flash_3d_enabled =
470 GpuProcessHost::gpu_enabled() &&
471 !command_line.HasSwitch(switches::kDisableFlash3d);
472 prefs.flash_stage3d_enabled =
473 GpuProcessHost::gpu_enabled() &&
474 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19475
[email protected]64d69de42012-02-06 00:19:54476 prefs.gl_multisampling_enabled =
477 !command_line.HasSwitch(switches::kDisableGLMultisampling);
478 prefs.privileged_webgl_extensions_enabled =
479 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
480 prefs.site_specific_quirks_enabled =
481 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
482 prefs.allow_file_access_from_file_urls =
483 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
484 prefs.show_composited_layer_borders =
485 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
486 prefs.show_composited_layer_tree =
487 command_line.HasSwitch(switches::kShowCompositedLayerTree);
488 prefs.show_fps_counter =
489 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19490 prefs.show_paint_rects =
491 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52492 prefs.render_vsync_enabled =
493 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54494 prefs.accelerated_compositing_enabled =
495 GpuProcessHost::gpu_enabled() &&
496 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54497 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23498 command_line.HasSwitch(switches::kForceCompositingMode) &&
499 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54500 prefs.fixed_position_compositing_enabled =
501 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
502 prefs.accelerated_2d_canvas_enabled =
503 GpuProcessHost::gpu_enabled() &&
504 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58505 prefs.deferred_2d_canvas_enabled =
[email protected]7aca2362012-07-10 20:17:08506 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54507 prefs.accelerated_painting_enabled =
508 GpuProcessHost::gpu_enabled() &&
509 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
510 prefs.accelerated_filters_enabled =
511 GpuProcessHost::gpu_enabled() &&
512 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
513 prefs.accelerated_layers_enabled =
514 prefs.accelerated_animation_enabled =
515 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54516 prefs.accelerated_plugins_enabled =
517 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
518 prefs.accelerated_video_enabled =
519 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54520 prefs.fullscreen_enabled =
521 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16522 prefs.css_regions_enabled =
523 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29524 prefs.css_shaders_enabled =
525 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01526 prefs.css_variables_enabled =
527 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56528 prefs.device_supports_touch =
529 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]d849b122012-07-18 07:35:26530#if defined(OS_ANDROID)
531 prefs.device_supports_mouse = false;
532#endif
[email protected]64d69de42012-02-06 00:19:54533
534#if defined(OS_MACOSX)
535 bool default_enable_scroll_animator = true;
536#else
537 // On CrOS, the launcher always passes in the --enable flag.
538 bool default_enable_scroll_animator = false;
539#endif
540 prefs.enable_scroll_animator = default_enable_scroll_animator;
541 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
542 prefs.enable_scroll_animator = true;
543 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
544 prefs.enable_scroll_animator = false;
545
546 prefs.visual_word_movement_enabled =
547 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54548
549 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32550 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54551 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11552 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
553 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54554 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11555 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54556 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19557 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
558 prefs.flash_3d_enabled = false;
559 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
560 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11561 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54562 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11563 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54564 prefs.gl_multisampling_enabled = false;
565
566 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45567 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32568 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54569 prefs.accelerated_video_enabled = false;
570 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45571 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09572 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54573 }
574 }
575
[email protected]b9535422012-02-09 01:47:59576 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58577 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54578 prefs.loads_images_automatically = true;
579 prefs.javascript_enabled = true;
580 }
581
582 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
583
584 // Force accelerated compositing and 2d canvas off for chrome:, about: and
585 // chrome-devtools: pages (unless it's specifically allowed).
586 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54587 url.SchemeIs(chrome::kChromeUIScheme) ||
588 (url.SchemeIs(chrome::kAboutScheme) &&
589 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25590 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54591 prefs.accelerated_compositing_enabled = false;
592 prefs.accelerated_2d_canvas_enabled = false;
593 }
[email protected]43d9d782012-03-01 15:40:09594
[email protected]302fe422012-06-11 14:49:11595#if !defined(WEBCOMPOSITOR_OWNS_SETTINGS)
596 prefs.threaded_animation_enabled =
597 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
598 prefs.per_tile_painting_enabled =
599 command_line.HasSwitch(switches::kEnablePerTilePainting);
600 prefs.partial_swap_enabled =
601 command_line.HasSwitch(switches::kEnablePartialSwap);
602#endif
603
[email protected]f98f5092012-05-19 00:08:14604 if (command_line.HasSwitch(switches::kDefaultTileWidth))
605 prefs.default_tile_width =
606 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
607 if (command_line.HasSwitch(switches::kDefaultTileHeight))
608 prefs.default_tile_height =
609 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
610 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
611 prefs.max_untiled_layer_width =
612 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
613 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
614 prefs.max_untiled_layer_height =
615 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
616
[email protected]2486dce2012-05-23 17:18:19617 if (gfx::Screen::IsDIPEnabled()) {
618 // Only apply when using DIP coordinate system as this setting interferes
619 // with fixed layout mode.
620 prefs.apply_default_device_scale_factor_in_compositor = true;
621 }
622
[email protected]de023762012-07-26 17:10:17623 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
624 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10625
[email protected]6b4dcb072012-06-18 22:26:51626 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
627
[email protected]2e21fe292012-03-02 22:52:32628 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54629
630 return prefs;
631}
632
[email protected]b172aee2012-04-10 17:05:26633NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20634 return controller_;
635}
636
[email protected]b172aee2012-04-10 17:05:26637RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28638 return &render_manager_;
639}
640
[email protected]7bb761892012-07-20 09:32:47641bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
642 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56643 if (GetWebUI() &&
644 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17645 return true;
[email protected]d2353452012-01-19 19:53:56646 }
[email protected]f82d57b52011-04-27 19:13:17647
[email protected]d8c660432011-12-22 20:51:25648 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
649 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10650 while ((observer = it.GetNext()) != NULL)
651 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53652 return true;
[email protected]403415a2011-01-10 18:57:53653
[email protected]7bb761892012-07-20 09:32:47654 // Message handlers should be aware of which RenderViewHost sent the
655 // message, which is temporarily stored in message_source_.
656 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18657 bool handled = true;
658 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26659 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58660 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
661 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24662 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
663 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18664 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
665 OnDidLoadResourceFromMemoryCache)
666 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
667 OnDidDisplayInsecureContent)
668 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
669 OnDidRunInsecureContent)
670 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
671 OnDocumentLoadedInFrame)
672 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26673 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
674 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17675 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
676 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25677 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26678 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59679 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21680 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20681 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
682 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
683 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16684 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45685 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10686 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20687 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
690 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29691 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50692 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18693 IPC_MESSAGE_UNHANDLED(handled = false)
694 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47695 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18696
697 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38698 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18699 GetRenderProcessHost()->ReceivedBadMessage();
700 }
701
702 return handled;
703}
704
[email protected]b172aee2012-04-10 17:05:26705void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18706 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23707 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43708 if (delegate_)
709 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18710}
711
[email protected]b172aee2012-04-10 17:05:26712NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56713 return controller_;
714}
715
[email protected]b172aee2012-04-10 17:05:26716const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56717 return controller_;
718}
719
[email protected]b172aee2012-04-10 17:05:26720content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55721 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30722}
723
[email protected]b172aee2012-04-10 17:05:26724const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31725 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23726 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51727 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31728}
729
730
[email protected]b172aee2012-04-10 17:05:26731const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31732 return &property_bag_;
733}
734
[email protected]b172aee2012-04-10 17:05:26735base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31736 return &property_bag_;
737}
738
[email protected]b172aee2012-04-10 17:05:26739content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31740 return delegate_;
741}
742
[email protected]b172aee2012-04-10 17:05:26743void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31744 // TODO(cbentzel): remove this debugging code?
745 if (delegate == delegate_)
746 return;
747 if (delegate_)
748 delegate_->Detach(this);
749 delegate_ = delegate;
750 if (delegate_)
751 delegate_->Attach(this);
752}
753
[email protected]b172aee2012-04-10 17:05:26754content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41755 RenderViewHostImpl* host = render_manager_.current_host();
756 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16757}
758
[email protected]b172aee2012-04-10 17:05:26759RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31760 return render_manager_.current_host();
761}
762
[email protected]b172aee2012-04-10 17:05:26763RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31764 return render_manager_.GetRenderWidgetHostView();
765}
766
[email protected]b172aee2012-04-10 17:05:26767content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31768 return view_.get();
769}
770
[email protected]b172aee2012-04-10 17:05:26771content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50772 WebUIControllerFactory* factory =
773 content::GetContentClient()->browser()->GetWebUIControllerFactory();
774 if (!factory)
775 return NULL;
[email protected]d2353452012-01-19 19:53:56776 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22777 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50778 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22779 if (controller) {
780 web_ui->SetController(controller);
781 return web_ui;
782 }
783
784 delete web_ui;
785 return NULL;
786}
787
[email protected]b172aee2012-04-10 17:05:26788content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31789 return render_manager_.web_ui() ? render_manager_.web_ui()
790 : render_manager_.pending_web_ui();
791}
792
[email protected]b172aee2012-04-10 17:05:26793content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31794 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34795}
796
[email protected]86ef6a392012-05-11 22:03:11797void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22798 if (GetUserAgentOverride() == override)
799 return;
800
801 renderer_preferences_.user_agent_override = override;
802
803 // Send the new override string to the renderer.
804 RenderViewHost* host = GetRenderViewHost();
805 if (host)
806 host->SyncRendererPrefs();
807
808 // Reload the page if a load is currently in progress to avoid having
809 // different parts of the page loaded using different user agents.
810 NavigationEntry* entry = controller_.GetActiveEntry();
811 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
812 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11813}
814
815const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22816 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11817}
818
[email protected]b172aee2012-04-10 17:05:26819const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55820 // Transient entries take precedence. They are used for interstitial pages
821 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23822 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08823 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20824 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30825 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23826 if (entry) {
[email protected]b5cca982011-05-26 04:42:08827 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23828 }
[email protected]7ade2732011-02-10 00:13:58829 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
830 render_manager_.pending_web_ui() : render_manager_.web_ui();
831 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54832 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55833 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54834 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35835 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22836 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54837 if (!title.empty())
838 return title;
839 }
840 }
841
842 // We use the title for the last committed entry rather than a pending
843 // navigation entry. For example, when the user types in a URL, we want to
844 // keep the old page's title until the new load has committed and we get a new
845 // title.
[email protected]96d185d2009-04-24 03:28:54846 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23847 if (entry) {
[email protected]b5cca982011-05-26 04:42:08848 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23849 }
[email protected]987fc3a2011-05-26 14:18:09850
851 // |page_title_when_no_navigation_entry_| is finally used
852 // if no title cannot be retrieved.
853 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54854}
855
[email protected]b172aee2012-04-10 17:05:26856int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46857 return GetMaxPageIDForSiteInstance(GetSiteInstance());
858}
859
[email protected]b172aee2012-04-10 17:05:26860int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
861 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33862 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
863 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46864
[email protected]b6583592012-01-25 19:52:33865 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34866}
867
[email protected]b172aee2012-04-10 17:05:26868void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46869 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
870}
871
[email protected]b172aee2012-04-10 17:05:26872void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33873 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46874 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33875 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34876}
877
[email protected]b172aee2012-04-10 17:05:26878void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
879 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57880}
881
[email protected]b172aee2012-04-10 17:05:26882SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58883 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54884}
885
[email protected]b172aee2012-04-10 17:05:26886SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38887 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
888 render_manager_.pending_render_view_host() :
889 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58890 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38891}
892
[email protected]b172aee2012-04-10 17:05:26893bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49895}
896
[email protected]b172aee2012-04-10 17:05:26897bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return waiting_for_response_;
899}
900
[email protected]b172aee2012-04-10 17:05:26901const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return load_state_;
903}
904
[email protected]b172aee2012-04-10 17:05:26905const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return load_state_host_;
907}
908
[email protected]b172aee2012-04-10 17:05:26909uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31910 return upload_size_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return upload_position_;
915}
916
[email protected]b172aee2012-04-10 17:05:26917const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return encoding_;
919}
920
[email protected]b172aee2012-04-10 17:05:26921bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31922 return displayed_insecure_content_;
923}
924
[email protected]b172aee2012-04-10 17:05:26925void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31926 capturing_contents_ = cap;
927}
928
[email protected]b172aee2012-04-10 17:05:26929bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
931 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
932 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49933}
934
[email protected]b172aee2012-04-10 17:05:26935void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
936 int error_code) {
[email protected]443b80e2010-12-14 00:42:23937 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34938 return;
939
[email protected]443b80e2010-12-14 00:42:23940 crashed_status_ = status;
941 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46942 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34943}
944
[email protected]b172aee2012-04-10 17:05:26945base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31946 return crashed_status_;
947}
948
[email protected]b172aee2012-04-10 17:05:26949bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31950 return is_being_destroyed_;
951}
952
[email protected]b172aee2012-04-10 17:05:26953void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34954 if (delegate_)
955 delegate_->NavigationStateChanged(this, changed_flags);
956}
957
[email protected]3e324142012-06-25 18:26:33958base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
959 return last_selected_time_;
960}
961
[email protected]9e2e4632012-07-27 16:38:41962void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54963 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04964 RenderWidgetHostViewPort* rwhv =
965 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16966 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41967 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43968#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16969 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43970#endif
971 }
[email protected]96d185d2009-04-24 03:28:54972
[email protected]5ac20162010-11-24 23:33:11973 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38974
[email protected]9e2e4632012-07-27 16:38:41975 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59976
977 // The resize rect might have changed while this was inactive -- send the new
978 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58979 RenderViewHostImpl* rvh =
980 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59981 if (rvh) {
982 rvh->ResizeRectChanged(GetRootWindowResizerRect());
983 }
[email protected]96d185d2009-04-24 03:28:54984
[email protected]3e324142012-06-25 18:26:33985 bool is_visible = true;
986 content::NotificationService::current()->Notify(
987 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
988 content::Source<WebContents>(this),
989 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31990}
991
[email protected]b172aee2012-04-10 17:05:26992void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31993 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52994 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
995 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26996 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52997 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33998 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52999 // calls us).
[email protected]c30585c2012-02-16 15:02:041000 RenderWidgetHostViewPort* rwhv =
1001 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161002 if (rwhv)
1003 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541004 }
1005
[email protected]375fa1b2012-05-22 22:05:371006 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071007 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371008 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091009 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371010 content::Details<bool>(&is_visible));
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311014 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271015 return WillNotifyDisconnection() &&
1016 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581017 !static_cast<RenderViewHostImpl*>(
1018 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311019}
1020
[email protected]b172aee2012-04-10 17:05:261021void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271022 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251023 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271024}
1025
[email protected]b172aee2012-04-10 17:05:261026WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441027 // We use our current SiteInstance since the cloned entry will use it anyway.
1028 // We pass |this| for the |base_web_contents| to size the view correctly, and
1029 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:261030 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:441031 GetBrowserContext(), GetSiteInstance(),
1032 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:201033 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271034 return tc;
1035}
1036
[email protected]b172aee2012-04-10 17:05:261037void WebContentsImpl::AddNewContents(WebContents* new_contents,
1038 WindowOpenDisposition disposition,
1039 const gfx::Rect& initial_pos,
1040 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271041 if (!delegate_)
1042 return;
1043
1044 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1045 user_gesture);
1046}
1047
[email protected]b172aee2012-04-10 17:05:261048gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271049 return view_->GetContentNativeView();
1050}
1051
[email protected]b172aee2012-04-10 17:05:261052gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271053 return view_->GetNativeView();
1054}
1055
[email protected]b172aee2012-04-10 17:05:261056void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271057 view_->GetContainerBounds(out);
1058}
1059
[email protected]b172aee2012-04-10 17:05:261060void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271061 view_->Focus();
1062}
1063
[email protected]14392a52012-05-02 20:28:441064void WebContentsImpl::Observe(int type,
1065 const content::NotificationSource& source,
1066 const content::NotificationDetails& details) {
1067 switch (type) {
1068 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1069 OnWebContentsDestroyed(
1070 content::Source<content::WebContents>(source).ptr());
1071 break;
[email protected]bafe6cd2012-05-23 23:09:501072 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1073 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1074 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1075 i != pending_widget_views_.end(); ++i) {
1076 if (host->GetView() == i->second) {
1077 pending_widget_views_.erase(i);
1078 break;
1079 }
1080 }
1081 break;
1082 }
[email protected]14392a52012-05-02 20:28:441083 default:
1084 NOTREACHED();
1085 }
1086}
1087
1088void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1089 // Clear the opener if it has been closed.
1090 if (web_contents == opener_) {
1091 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1092 content::Source<WebContents>(opener_));
1093 opener_ = NULL;
1094 }
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311098 observers_.AddObserver(observer);
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311102 observers_.RemoveObserver(observer);
1103}
1104
[email protected]b172aee2012-04-10 17:05:261105void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341106 if (delegate_)
1107 delegate_->ActivateContents(this);
1108}
1109
[email protected]b172aee2012-04-10 17:05:261110void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121111 if (delegate_)
1112 delegate_->DeactivateContents(this);
1113}
1114
[email protected]b172aee2012-04-10 17:05:261115void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481116 if (delegate_)
1117 delegate_->LostCapture();
1118}
1119
[email protected]b172aee2012-04-10 17:05:261120bool WebContentsImpl::PreHandleKeyboardEvent(
1121 const NativeWebKeyboardEvent& event,
1122 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481123 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131124 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481125}
1126
[email protected]b172aee2012-04-10 17:05:261127void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481128 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131129 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481130}
1131
[email protected]b172aee2012-04-10 17:05:261132void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431133 if (delegate_)
1134 delegate_->HandleMouseDown();
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481138 if (delegate_)
1139 delegate_->HandleMouseUp();
1140}
1141
[email protected]590a634e2012-07-19 16:38:231142void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481143 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231144 delegate_->HandlePointerActivate();
1145}
1146
1147void WebContentsImpl::HandleGestureBegin() {
1148 if (delegate_)
1149 delegate_->HandleGestureBegin();
1150}
1151
1152void WebContentsImpl::HandleGestureEnd() {
1153 if (delegate_)
1154 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481155}
1156
[email protected]b172aee2012-04-10 17:05:261157void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471158 if (delegate_)
1159 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1160}
1161
[email protected]b172aee2012-04-10 17:05:261162bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381163 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121164}
1165
[email protected]a9c81f02012-06-01 00:15:441166void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1167 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371168 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441169 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371170 } else {
1171 GotResponseToLockMouseRequest(false);
1172 }
1173}
1174
[email protected]b172aee2012-04-10 17:05:261175void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371176 if (delegate_)
1177 delegate_->LostMouseLock();
1178}
1179
[email protected]bafe6cd2012-05-23 23:09:501180void WebContentsImpl::CreateNewWindow(
1181 int route_id,
[email protected]97714c82012-06-06 10:15:131182 const ViewHostMsg_CreateWindow_Params& params,
1183 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501184 if (delegate_ && !delegate_->ShouldCreateWebContents(
1185 this, route_id, params.window_container_type, params.frame_name,
1186 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091187 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501188 return;
1189 }
1190
1191 // We usually create the new window in the same BrowsingInstance (group of
1192 // script-related windows), by passing in the current SiteInstance. However,
1193 // if the opener is being suppressed, we create a new SiteInstance in its own
1194 // BrowsingInstance.
1195 scoped_refptr<SiteInstance> site_instance =
1196 params.opener_suppressed ?
1197 SiteInstance::Create(GetBrowserContext()) :
1198 GetSiteInstance();
1199
1200 // Create the new web contents. This will automatically create the new
1201 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131202 WebContentsImpl* new_contents = new WebContentsImpl(
1203 GetBrowserContext(),
[email protected]b441a8492012-06-06 14:55:571204 site_instance,
1205 route_id,
1206 this,
1207 params.opener_suppressed ? NULL : this,
[email protected]97714c82012-06-06 10:15:131208 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501209 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1210
1211 if (!params.opener_suppressed) {
1212 content::WebContentsView* new_view = new_contents->GetView();
1213
1214 // TODO(brettw): It seems bogus that we have to call this function on the
1215 // newly created object and give it one of its own member variables.
1216 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1217
1218 // Save the created window associated with the route so we can show it
1219 // later.
1220 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1221 pending_contents_[route_id] = new_contents;
1222 }
1223
1224 if (delegate_) {
1225 delegate_->WebContentsCreated(
1226 this, params.opener_frame_id, params.target_url, new_contents);
1227 }
1228
1229 if (params.opener_suppressed) {
1230 // When the opener is suppressed, the original renderer cannot access the
1231 // new window. As a result, we need to show and navigate the window here.
1232 gfx::Rect initial_pos;
1233 AddNewContents(
1234 new_contents, params.disposition, initial_pos, params.user_gesture);
1235
1236 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1237 CURRENT_TAB,
1238 content::PAGE_TRANSITION_LINK,
1239 true /* is_renderer_initiated */);
1240 new_contents->OpenURL(open_params);
1241 }
1242}
1243
1244void WebContentsImpl::CreateNewWidget(int route_id,
1245 WebKit::WebPopupType popup_type) {
1246 CreateNewWidget(route_id, false, popup_type);
1247}
1248
1249void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1250 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1251}
1252
1253void WebContentsImpl::CreateNewWidget(int route_id,
1254 bool is_fullscreen,
1255 WebKit::WebPopupType popup_type) {
1256 content::RenderProcessHost* process = GetRenderProcessHost();
1257 RenderWidgetHostImpl* widget_host =
1258 new RenderWidgetHostImpl(this, process, route_id);
1259 RenderWidgetHostViewPort* widget_view =
1260 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1261 if (!is_fullscreen) {
1262 // Popups should not get activated.
1263 widget_view->SetPopupType(popup_type);
1264 }
1265 // Save the created widget associated with the route so we can show it later.
1266 pending_widget_views_[route_id] = widget_view;
1267
1268#if defined(OS_MACOSX)
1269 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1270 // to allow it to survive the trip without being hosted.
1271 base::mac::NSObjectRetain(widget_view->GetNativeView());
1272#endif
1273}
1274
1275void WebContentsImpl::ShowCreatedWindow(int route_id,
1276 WindowOpenDisposition disposition,
1277 const gfx::Rect& initial_pos,
1278 bool user_gesture) {
1279 WebContentsImpl* contents = GetCreatedWindow(route_id);
1280 if (contents)
1281 AddNewContents(contents, disposition, initial_pos, user_gesture);
1282}
1283
1284void WebContentsImpl::ShowCreatedWidget(int route_id,
1285 const gfx::Rect& initial_pos) {
1286 ShowCreatedWidget(route_id, false, initial_pos);
1287}
1288
1289void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1290 ShowCreatedWidget(route_id, true, gfx::Rect());
1291}
1292
1293void WebContentsImpl::ShowCreatedWidget(int route_id,
1294 bool is_fullscreen,
1295 const gfx::Rect& initial_pos) {
1296 if (delegate_)
1297 delegate_->RenderWidgetShowing();
1298
1299 RenderWidgetHostViewPort* widget_host_view =
1300 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1301 if (!widget_host_view)
1302 return;
1303 if (is_fullscreen) {
1304 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1305 } else {
1306 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1307 }
[email protected]89054502012-06-03 10:29:241308
1309 RenderWidgetHostImpl* render_widget_host_impl =
1310 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1311 render_widget_host_impl->Init();
1312 // Only allow privileged mouse lock for fullscreen render widget, which is
1313 // used to implement Pepper Flash fullscreen.
1314 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501315
1316#if defined(OS_MACOSX)
1317 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1318 // properly embedded (or purposefully ignored) we can release the retain we
1319 // took in CreateNewWidget().
1320 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1321#endif
1322}
1323
1324WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1325 PendingContents::iterator iter = pending_contents_.find(route_id);
1326
1327 // Certain systems can block the creation of new windows. If we didn't succeed
1328 // in creating one, just return NULL.
1329 if (iter == pending_contents_.end()) {
1330 return NULL;
1331 }
1332
1333 WebContentsImpl* new_contents = iter->second;
1334 pending_contents_.erase(route_id);
1335
1336 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1337 !new_contents->GetRenderViewHost()->GetView())
1338 return NULL;
1339
1340 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1341 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1342 return new_contents;
1343}
1344
1345RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1346 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1347 if (iter == pending_widget_views_.end()) {
1348 DCHECK(false);
1349 return NULL;
1350 }
1351
1352 RenderWidgetHostView* widget_host_view = iter->second;
1353 pending_widget_views_.erase(route_id);
1354
1355 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1356 if (!widget_host->GetProcess()->HasConnection()) {
1357 // The view has gone away or the renderer crashed. Nothing to do.
1358 return NULL;
1359 }
1360
1361 return widget_host_view;
1362}
1363
1364void WebContentsImpl::ShowContextMenu(
1365 const content::ContextMenuParams& params) {
1366 // Allow WebContentsDelegates to handle the context menu operation first.
1367 if (delegate_ && delegate_->HandleContextMenu(params))
1368 return;
1369
[email protected]5a3bdf52012-05-24 15:12:571370 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501371}
1372
[email protected]f13b4202012-06-12 23:53:231373void WebContentsImpl::RequestMediaAccessPermission(
1374 const content::MediaStreamRequest* request,
1375 const content::MediaResponseCallback& callback) {
1376 if (delegate_)
1377 delegate_->RequestMediaAccessPermission(this, request, callback);
1378 else
1379 callback.Run(content::MediaStreamDevices());
1380}
1381
[email protected]b172aee2012-04-10 17:05:261382void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231383 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331384 if (delegate_)
1385 delegate_->UpdatePreferredSize(this, pref_size);
1386}
1387
[email protected]b172aee2012-04-10 17:05:261388void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341389 if (delegate_)
1390 delegate_->ResizeDueToAutoResize(this, new_size);
1391}
1392
[email protected]b172aee2012-04-10 17:05:261393WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201394 if (!delegate_)
1395 return NULL;
[email protected]00c37fc2011-08-02 00:22:501396
[email protected]e5d549d2011-12-28 01:29:201397 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1398 // Notify observers.
1399 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1400 DidOpenURL(params.url, params.referrer,
1401 params.disposition, params.transition));
1402 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341403}
1404
[email protected]b172aee2012-04-10 17:05:261405bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501406 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251407 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231408 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251409 reload_type);
[email protected]876bc832010-09-07 16:29:541410}
[email protected]96d185d2009-04-24 03:28:541411
[email protected]ba45bfd2012-05-22 21:51:441412void WebContentsImpl::RenderViewForInterstitialPageCreated(
1413 content::RenderViewHost* render_view_host) {
1414 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1415 RenderViewForInterstitialPageCreated(render_view_host));
1416}
1417
[email protected]b172aee2012-04-10 17:05:261418bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231419 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501420 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401421 // The renderer will reject IPC messages with URLs longer than
1422 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511423 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401424 return false;
1425
[email protected]9f76c1e2012-03-05 15:15:581426 RenderViewHostImpl* dest_render_view_host =
1427 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401428 if (!dest_render_view_host)
1429 return false; // Unable to create the desired render view host.
1430
[email protected]80a8fad2011-01-29 04:02:381431 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071432 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581433 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501434 WebUIControllerFactory* factory =
1435 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271436 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501437 bool is_allowed_in_web_ui_renderer =
1438 factory &&
[email protected]24e18252012-04-16 21:26:271439 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1440 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231441 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1442 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271443 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231444 content::GetContentClient()->SetActiveURL(entry.GetURL());
1445 CHECK(0);
1446 }
[email protected]54ec6472010-04-09 19:39:581447
[email protected]96d185d2009-04-24 03:28:541448 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441449 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521450 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441451 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511452 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541453
[email protected]7bb761892012-07-20 09:32:471454 // Notify observers that we will navigate in this RV.
1455 FOR_EACH_OBSERVER(WebContentsObserver,
1456 observers_,
1457 AboutToNavigateRenderView(dest_render_view_host));
1458
[email protected]96d185d2009-04-24 03:28:541459 // Used for page load time metrics.
1460 current_load_start_ = base::TimeTicks::Now();
1461
1462 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241463 std::string embedder_channel_name;
1464 int embedder_container_id;
1465 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1466 &embedder_channel_name,
1467 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341468 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271469 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241470 embedder_channel_name,
1471 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471472 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341473 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541474
[email protected]36fc0392011-12-25 03:59:511475 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541476 // HACK!! This code suppresses javascript: URLs from being added to
1477 // session history, which is what we want to do for javascript: URLs that
1478 // do not generate content. What we really need is a message from the
1479 // renderer telling us that a new page was not created. The same message
1480 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511481 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541482 return false;
1483 }
1484
[email protected]3c9e1872010-11-18 16:17:491485 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251486 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041487 observers_,
[email protected]36fc0392011-12-25 03:59:511488 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541489
[email protected]09b29342011-06-24 19:18:481490 if (delegate_)
1491 delegate_->DidNavigateToPendingEntry(this);
1492
[email protected]d5f942ba2008-09-26 19:30:341493 return true;
1494}
1495
[email protected]b172aee2012-04-10 17:05:261496void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331497 const SiteInstance* site_instance,
1498 int history_length,
1499 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411500 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1501 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191502 if (render_manager_.pending_render_view_host()) {
1503 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141504 return;
[email protected]9e1ad4b2011-08-14 16:49:191505 }
[email protected]9f76c1e2012-03-05 15:15:581506 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191507 if (!rvh) {
1508 NOTREACHED();
1509 return;
1510 }
[email protected]9f76c1e2012-03-05 15:15:581511 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191512 NOTREACHED();
1513 return;
1514 }
[email protected]9f76c1e2012-03-05 15:15:581515 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191516 history_length,
1517 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141518}
1519
[email protected]b172aee2012-04-10 17:05:261520void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271521 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541522 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1523 return;
1524 }
[email protected]9f76c1e2012-03-05 15:15:581525 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541526}
1527
[email protected]b172aee2012-04-10 17:05:261528bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271529 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541530}
1531
[email protected]b172aee2012-04-10 17:05:261532InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271533 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221534}
1535
[email protected]b172aee2012-04-10 17:05:261536bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161537 // WebKit creates Document object when MIME type is application/xhtml+xml,
1538 // so we also support this MIME type.
1539 return contents_mime_type_ == "text/html" ||
1540 contents_mime_type_ == "text/xml" ||
1541 contents_mime_type_ == "application/xhtml+xml" ||
1542 contents_mime_type_ == "text/plain" ||
1543 contents_mime_type_ == "text/css" ||
1544 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1545}
1546
[email protected]b172aee2012-04-10 17:05:261547void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591548 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161549 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481550 download_stats::RecordDownloadSource(
1551 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461552 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141553 return;
[email protected]c7dd2f62011-07-18 15:57:591554 }
1555
1556 Stop();
1557
1558 // Create the save package and possibly prompt the user for the name to save
1559 // the page as. The user prompt is an asynchronous operation that runs on
1560 // another thread.
1561 save_package_ = new SavePackage(this);
1562 save_package_->GetSaveInfo();
1563}
1564
1565// Used in automated testing to bypass prompting the user for file names.
1566// Instead, the names and paths are hard coded rather than running them through
1567// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261568bool WebContentsImpl::SavePage(const FilePath& main_file,
1569 const FilePath& dir_path,
1570 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591571 // Stop the page from navigating.
1572 Stop();
1573
1574 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271575 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591576}
1577
[email protected]b172aee2012-04-10 17:05:261578void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121579 const FilePath& file,
1580 const base::Callback<void(const FilePath&, int64)>& callback) {
1581 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1582}
1583
[email protected]b172aee2012-04-10 17:05:261584bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231585 NavigationEntryImpl* active_entry =
1586 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321587 return (active_entry != NULL &&
1588 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511589 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321590}
1591
[email protected]b172aee2012-04-10 17:05:261592const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271593 return contents_mime_type_;
1594}
1595
[email protected]b172aee2012-04-10 17:05:261596bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271597 return notify_disconnection_;
1598}
1599
[email protected]b172aee2012-04-10 17:05:261600void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311601 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581602 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1603 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161604}
1605
[email protected]b172aee2012-04-10 17:05:261606void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311607 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581608 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1609 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161610}
1611
[email protected]b172aee2012-04-10 17:05:261612content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271613 return &renderer_preferences_;
1614}
1615
[email protected]b172aee2012-04-10 17:05:261616void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271617 new_tab_start_time_ = time;
1618}
1619
[email protected]b172aee2012-04-10 17:05:261620base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271621 return new_tab_start_time_;
1622}
1623
[email protected]e35ccd52012-05-23 16:22:471624void WebContentsImpl::Close() {
1625 Close(GetRenderViewHost());
1626}
1627
[email protected]b172aee2012-04-10 17:05:261628void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151629 if (close_start_time_.is_null())
1630 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011631}
1632
[email protected]b172aee2012-04-10 17:05:261633bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191634#if defined(OS_CHROMEOS)
1635 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1636 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511637 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201638 return false;
1639 return true;
[email protected]46624bf2010-06-09 16:04:191640#else
1641 return true;
1642#endif
1643}
1644
[email protected]b172aee2012-04-10 17:05:261645void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521646 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581647 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511648 if (delegate_)
1649 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341650}
1651
[email protected]e35ccd52012-05-23 16:22:471652void WebContentsImpl::UserGestureDone() {
1653 OnUserGesture();
1654}
1655
[email protected]b172aee2012-04-10 17:05:261656void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271657 closed_by_user_gesture_ = value;
1658}
1659
[email protected]b172aee2012-04-10 17:05:261660bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271661 return closed_by_user_gesture_;
1662}
1663
[email protected]b172aee2012-04-10 17:05:261664double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051665 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561666 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251667 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171668 return 0;
[email protected]b75b8292010-10-01 07:28:251669
1670 double zoom_level;
1671 if (temporary_zoom_settings_) {
1672 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581673 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251674 } else {
[email protected]2ae88d12011-10-14 09:11:191675 GURL url;
[email protected]10f417c52011-12-28 21:04:231676 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191677 // Since zoom map is updated using rewritten URL, use rewritten URL
1678 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511679 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191680 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251681 }
[email protected]d0b8d092010-10-25 04:05:171682 return zoom_level;
1683}
[email protected]b75b8292010-10-01 07:28:251684
[email protected]b172aee2012-04-10 17:05:261685int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1686 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171687 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011688 // Calculate the zoom percent from the factor. Round up to the nearest whole
1689 // number.
[email protected]b75b8292010-10-01 07:28:251690 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011691 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251692 *enable_decrement = percent > minimum_zoom_percent_;
1693 *enable_increment = percent < maximum_zoom_percent_;
1694 return percent;
1695}
1696
[email protected]b172aee2012-04-10 17:05:261697void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501698 if (!delegate_)
1699 return;
1700
[email protected]10f417c52011-12-28 21:04:231701 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501702 if (!active_entry)
1703 return;
1704
[email protected]36fc0392011-12-25 03:59:511705 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121706}
1707
[email protected]b172aee2012-04-10 17:05:261708void WebContentsImpl::ViewFrameSource(const GURL& url,
1709 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271710 if (!delegate_)
1711 return;
1712
1713 delegate_->ViewSourceForFrame(this, url, content_state);
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271717 return minimum_zoom_percent_;
1718}
1719
[email protected]b172aee2012-04-10 17:05:261720int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271721 return maximum_zoom_percent_;
1722}
1723
[email protected]b172aee2012-04-10 17:05:261724gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231725 return preferred_size_;
1726}
1727
[email protected]b172aee2012-04-10 17:05:261728int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271729 return content_restrictions_;
1730}
1731
[email protected]b172aee2012-04-10 17:05:261732WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501733 WebUIControllerFactory* factory =
1734 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1735 if (!factory)
1736 return WebUI::kNoWebUI;
1737 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271738}
1739
[email protected]b172aee2012-04-10 17:05:261740content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271741 // When there is a pending navigation entry, we want to use the pending WebUI
1742 // that goes along with it to control the basic flags. For example, we want to
1743 // show the pending URL in the URL bar, so we want the display_url flag to
1744 // be from the pending entry.
1745 //
1746 // The confusion comes because there are multiple possibilities for the
1747 // initial load in a tab as a side effect of the way the RenderViewHostManager
1748 // works.
1749 //
1750 // - For the very first tab the load looks "normal". The new tab Web UI is
1751 // the pending one, and we want it to apply here.
1752 //
1753 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1754 // get switched to the one previously associated with the new tab pages.
1755 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1756 // have a committed Web UI in this case.
1757 //
1758 // This condition handles all of these cases:
1759 //
1760 // - First load in first tab: no committed nav entry + pending nav entry +
1761 // pending dom ui:
1762 // -> Use pending Web UI if any.
1763 //
1764 // - First load in second tab: no committed nav entry + pending nav entry +
1765 // no pending Web UI:
1766 // -> Use the committed Web UI if any.
1767 //
1768 // - Second navigation in any tab: committed nav entry + pending nav entry:
1769 // -> Use pending Web UI if any.
1770 //
1771 // - Normal state with no load: committed nav entry + no pending nav entry:
1772 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251773 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271774 (controller_.GetLastCommittedEntry() ||
1775 render_manager_.pending_web_ui()))
1776 return render_manager_.pending_web_ui();
1777 return render_manager_.web_ui();
1778}
1779
[email protected]b172aee2012-04-10 17:05:261780bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271781 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581782 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271783}
1784
[email protected]b172aee2012-04-10 17:05:261785bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441786 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501787}
1788
[email protected]b172aee2012-04-10 17:05:261789void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321790 SkColor color) {
[email protected]da8543762012-03-20 08:52:201791 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1792 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1793}
1794
[email protected]b172aee2012-04-10 17:05:261795void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201796 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1797 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1798 if (delegate_)
1799 delegate_->DidEndColorChooser();
1800 color_chooser_ = NULL;
1801}
1802
[email protected]b172aee2012-04-10 17:05:261803bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471804 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271805 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221806 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231807 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411808 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271809}
1810
[email protected]b172aee2012-04-10 17:05:261811void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271812 if (delegate_)
1813 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211814}
1815
[email protected]3a3b75a2012-06-01 08:38:361816void WebContentsImpl::OnRegisterIntentService(
1817 const webkit_glue::WebIntentServiceData& data,
1818 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431819 if (delegate_)
1820 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301821}
1822
[email protected]b172aee2012-04-10 17:05:261823void WebContentsImpl::OnWebIntentDispatch(
1824 const webkit_glue::WebIntentData& intent,
1825 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431826 if (!delegate_)
1827 return;
1828
[email protected]0d9989d2011-12-21 20:26:001829 WebIntentsDispatcherImpl* intents_dispatcher =
1830 new WebIntentsDispatcherImpl(this, intent, intent_id);
1831 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301832}
1833
[email protected]54047eb52012-05-08 21:45:571834void WebContentsImpl::DidStartProvisionalLoadForFrame(
1835 content::RenderViewHost* render_view_host,
1836 int64 frame_id,
1837 bool is_main_frame,
1838 const GURL& opener_url,
1839 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281840 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181841 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451842 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571843 content::RenderProcessHost* render_process_host =
1844 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541845 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571846 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451847 false,
[email protected]9f76c1e2012-03-05 15:15:581848 &validated_url);
[email protected]ef108e72012-06-20 14:03:541849 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571850 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451851 true,
1852 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181853
[email protected]0d60f0192011-04-14 12:40:101854 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251855 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101856 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571857 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541858
1859 if (is_main_frame) {
1860 // Notify observers about the provisional change in the main frame URL.
1861 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1862 ProvisionalChangeToMainFrameUrl(validated_url,
1863 validated_opener_url,
1864 render_view_host));
1865 }
1866}
1867
1868void WebContentsImpl::DidRedirectProvisionalLoad(
1869 content::RenderViewHost* render_view_host,
1870 int32 page_id,
1871 const GURL& opener_url,
1872 const GURL& source_url,
1873 const GURL& target_url) {
1874 // TODO(creis): Remove this method and have the pre-rendering code listen to
1875 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1876 // instead. See http://crbug.com/78512.
1877 GURL validated_source_url(source_url);
1878 GURL validated_target_url(target_url);
1879 GURL validated_opener_url(opener_url);
1880 content::RenderProcessHost* render_process_host =
1881 render_view_host->GetProcess();
1882 RenderViewHostImpl::FilterURL(
1883 ChildProcessSecurityPolicyImpl::GetInstance(),
1884 render_process_host->GetID(),
1885 false,
1886 &validated_source_url);
1887 RenderViewHostImpl::FilterURL(
1888 ChildProcessSecurityPolicyImpl::GetInstance(),
1889 render_process_host->GetID(),
1890 false,
1891 &validated_target_url);
1892 RenderViewHostImpl::FilterURL(
1893 ChildProcessSecurityPolicyImpl::GetInstance(),
1894 render_process_host->GetID(),
1895 true,
1896 &validated_opener_url);
1897 NavigationEntry* entry;
1898 if (page_id == -1) {
1899 entry = controller_.GetPendingEntry();
1900 } else {
1901 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1902 page_id);
1903 }
1904 if (!entry || entry->GetURL() != validated_source_url)
1905 return;
1906
1907 // Notify observers about the provisional change in the main frame URL.
1908 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1909 ProvisionalChangeToMainFrameUrl(validated_target_url,
1910 validated_opener_url,
1911 render_view_host));
[email protected]724159a2010-12-30 01:11:181912}
1913
[email protected]54047eb52012-05-08 21:45:571914void WebContentsImpl::DidFailProvisionalLoadWithError(
1915 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581916 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1917 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1918 << ", error_code: " << params.error_code
1919 << ", error_description: " << params.error_description
1920 << ", is_main_frame: " << params.is_main_frame
1921 << ", showing_repost_interstitial: " <<
1922 params.showing_repost_interstitial
1923 << ", frame_id: " << params.frame_id;
1924 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571925 content::RenderProcessHost* render_process_host =
1926 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541927 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571928 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451929 false,
[email protected]9f76c1e2012-03-05 15:15:581930 &validated_url);
[email protected]724159a2010-12-30 01:11:181931
[email protected]d7b175e2011-10-11 15:31:581932 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181933 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1934 // This means that the interstitial won't be torn down properly, which is
1935 // bad. But if we have an interstitial, go back to another tab type, and
1936 // then load the same interstitial again, we could end up getting the first
1937 // interstitial's "failed" message (as a result of the cancel) when we're on
1938 // the second one.
1939 //
1940 // We can't tell this apart, so we think we're tearing down the current page
1941 // which will cause a crash later one. There is also some code in
1942 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1943 // out because of this problem.
1944 //
1945 // http://code.google.com/p/chromium/issues/detail?id=2855
1946 // Because this will not tear down the interstitial properly, if "back" is
1947 // back to another tab type, the interstitial will still be somewhat alive
1948 // in the previous tab type. If you navigate somewhere that activates the
1949 // tab with the interstitial again, you'll see a flash before the new load
1950 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271951 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181952 LOG(WARNING) << "Discarding message during interstitial.";
1953 return;
1954 }
1955
[email protected]a16690732012-07-13 19:22:171956 // Do not clear the pending entry if one exists, so that the user's typed
1957 // URL is not lost when a navigation fails or is aborted. We'll allow
1958 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181959
[email protected]54047eb52012-05-08 21:45:571960 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181961 }
1962
[email protected]d8c660432011-12-22 20:51:251963 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581964 observers_,
1965 DidFailProvisionalLoad(params.frame_id,
1966 params.is_main_frame,
1967 validated_url,
1968 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461969 params.error_description,
1970 render_view_host));
[email protected]724159a2010-12-30 01:11:181971}
1972
[email protected]b172aee2012-04-10 17:05:261973void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181974 const GURL& url,
[email protected]70435962011-08-02 20:13:281975 const std::string& security_info,
1976 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181977 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281978 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191979 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181980 cache.Increment();
1981
1982 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081983 int cert_id = 0;
1984 net::CertStatus cert_status = 0;
1985 int security_bits = -1;
1986 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511987 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1988 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:001989 content::LoadFromMemoryCacheDetails details(
1990 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
1991 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181992
[email protected]ad50def52011-10-19 23:17:071993 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271994 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501995 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:001996 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181997}
1998
[email protected]b172aee2012-04-10 17:05:261999void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382000 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182001 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:202002 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:182003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022006 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232007 LOG(INFO) << security_origin << " ran insecure content from "
2008 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382009 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412010 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2011 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182012 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412013 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:202014 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:182015}
2016
[email protected]b172aee2012-04-10 17:05:262017void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182018 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252019 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472020 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182021}
2022
[email protected]b172aee2012-04-10 17:05:262023void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312024 int64 frame_id,
2025 const GURL& validated_url,
2026 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252027 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472028 DidFinishLoad(frame_id, validated_url, is_main_frame,
2029 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312030}
2031
[email protected]b172aee2012-04-10 17:05:262032void WebContentsImpl::OnDidFailLoadWithError(
2033 int64 frame_id,
2034 const GURL& validated_url,
2035 bool is_main_frame,
2036 int error_code,
2037 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252038 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312039 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472040 error_code, error_description,
2041 message_source_));
[email protected]724159a2010-12-30 01:11:182042}
2043
[email protected]b172aee2012-04-10 17:05:262044void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272045 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432046 if (delegate_)
2047 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172048}
2049
[email protected]b172aee2012-04-10 17:05:262050void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262051 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232052 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252053 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262054 if (!entry)
2055 return;
2056 // Note that we don't call NavigationController::GotToOffset() as we don't
2057 // want to create a pending navigation entry (it might end up lingering
2058 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252059 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582060 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512061 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582062 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472063 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572064
2065 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2066 // it in now that we know. This allows us to find the entry when it commits.
2067 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232068 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332069 entry->set_site_instance(
2070 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572071 }
[email protected]216813952011-05-19 22:21:262072 }
2073}
2074
[email protected]b172aee2012-04-10 17:05:262075void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2076 int maximum_percent,
2077 bool remember) {
[email protected]216813952011-05-19 22:21:262078 minimum_zoom_percent_ = minimum_percent;
2079 maximum_zoom_percent_ = maximum_percent;
2080 temporary_zoom_settings_ = !remember;
2081}
2082
[email protected]20b433a2012-05-15 21:23:462083void WebContentsImpl::OnSaveURL(const GURL& url,
2084 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482085 download_stats::RecordDownloadSource(
2086 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262087 // Check if the URL to save matches the URL of the main frame. Since this
2088 // message originates from Pepper plugins, it may not be the case if the
2089 // plugin is an embedded element.
2090 GURL main_frame_url = GetURL();
2091 if (!main_frame_url.is_valid())
2092 return;
2093 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462094 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272095}
2096
[email protected]b172aee2012-04-10 17:05:262097void WebContentsImpl::OnEnumerateDirectory(int request_id,
2098 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432099 if (!delegate_)
2100 return;
2101
[email protected]b9535422012-02-09 01:47:592102 ChildProcessSecurityPolicyImpl* policy =
2103 ChildProcessSecurityPolicyImpl::GetInstance();
2104 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2105 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432109 if (delegate_)
2110 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202111}
2112
[email protected]b172aee2012-04-10 17:05:262113void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2114 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362115 const string16& title,
2116 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432117 if (!delegate_)
2118 return;
2119
[email protected]b9535422012-02-09 01:47:592120 ChildProcessSecurityPolicyImpl* policy =
2121 ChildProcessSecurityPolicyImpl::GetInstance();
2122 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2123 return;
[email protected]3a3b75a2012-06-01 08:38:362124 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202125}
2126
[email protected]b172aee2012-04-10 17:05:262127void WebContentsImpl::OnFindReply(int request_id,
2128 int number_of_matches,
2129 const gfx::Rect& selection_rect,
2130 int active_match_ordinal,
2131 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432132 if (delegate_) {
2133 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2134 active_match_ordinal, final_update);
2135 }
2136
[email protected]4e6239c2011-09-23 00:11:002137 // Send a notification to the renderer that we are ready to receive more
2138 // results from the scoping effort of the Find operation. The FindInPage
2139 // scoping is asynchronous and periodically sends results back up to the
2140 // browser using IPC. In an effort to not spam the browser we have the
2141 // browser send an ACK for each FindReply message and have the renderer
2142 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582143 GetRenderViewHostImpl()->Send(
2144 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442148 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2149 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452150}
2151
[email protected]b172aee2012-04-10 17:05:262152void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2153 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102154 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102156 AppCacheAccessed(manifest_url, blocked_by_policy));
2157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322160 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432161 color_chooser_ = delegate_ ?
2162 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202163}
2164
[email protected]b172aee2012-04-10 17:05:262165void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202166 if (color_chooser_ &&
2167 color_chooser_id == color_chooser_->identifier())
2168 color_chooser_->End();
2169}
2170
[email protected]b172aee2012-04-10 17:05:262171void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322172 SkColor color) {
[email protected]da8543762012-03-20 08:52:202173 if (color_chooser_ &&
2174 color_chooser_id == color_chooser_->identifier())
2175 color_chooser_->SetSelectedColor(color);
2176}
2177
[email protected]9f2a9d72012-04-16 16:02:222178void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2179 const FilePath& path,
2180 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442181 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2182 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292183}
2184
[email protected]d0759f492012-04-19 22:50:502185// This exists for render views that don't have a WebUI, but do have WebUI
2186// bindings enabled.
2187void WebContentsImpl::OnWebUISend(const GURL& source_url,
2188 const std::string& name,
2189 const base::ListValue& args) {
2190 if (delegate_)
2191 delegate_->WebUISend(this, source_url, name, args);
2192}
2193
[email protected]96d185d2009-04-24 03:28:542194// Notifies the RenderWidgetHost instance about the fact that the page is
2195// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262196void WebContentsImpl::SetIsLoading(bool is_loading,
2197 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542198 if (is_loading == is_loading_)
2199 return;
2200
2201 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212202 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542203 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562204 upload_size_ = 0;
2205 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542206 }
2207
2208 render_manager_.SetIsLoading(is_loading);
2209
2210 is_loading_ = is_loading;
2211 waiting_for_response_ = is_loading;
2212
[email protected]6ebdc9b2010-09-27 16:55:572213 if (delegate_)
2214 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462215 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542216
[email protected]432115822011-07-10 15:52:272217 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2218 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072219 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542220 if (details)
[email protected]6c2381d2011-10-19 02:52:532221 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072222 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502223 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542224 det);
2225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132228 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322229 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562230 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382231 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442232 // that opened the window, as long as both renderers have the same
2233 // privileges.
[email protected]1fd1a502011-03-30 16:55:562234 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562235 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582236 // web_ui might be NULL if the URL refers to a non-existent extension.
2237 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402238 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522239 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442240 }
2241 }
[email protected]1fd1a502011-03-30 16:55:562242 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442243 }
2244
[email protected]4e697b042011-07-08 06:44:562245 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322246 // Clear the status bubble. This is a workaround for a bug where WebKit
2247 // doesn't let us know that the cursor left an element during a
2248 // transition (this is also why the mouse cursor remains as a hand after
2249 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2250 // clear the bubble when a user navigates to a named anchor in the same
2251 // page.
[email protected]36fc0392011-12-25 03:59:512252 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322253 }
2254
[email protected]a6e82fc2010-02-24 22:28:142255 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472256 // Once the main frame is navigated, we're no longer considered to have
2257 // displayed insecure content.
2258 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172259 }
[email protected]ce5c4502009-05-06 16:46:112260
[email protected]3c9e1872010-11-18 16:17:492261 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252262 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042263 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322264}
2265
[email protected]b172aee2012-04-10 17:05:262266void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322267 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132268 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322269 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062270 // If we navigate off the page, reset JavaScript state. This does nothing
2271 // to prevent a malicious script from spamming messages, since the script
2272 // could just reload the page to stop blocking.
2273 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552274 dialog_creator_->ResetJavaScriptState(this);
2275 dialog_creator_ = NULL;
2276 }
[email protected]420ae012009-04-24 05:16:322277
[email protected]3c9e1872010-11-18 16:17:492278 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252279 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042280 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322281}
2282
[email protected]b172aee2012-04-10 17:05:262283void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462284 // If we are creating a RVH for a restored controller, then we need to make
2285 // sure the RenderView starts with a next_page_id_ larger than the number
2286 // of restored entries. This must be called before the RenderView starts
2287 // navigating (to avoid a race between the browser updating max_page_id and
2288 // the renderer updating next_page_id_). Because of this, we only call this
2289 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562290 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582291 if (max_restored_page_id >
2292 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2293 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2294 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322295}
2296
[email protected]b172aee2012-04-10 17:05:262297bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2298 const string16& title) {
[email protected]420ae012009-04-24 05:16:322299 // For file URLs without a title, use the pathname instead. In the case of a
2300 // synthesized title, we don't want the update to count toward the "one set
2301 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512302 string16 final_title;
[email protected]420ae012009-04-24 05:16:322303 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512304 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2305 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322306 explicit_set = false; // Don't count synthetic titles toward the set limit.
2307 } else {
[email protected]acafd272011-07-26 17:35:572308 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322309 explicit_set = true;
2310 }
2311
[email protected]987fc3a2011-05-26 14:18:092312 // If a page is created via window.open and never navigated,
2313 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552314 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092315 if (entry) {
[email protected]36fc0392011-12-25 03:59:512316 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092317 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322318
[email protected]36fc0392011-12-25 03:59:512319 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092320 } else {
2321 if (page_title_when_no_navigation_entry_ == final_title)
2322 return false; // Nothing changed, don't bother.
2323
2324 page_title_when_no_navigation_entry_ = final_title;
2325 }
[email protected]420ae012009-04-24 05:16:322326
[email protected]420ae012009-04-24 05:16:322327 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232328 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322329
[email protected]2bb171882012-03-07 02:09:462330 std::pair<content::NavigationEntry*, bool> details =
2331 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142332
[email protected]ad50def52011-10-19 23:17:072333 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442334 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2335 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462336 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042337
[email protected]420ae012009-04-24 05:16:322338 return true;
2339}
2340
[email protected]b172aee2012-04-10 17:05:262341void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322342 // After sending out a swap notification, we need to send a disconnect
2343 // notification so that clients that pick up a pointer to |this| can NULL the
2344 // pointer. See Bug 1230284.
2345 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072346 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202347 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2348 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072349 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322350}
2351
[email protected]b172aee2012-04-10 17:05:262352void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322353 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072354 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122355 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2356 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072357 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322358}
2359
[email protected]b172aee2012-04-10 17:05:262360void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322361 if (!notify_disconnection_)
2362 return;
2363
2364 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072365 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322366 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2367 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072368 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322369}
2370
[email protected]5a3bdf52012-05-24 15:12:572371RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2372 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322373}
2374
[email protected]8d3347f2009-07-09 22:00:212375RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262376WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212377 return &render_manager_;
2378}
2379
[email protected]b172aee2012-04-10 17:05:262380content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372381 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462382 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512383}
2384
[email protected]b172aee2012-04-10 17:05:262385WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172386 return this;
2387}
2388
[email protected]b172aee2012-04-10 17:05:262389gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172390 if (delegate_)
2391 return delegate_->GetRootWindowResizerRect();
2392 return gfx::Rect();
2393}
2394
[email protected]b172aee2012-04-10 17:05:262395void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442396 // Don't send notifications if we are just creating a swapped-out RVH for
2397 // the opener chain. These won't be used for view-source or WebUI, so it's
2398 // ok to return early.
2399 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2400 return;
2401
[email protected]ad50def52011-10-19 23:17:072402 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302403 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322404 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532405 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232406 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322407 if (!entry)
2408 return;
2409
2410 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352411 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562412 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582413 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322414
2415 if (entry->IsViewSourceMode()) {
2416 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582417 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2418 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322419 }
[email protected]0666aef2009-05-13 19:48:082420
[email protected]d487beefe2011-12-21 05:41:212421 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262422
2423 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252424 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322425}
2426
[email protected]b172aee2012-04-10 17:05:262427void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522428 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322429 // Don't notify the world, since this came from a renderer in the
2430 // background.
2431 return;
2432 }
2433
2434 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312435 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232436 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302437
2438 // Restore the focus to the tab (otherwise the focus will be on the top
2439 // window).
[email protected]484ae5912010-09-29 19:16:142440 if (was_crashed && !FocusLocationBarByDefault() &&
2441 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302442 Focus();
[email protected]484ae5912010-09-29 19:16:142443 }
[email protected]32ded2212011-11-10 18:51:432444
[email protected]d8c660432011-12-22 20:51:252445 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322446}
2447
[email protected]b172aee2012-04-10 17:05:262448void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2449 base::TerminationStatus status,
2450 int error_code) {
[email protected]151a63d2011-12-20 22:32:522451 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322452 // The pending page's RenderViewHost is gone.
2453 return;
2454 }
2455
2456 SetIsLoading(false, NULL);
2457 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232458 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312459 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322460
[email protected]d8c660432011-12-22 20:51:252461 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272462 observers_,
[email protected]be1f56ab2011-12-22 06:55:312463 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322464}
2465
[email protected]b172aee2012-04-10 17:05:262466void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482467 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252468 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062469}
2470
[email protected]b172aee2012-04-10 17:05:262471void WebContentsImpl::DidNavigate(
2472 RenderViewHost* rvh,
2473 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582474 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322475 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372476
[email protected]434f69f2012-02-06 21:56:522477 // Update the site of the SiteInstance if it doesn't have one yet, unless
2478 // this is for about:blank. In that case, the SiteInstance can still be
2479 // considered unused until a navigation to a real page.
2480 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2481 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332482 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522483 }
[email protected]420ae012009-04-24 05:16:322484
2485 // Need to update MIME type here because it's referred to in
2486 // UpdateNavigationCommands() called by RendererDidNavigate() to
2487 // determine whether or not to enable the encoding menu.
2488 // It's updated only for the main frame. For a subframe,
2489 // RenderView::UpdateURL does not set params.contents_mime_type.
2490 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2491 // TODO(jungshik): Add a test for the encoding menu to avoid
2492 // regressing it again.
[email protected]2905f742011-10-13 03:51:582493 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322494 contents_mime_type_ = params.contents_mime_type;
2495
[email protected]8286f51a2011-05-31 17:39:132496 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002497 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392498
[email protected]a9c0bfe2010-09-17 08:35:222499 // Send notification about committed provisional loads. This notification is
2500 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2501 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082502 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072503 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2504 // that is not recorded in the navigation history. For the purpose of
2505 // tracking navigation events, we treat this event as a sub frame navigation
2506 // event.
2507 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582508 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222509 // Whether or not a page transition was triggered by going backward or
2510 // forward in the history is only stored in the navigation controller's
2511 // entry list.
2512 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512513 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582514 content::PAGE_TRANSITION_FORWARD_BACK)) {
2515 transition_type = content::PageTransitionFromInt(
2516 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222517 }
[email protected]0d60f0192011-04-14 12:40:102518 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252519 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102520 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462521 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222522 }
2523
[email protected]76543b92009-08-31 17:27:452524 if (!did_navigate)
2525 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322526
2527 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2528 // for the appropriate notification (best) or you can add it to
2529 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2530 // necessary, please).
2531
2532 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002533 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322534 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512535 if (delegate_)
2536 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002537 }
[email protected]420ae012009-04-24 05:16:322538 DidNavigateAnyFramePostCommit(rvh, details, params);
2539}
2540
[email protected]b172aee2012-04-10 17:05:262541void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2542 int32 page_id,
2543 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152544 // Ensure that this state update comes from either the active RVH or one of
2545 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522546 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322547
2548 // We must be prepared to handle state updates for any page, these occur
2549 // when the user is scrolling and entering form data, as well as when we're
2550 // leaving a page, in which case our state may have already been moved to
2551 // the next page. The navigation controller will look up the appropriate
2552 // NavigationEntry and update it when it is notified via the delegate.
2553
2554 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582555 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322556 if (entry_index < 0)
2557 return;
[email protected]10f417c52011-12-28 21:04:232558 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322559
[email protected]36fc0392011-12-25 03:59:512560 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322561 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512562 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322563 controller_.NotifyEntryChanged(entry, entry_index);
2564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2567 int32 page_id,
2568 const string16& title,
2569 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322570 // If we have a title, that's a pretty good indication that we've started
2571 // getting useful data.
2572 SetNotWaitingForResponse();
2573
[email protected]73eb2602012-02-09 19:50:552574 // Try to find the navigation entry, which might not be the current one.
2575 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232576 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582577 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092578
[email protected]73eb2602012-02-09 19:50:552579 // We can handle title updates when we don't have an entry in
2580 // UpdateTitleForEntry, but only if the update is from the current RVH.
2581 if (!entry && rvh != GetRenderViewHost())
2582 return;
2583
[email protected]a49e10b2011-08-01 23:57:462584 // TODO(evan): make use of title_direction.
2585 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092586 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322587 return;
2588
2589 // Broadcast notifications when the UI should be updated.
2590 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462591 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322592}
2593
[email protected]b172aee2012-04-10 17:05:262594void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2595 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312596 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322597}
2598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512600 if (delegate_)
2601 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322602}
2603
[email protected]b172aee2012-04-10 17:05:262604void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292605 // The UI may be in an event-tracking loop, such as between the
2606 // mouse-down and mouse-up in text selection or a button click.
2607 // Defer the close until after tracking is complete, so that we
2608 // don't free objects out from under the UI.
2609 // TODO(shess): This could probably be integrated with the
2610 // IsDoingDrag() test below. Punting for now because I need more
2611 // research to understand how this impacts platforms other than Mac.
2612 // TODO(shess): This could get more fine-grained. For instance,
2613 // closing a tab in another window while selecting text in the
2614 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212615 if (GetView()->IsEventTracking()) {
2616 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292617 return;
2618 }
2619
[email protected]24a4d1062009-07-10 23:10:422620 // If we close the tab while we're in the middle of a drag, we'll crash.
2621 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212622 if (GetView()->IsDoingDrag()) {
2623 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422624 return;
2625 }
2626
[email protected]420ae012009-04-24 05:16:322627 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522628 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512629 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]b172aee2012-04-10 17:05:262632void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522633 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512634 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572635}
2636
[email protected]b172aee2012-04-10 17:05:262637void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512638 if (delegate_ && delegate_->IsPopupOrPanel(this))
2639 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322640}
2641
[email protected]89793072012-07-23 22:25:292642void WebContentsImpl::DidStartLoading(
2643 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322644 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492645
[email protected]82114f52012-03-20 22:53:412646 if (delegate_ && content_restrictions_)
2647 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492648
2649 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292650 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2651 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322652}
2653
[email protected]89793072012-07-23 22:25:292654void WebContentsImpl::DidStopLoading(
2655 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322656 scoped_ptr<LoadNotificationDetails> details;
2657
[email protected]10f417c52011-12-28 21:04:232658 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322659 // An entry may not exist for a stop when loading an initial blank page or
2660 // if an iframe injected by script into a blank page finishes loading.
2661 if (entry) {
[email protected]420ae012009-04-24 05:16:322662 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2663
2664 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512665 entry->GetVirtualURL(),
2666 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322667 elapsed,
2668 &controller_,
2669 controller_.GetCurrentEntryIndex()));
2670 }
2671
[email protected]420ae012009-04-24 05:16:322672 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492673
2674 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292675 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2676 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322677}
2678
[email protected]b172aee2012-04-10 17:05:262679void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162680 controller_.DiscardNonCommittedEntries();
2681
2682 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462683 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162684}
2685
[email protected]b172aee2012-04-10 17:05:262686void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512687 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132688 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402689}
2690
[email protected]87717d0e2012-04-26 02:58:432691void WebContentsImpl::DocumentAvailableInMainFrame(
2692 RenderViewHost* render_view_host) {
2693 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2694 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102695}
2696
[email protected]b172aee2012-04-10 17:05:262697void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082698 RenderViewHost* render_view_host,
2699 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072700 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272701 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322702 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532703 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082704}
2705
[email protected]196159d2012-05-04 17:26:542706void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2707 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262708 const content::Referrer& referrer,
2709 WindowOpenDisposition disposition,
2710 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542711 // If this came from a swapped out RenderViewHost, we only allow the request
2712 // if we are still in the same BrowsingInstance.
2713 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2714 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2715 return;
2716 }
2717
[email protected]4ad5d77d2011-12-03 02:00:482718 // Delegate to RequestTransferURL because this is just the generic
2719 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582720 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482721 GlobalRequestID());
2722}
2723
[email protected]b172aee2012-04-10 17:05:262724void WebContentsImpl::RequestTransferURL(
2725 const GURL& url,
2726 const content::Referrer& referrer,
2727 WindowOpenDisposition disposition,
2728 int64 source_frame_id,
2729 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202730 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582731 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582732 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352733 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322734 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2735 // generated suggestions).
2736 //
[email protected]e0112912011-02-02 22:54:352737 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162738 // want web sites to see a referrer of "chrome://blah" (and some
2739 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322740 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432741 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222742 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482743 false /* is_renderer_initiated */);
2744 params.transferred_global_request_id = old_request_id;
2745 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222746 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322747 } else {
[email protected]6bf6a6b52012-02-03 15:41:432748 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482749 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2750 params.transferred_global_request_id = old_request_id;
2751 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582752 }
2753 if (new_contents) {
2754 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252755 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582756 DidOpenRequestedURL(new_contents,
2757 url,
2758 referrer,
2759 disposition,
2760 transition_type,
2761 source_frame_id));
[email protected]420ae012009-04-24 05:16:322762 }
2763}
2764
[email protected]e1c3a552012-05-04 20:51:322765void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2766 // Tell the active RenderViewHost to run unload handlers and close, as long
2767 // as the request came from a RenderViewHost in the same BrowsingInstance.
2768 // In most cases, we receive this from a swapped out RenderViewHost.
2769 // It is possible to receive it from one that has just been swapped in,
2770 // in which case we might as well deliver the message anyway.
2771 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2772 GetRenderViewHost()->ClosePage();
2773}
2774
[email protected]f546640b2012-05-15 00:03:492775void WebContentsImpl::RouteMessageEvent(
2776 RenderViewHost* rvh,
2777 const ViewMsg_PostMessage_Params& params) {
2778 // Only deliver the message to the active RenderViewHost if the request
2779 // came from a RenderViewHost in the same BrowsingInstance.
2780 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2781 return;
2782
2783 ViewMsg_PostMessage_Params new_params(params);
2784
2785 // If there is a source_routing_id, translate it to the routing ID for
2786 // the equivalent swapped out RVH in the target process. If we need
2787 // to create a swapped out RVH for the source tab, we create its opener
2788 // chain as well, since those will also be accessible to the target page.
2789 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2790 // Try to look up the WebContents for the source page.
2791 WebContentsImpl* source_contents = NULL;
2792 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2793 rvh->GetProcess()->GetID(), params.source_routing_id);
2794 if (source_rvh) {
2795 source_contents = static_cast<WebContentsImpl*>(
2796 source_rvh->GetDelegate()->GetAsWebContents());
2797 }
2798
2799 if (source_contents) {
2800 new_params.source_routing_id =
2801 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2802 } else {
2803 // We couldn't find it, so don't pass a source frame.
2804 new_params.source_routing_id = MSG_ROUTING_NONE;
2805 }
2806 }
2807
2808 // In most cases, we receive this from a swapped out RenderViewHost.
2809 // It is possible to receive it from one that has just been swapped in,
2810 // in which case we might as well deliver the message anyway.
2811 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2812 GetRenderViewHost()->GetRoutingID(), new_params));
2813}
2814
[email protected]b172aee2012-04-10 17:05:262815void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342816 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412817 const string16& message,
2818 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322819 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142820 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322821 IPC::Message* reply_msg,
2822 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072823 // Suppress JavaScript dialogs when requested. Also suppress messages when
2824 // showing an interstitial as it's shown over the previous page and we don't
2825 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502826 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582827 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272828 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072829 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522830 delegate_->ShouldSuppressDialogs() ||
2831 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322832
2833 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432834 std::string accept_lang = content::GetContentClient()->browser()->
2835 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552836 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522837 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432838 this,
2839 frame_url.GetOrigin(),
2840 accept_lang,
2841 javascript_message_type,
2842 message,
[email protected]51da7e32012-01-30 19:24:522843 default_prompt,
[email protected]b172aee2012-04-10 17:05:262844 base::Bind(&WebContentsImpl::OnDialogClosed,
2845 base::Unretained(this),
2846 rvh,
2847 reply_msg),
[email protected]51da7e32012-01-30 19:24:522848 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322849 }
[email protected]3ab9cb82011-06-03 18:02:072850
2851 if (suppress_this_message) {
2852 // If we are suppressing messages, just reply as if the user immediately
2853 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342854 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072855 }
2856
2857 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322858}
2859
[email protected]b172aee2012-04-10 17:05:262860void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2861 const string16& message,
2862 bool is_reload,
2863 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582864 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512865 if (delegate_)
2866 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072867
2868 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582869 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072870 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522871 delegate_->ShouldSuppressDialogs() ||
2872 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152873 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342874 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582875 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502876 return;
2877 }
[email protected]3ab9cb82011-06-03 18:02:072878
[email protected]7ab1e7d62009-10-14 23:32:012879 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552880 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522881 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322882 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262883 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522884 reply_msg));
[email protected]420ae012009-04-24 05:16:322885}
2886
[email protected]a796f202012-05-30 14:14:252887bool WebContentsImpl::AddMessageToConsole(int32 level,
2888 const string16& message,
2889 int32 line_no,
2890 const string16& source_id) {
2891 if (!delegate_)
2892 return false;
2893 return delegate_->AddMessageToConsole(this, level, message, line_no,
2894 source_id);
2895}
2896
[email protected]b172aee2012-04-10 17:05:262897WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332898 // We want to base the page config off of the real URL, rather than the
2899 // display URL.
2900 GURL url = controller_.GetActiveEntry()
2901 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2902 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322903}
2904
[email protected]b172aee2012-04-10 17:05:262905void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272906 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252907 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222908
[email protected]ea114722012-03-12 01:11:252909 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172910 if (rdh) // NULL in unittests.
2911 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252912}
2913
[email protected]b172aee2012-04-10 17:05:262914void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442915 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252916 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442917}
2918
[email protected]b172aee2012-04-10 17:05:262919void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2920 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152921 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522922 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152923 return;
2924
[email protected]9f76c1e2012-03-05 15:15:582925 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2926
[email protected]e5fc1632011-08-08 07:51:532927 // Ignore renderer unresponsive event if debugger is attached to the tab
2928 // since the event may be a result of the renderer sitting on a breakpoint.
2929 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442930 DevToolsAgentHost* agent =
2931 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2932 if (agent &&
2933 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532934 return;
2935
[email protected]420ae012009-04-24 05:16:322936 if (is_during_unload) {
2937 // Hang occurred while firing the beforeunload/unload handler.
2938 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582939 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322940
2941 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2942 return;
2943
2944 // If the tab hangs in the beforeunload/unload handler there's really
2945 // nothing we can do to recover. Pretend the unload listeners have
2946 // all fired and close the tab. If the hang is in the beforeunload handler
2947 // then the user will not have the option of cancelling the close.
2948 Close(rvh);
2949 return;
2950 }
2951
[email protected]9f76c1e2012-03-05 15:15:582952 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472953 return;
2954
[email protected]6934a702011-12-20 00:04:512955 if (delegate_)
2956 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322957}
2958
[email protected]b172aee2012-04-10 17:05:262959void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512960 if (delegate_)
2961 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322962}
2963
[email protected]b172aee2012-04-10 17:05:262964void WebContentsImpl::LoadStateChanged(
2965 const GURL& url,
2966 const net::LoadStateWithParam& load_state,
2967 uint64 upload_position,
2968 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322969 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562970 upload_position_ = upload_position;
2971 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502972 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202973 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302974 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212975 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322976 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462977 if (IsLoading()) {
2978 NotifyNavigationStateChanged(
2979 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2980 }
[email protected]420ae012009-04-24 05:16:322981}
2982
[email protected]b172aee2012-04-10 17:05:262983void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512984 if (delegate_)
2985 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252986}
2987
[email protected]b172aee2012-04-10 17:05:262988void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322989 bool proceed,
2990 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512991 if (delegate_)
2992 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322993}
2994
[email protected]b172aee2012-04-10 17:05:262995void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542996 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232997 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2998 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542999}
3000
[email protected]b172aee2012-04-10 17:05:263001void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103002 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263003 gfx::Size size = view_->GetContainerSize();
3004 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3005 // here during container initialization and normal window size will be set
3006 // later. In case of tab duplication this resizing to 0x0 prevents setting
3007 // normal size later so just ignore it.
3008 if (!size.IsEmpty())
3009 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323010}
3011
[email protected]b172aee2012-04-10 17:05:263012void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543013 NotifySwapped();
3014}
3015
[email protected]14392a52012-05-02 20:28:443016int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3017 SiteInstance* instance) {
3018 if (!opener_)
3019 return MSG_ROUTING_NONE;
3020
3021 // Recursively create RenderViews for anything else in the opener chain.
3022 return opener_->CreateOpenerRenderViews(instance);
3023}
3024
3025int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3026 int opener_route_id = MSG_ROUTING_NONE;
3027
3028 // If this tab has an opener, ensure it has a RenderView in the given
3029 // SiteInstance as well.
3030 if (opener_)
3031 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3032
3033 // Create a swapped out RenderView in the given SiteInstance if none exists,
3034 // setting its opener to the given route_id. Return the new view's route_id.
3035 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3036}
3037
[email protected]b172aee2012-04-10 17:05:263038NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:203039 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:543040}
3041
[email protected]b172aee2012-04-10 17:05:263042WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563043 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323044}
3045
[email protected]10f417c52011-12-28 21:04:233046NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263047 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323048 return controller_.GetLastCommittedEntry();
3049}
3050
[email protected]b172aee2012-04-10 17:05:263051bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443052 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443053 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323054 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523055
[email protected]420ae012009-04-24 05:16:323056 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443057 if (rwh_view)
3058 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323059
[email protected]74ce1ad2011-12-16 21:51:463060 // Make sure we use the correct starting page_id in the new RenderView.
3061 UpdateMaxPageIDIfNecessary(render_view_host);
3062 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583063 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463064
[email protected]7900bfdb2012-05-24 19:31:243065 std::string embedder_channel_name;
3066 int embedder_container_id;
3067 GetBrowserPluginEmbedderInfo(render_view_host,
3068 &embedder_channel_name,
3069 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583070 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493071 render_view_host)->CreateRenderView(string16(),
3072 opener_route_id,
3073 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243074 embedder_channel_name,
3075 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523076 return false;
[email protected]14392a52012-05-02 20:28:443077 }
[email protected]a4127722011-04-27 23:13:523078
[email protected]e60c0232011-11-11 19:56:353079#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503080 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3081 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443082 if (rwh_view) {
3083 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3084 render_widget_host->WasResized();
3085 }
[email protected]f8233cc2011-05-31 20:24:503086#endif
3087
[email protected]420ae012009-04-24 05:16:323088 return true;
3089}
3090
[email protected]b172aee2012-04-10 17:05:263091void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3092 IPC::Message* reply_msg,
3093 bool success,
3094 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543095 if (is_showing_before_unload_dialog_ && !success) {
3096 // If a beforeunload dialog is canceled, we need to stop the throbber from
3097 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293098 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353099 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543100
[email protected]3bbacc5b2012-04-17 17:46:153101 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543102 }
3103 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583104 static_cast<RenderViewHostImpl*>(
3105 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543106}
3107
[email protected]b172aee2012-04-10 17:05:263108void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123109 encoding_ = content::GetContentClient()->browser()->
3110 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103111}
[email protected]f45d2a72010-03-08 23:28:353112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463114 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263115 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573116 DownloadManager* dlm =
3117 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143118 if (!dlm)
3119 return;
3120 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263121 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143122 const NavigationEntry* entry = controller_.GetActiveEntry();
3123 if (entry)
3124 post_id = entry->GetPostID();
3125 }
[email protected]29a5ffc82012-03-13 19:35:583126 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143127 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143128 scoped_ptr<DownloadUrlParameters> params(
3129 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493130 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143131 params->set_post_id(post_id);
3132 params->set_prefer_cache(true);
3133 if (post_id >= 0)
3134 params->set_method("POST");
3135 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143136}
3137
[email protected]b172aee2012-04-10 17:05:263138void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213139 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443140 // Can be NULL during tests.
3141 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213142 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363143}
[email protected]9f76c1e2012-03-05 15:15:583144
[email protected]b172aee2012-04-10 17:05:263145RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583146 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3147}
[email protected]7900bfdb2012-05-24 19:31:243148
3149void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3150 content::RenderViewHost* render_view_host,
3151 std::string* embedder_channel_name,
3152 int* embedder_container_id) {
3153 content::RenderProcessHost* embedder_render_process_host =
3154 browser_plugin_host()->embedder_render_process_host();
3155 *embedder_container_id = browser_plugin_host()->instance_id();
3156 int embedder_process_id =
3157 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3158 if (embedder_process_id != -1) {
3159 *embedder_channel_name =
3160 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3161 embedder_process_id);
3162 }
3163}