blob: d5a09dcbb874a55aa40e394cedb5f2975d3edf94 [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]cc510d7e2012-08-08 04:40:1018#include "content/browser/browser_plugin/old/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]d1198fd2012-08-13 22:50:1921#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0422#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4623#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1224#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1625#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3226#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5427#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0528#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0029#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3030#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3231#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5032#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2533#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3334#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3735#include "content/browser/web_contents/interstitial_page_impl.h"
36#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5741#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5842#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1143#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2044#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4445#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4446#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1747#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1448#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4649#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1550#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0051#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2752#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0053#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3754#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1455#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3256#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3857#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4258#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2559#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1060#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5061#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2162#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4863#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1864#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5465#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0366#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1667#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2968#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5469#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3470#include "net/url_request/url_request_context_getter.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]d1198fd2012-08-13 22:50:19285 const WebContents* base_web_contents) {
286 return WebContentsImpl::Create(
287 browser_context, site_instance, routing_id,
288 static_cast<const WebContentsImpl*>(base_web_contents));
289}
290
291WebContents* WebContents::CreateWithSessionStorage(
292 BrowserContext* browser_context,
293 SiteInstance* site_instance,
294 int routing_id,
[email protected]b172aee2012-04-10 17:05:26295 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19296 const SessionStorageNamespaceMap& session_storage_namespace_map) {
297 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
298
299 for (SessionStorageNamespaceMap::const_iterator it =
300 session_storage_namespace_map.begin();
301 it != session_storage_namespace_map.end();
302 ++it) {
303 new_contents->GetController().SetSessionStorageNamespace(it->first,
304 it->second);
305 }
306
307 new_contents->Init(browser_context, site_instance, routing_id,
308 static_cast<const WebContentsImpl*>(base_web_contents));
309 return new_contents;
[email protected]a81343d232011-12-27 07:39:20310}
[email protected]746d3052012-05-22 15:15:47311
[email protected]299d7f12012-05-23 05:31:15312WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47313 return rvh->GetDelegate()->GetAsWebContents();
314}
315
[email protected]a81343d232011-12-27 07:39:20316}
[email protected]f4f50ef2011-01-21 19:01:19317
[email protected]b172aee2012-04-10 17:05:26318// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32319
[email protected]b172aee2012-04-10 17:05:26320WebContentsImpl::WebContentsImpl(
321 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19322 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42323 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19324 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57325 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44326 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05327 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34328 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23329 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
330 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34331 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21332 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56333 upload_size_(0),
334 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47335 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57336 capturing_contents_(false),
337 is_being_destroyed_(false),
338 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55339 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57340#if defined(OS_WIN)
341 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
342#endif
[email protected]7ab1e7d62009-10-14 23:32:01343 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56344 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38345 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25346 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01347 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25348 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01349 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00350 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43351 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20352 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35353}
initial.commit09911bf2008-07-26 23:55:29354
[email protected]b172aee2012-04-10 17:05:26355WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32356 is_being_destroyed_ = true;
357
[email protected]3ab9cb82011-06-03 18:02:07358 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55359 if (dialog_creator_)
360 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07361
[email protected]da8543762012-03-20 08:52:20362 if (color_chooser_)
363 color_chooser_->End();
364
[email protected]420ae012009-04-24 05:16:32365 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32366
[email protected]ca13a442012-04-17 14:00:12367 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07368 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09369 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
370 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07371 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32372
373 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07374#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32375 // If we still have a window handle, destroy it. GetNativeView can return
376 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42377 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52378 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58379 if (host && host->GetView())
380 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42381 }
[email protected]420ae012009-04-24 05:16:32382#endif
[email protected]7ab1e7d62009-10-14 23:32:01383
384 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15385 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01386 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15387 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01388 }
[email protected]b5a1d11c2011-02-17 03:09:42389
[email protected]2db9bd72012-04-13 20:20:56390 FOR_EACH_OBSERVER(WebContentsObserver,
391 observers_,
392 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08393
[email protected]6934a702011-12-20 00:04:51394 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42395}
396
[email protected]d1198fd2012-08-13 22:50:19397WebContentsImpl* WebContentsImpl::Create(
398 BrowserContext* browser_context,
399 SiteInstance* site_instance,
400 int routing_id,
401 const WebContentsImpl* base_web_contents) {
402 return CreateWithOpener(browser_context, site_instance, routing_id,
403 base_web_contents, NULL);
404}
405
406WebContentsImpl* WebContentsImpl::CreateWithOpener(
407 BrowserContext* browser_context,
408 SiteInstance* site_instance,
409 int routing_id,
410 const WebContentsImpl* base_web_contents,
411 WebContentsImpl* opener) {
412 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
413
414 new_contents->Init(browser_context, site_instance, routing_id,
415 static_cast<const WebContentsImpl*>(base_web_contents));
416 return new_contents;
417}
418
[email protected]b172aee2012-04-10 17:05:26419WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
420 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54421 WebPreferences prefs;
422
423 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
424
425 prefs.developer_extras_enabled = true;
426 prefs.javascript_enabled =
427 !command_line.HasSwitch(switches::kDisableJavaScript);
428 prefs.web_security_enabled =
429 !command_line.HasSwitch(switches::kDisableWebSecurity);
430 prefs.plugins_enabled =
431 !command_line.HasSwitch(switches::kDisablePlugins);
432 prefs.java_enabled =
433 !command_line.HasSwitch(switches::kDisableJava);
434
435 prefs.uses_page_cache =
436 command_line.HasSwitch(switches::kEnableFastback);
437 prefs.remote_fonts_enabled =
438 !command_line.HasSwitch(switches::kDisableRemoteFonts);
439 prefs.xss_auditor_enabled =
440 !command_line.HasSwitch(switches::kDisableXSSAuditor);
441 prefs.application_cache_enabled =
442 !command_line.HasSwitch(switches::kDisableApplicationCache);
443
444 prefs.local_storage_enabled =
445 !command_line.HasSwitch(switches::kDisableLocalStorage);
446 prefs.databases_enabled =
447 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01448#if defined(OS_ANDROID)
449 prefs.webaudio_enabled =
450 command_line.HasSwitch(switches::kEnableWebAudio);
451#else
[email protected]64d69de42012-02-06 00:19:54452 prefs.webaudio_enabled =
453 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01454#endif
[email protected]64d69de42012-02-06 00:19:54455
456 prefs.experimental_webgl_enabled =
457 GpuProcessHost::gpu_enabled() &&
458 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07459#if defined(OS_ANDROID)
460 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
461#else
[email protected]64d69de42012-02-06 00:19:54462 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07463#endif
[email protected]64d69de42012-02-06 00:19:54464
[email protected]5a073092012-06-08 00:42:51465 prefs.flash_3d_enabled =
466 GpuProcessHost::gpu_enabled() &&
467 !command_line.HasSwitch(switches::kDisableFlash3d);
468 prefs.flash_stage3d_enabled =
469 GpuProcessHost::gpu_enabled() &&
470 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19471
[email protected]64d69de42012-02-06 00:19:54472 prefs.gl_multisampling_enabled =
473 !command_line.HasSwitch(switches::kDisableGLMultisampling);
474 prefs.privileged_webgl_extensions_enabled =
475 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
476 prefs.site_specific_quirks_enabled =
477 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
478 prefs.allow_file_access_from_file_urls =
479 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
480 prefs.show_composited_layer_borders =
481 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
482 prefs.show_composited_layer_tree =
483 command_line.HasSwitch(switches::kShowCompositedLayerTree);
484 prefs.show_fps_counter =
485 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19486 prefs.show_paint_rects =
487 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52488 prefs.render_vsync_enabled =
489 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54490 prefs.accelerated_compositing_enabled =
491 GpuProcessHost::gpu_enabled() &&
492 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54493 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23494 command_line.HasSwitch(switches::kForceCompositingMode) &&
495 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54496 prefs.fixed_position_compositing_enabled =
497 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
498 prefs.accelerated_2d_canvas_enabled =
499 GpuProcessHost::gpu_enabled() &&
500 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58501 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27502 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54503 prefs.accelerated_painting_enabled =
504 GpuProcessHost::gpu_enabled() &&
505 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
506 prefs.accelerated_filters_enabled =
507 GpuProcessHost::gpu_enabled() &&
508 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
509 prefs.accelerated_layers_enabled =
510 prefs.accelerated_animation_enabled =
511 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54512 prefs.accelerated_plugins_enabled =
513 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
514 prefs.accelerated_video_enabled =
515 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54516 prefs.fullscreen_enabled =
517 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16518 prefs.css_regions_enabled =
519 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29520 prefs.css_shaders_enabled =
521 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01522 prefs.css_variables_enabled =
523 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56524 prefs.device_supports_touch =
525 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]d849b122012-07-18 07:35:26526#if defined(OS_ANDROID)
527 prefs.device_supports_mouse = false;
528#endif
[email protected]64d69de42012-02-06 00:19:54529
530#if defined(OS_MACOSX)
531 bool default_enable_scroll_animator = true;
532#else
533 // On CrOS, the launcher always passes in the --enable flag.
534 bool default_enable_scroll_animator = false;
535#endif
536 prefs.enable_scroll_animator = default_enable_scroll_animator;
537 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
538 prefs.enable_scroll_animator = true;
539 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
540 prefs.enable_scroll_animator = false;
541
542 prefs.visual_word_movement_enabled =
543 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54544
545 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32546 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54547 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11548 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
549 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54550 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11551 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54552 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19553 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
554 prefs.flash_3d_enabled = false;
555 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
556 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11557 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54558 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11559 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54560 prefs.gl_multisampling_enabled = false;
561
562 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45563 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32564 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54565 prefs.accelerated_video_enabled = false;
566 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45567 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09568 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54569 }
570 }
571
[email protected]b9535422012-02-09 01:47:59572 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58573 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54574 prefs.loads_images_automatically = true;
575 prefs.javascript_enabled = true;
576 }
577
578 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
579
580 // Force accelerated compositing and 2d canvas off for chrome:, about: and
581 // chrome-devtools: pages (unless it's specifically allowed).
582 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54583 url.SchemeIs(chrome::kChromeUIScheme) ||
584 (url.SchemeIs(chrome::kAboutScheme) &&
585 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25586 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54587 prefs.accelerated_compositing_enabled = false;
588 prefs.accelerated_2d_canvas_enabled = false;
589 }
[email protected]43d9d782012-03-01 15:40:09590
[email protected]f98f5092012-05-19 00:08:14591 if (command_line.HasSwitch(switches::kDefaultTileWidth))
592 prefs.default_tile_width =
593 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
594 if (command_line.HasSwitch(switches::kDefaultTileHeight))
595 prefs.default_tile_height =
596 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
597 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
598 prefs.max_untiled_layer_width =
599 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
600 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
601 prefs.max_untiled_layer_height =
602 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
603
[email protected]2486dce2012-05-23 17:18:19604 if (gfx::Screen::IsDIPEnabled()) {
605 // Only apply when using DIP coordinate system as this setting interferes
606 // with fixed layout mode.
607 prefs.apply_default_device_scale_factor_in_compositor = true;
608 }
609
[email protected]de023762012-07-26 17:10:17610 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
611 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10612
[email protected]6b4dcb072012-06-18 22:26:51613 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
614
[email protected]2e21fe292012-03-02 22:52:32615 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54616
617 return prefs;
618}
619
[email protected]b172aee2012-04-10 17:05:26620RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28621 return &render_manager_;
622}
623
[email protected]7bb761892012-07-20 09:32:47624bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
625 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56626 if (GetWebUI() &&
627 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17628 return true;
[email protected]d2353452012-01-19 19:53:56629 }
[email protected]f82d57b52011-04-27 19:13:17630
[email protected]d8c660432011-12-22 20:51:25631 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
632 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10633 while ((observer = it.GetNext()) != NULL)
634 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53635 return true;
[email protected]403415a2011-01-10 18:57:53636
[email protected]7bb761892012-07-20 09:32:47637 // Message handlers should be aware of which RenderViewHost sent the
638 // message, which is temporarily stored in message_source_.
639 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18640 bool handled = true;
641 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26642 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58643 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
644 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24645 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
646 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18647 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
648 OnDidLoadResourceFromMemoryCache)
649 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
650 OnDidDisplayInsecureContent)
651 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
652 OnDidRunInsecureContent)
653 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
654 OnDocumentLoadedInFrame)
655 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26656 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
657 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17658 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
659 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25660 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26661 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59662 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21663 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20664 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
665 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
666 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16667 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45668 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10669 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20670 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
671 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
672 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
673 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29674 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50675 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18676 IPC_MESSAGE_UNHANDLED(handled = false)
677 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47678 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18679
680 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38681 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18682 GetRenderProcessHost()->ReceivedBadMessage();
683 }
684
685 return handled;
686}
687
[email protected]b172aee2012-04-10 17:05:26688void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18689 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23690 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43691 if (delegate_)
692 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18693}
694
[email protected]d1198fd2012-08-13 22:50:19695NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56696 return controller_;
697}
698
[email protected]d1198fd2012-08-13 22:50:19699const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56700 return controller_;
701}
702
[email protected]b172aee2012-04-10 17:05:26703content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55704 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30705}
706
[email protected]b172aee2012-04-10 17:05:26707const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31708 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23709 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51710 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31711}
712
713
[email protected]b172aee2012-04-10 17:05:26714const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31715 return &property_bag_;
716}
717
[email protected]b172aee2012-04-10 17:05:26718base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31719 return &property_bag_;
720}
721
[email protected]b172aee2012-04-10 17:05:26722content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31723 return delegate_;
724}
725
[email protected]b172aee2012-04-10 17:05:26726void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31727 // TODO(cbentzel): remove this debugging code?
728 if (delegate == delegate_)
729 return;
730 if (delegate_)
731 delegate_->Detach(this);
732 delegate_ = delegate;
733 if (delegate_)
734 delegate_->Attach(this);
735}
736
[email protected]b172aee2012-04-10 17:05:26737content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41738 RenderViewHostImpl* host = render_manager_.current_host();
739 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16740}
741
[email protected]b172aee2012-04-10 17:05:26742RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31743 return render_manager_.current_host();
744}
745
[email protected]b172aee2012-04-10 17:05:26746RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31747 return render_manager_.GetRenderWidgetHostView();
748}
749
[email protected]b172aee2012-04-10 17:05:26750content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31751 return view_.get();
752}
753
[email protected]b172aee2012-04-10 17:05:26754content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50755 WebUIControllerFactory* factory =
756 content::GetContentClient()->browser()->GetWebUIControllerFactory();
757 if (!factory)
758 return NULL;
[email protected]d2353452012-01-19 19:53:56759 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22760 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50761 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22762 if (controller) {
763 web_ui->SetController(controller);
764 return web_ui;
765 }
766
767 delete web_ui;
768 return NULL;
769}
770
[email protected]b172aee2012-04-10 17:05:26771content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31772 return render_manager_.web_ui() ? render_manager_.web_ui()
773 : render_manager_.pending_web_ui();
774}
775
[email protected]b172aee2012-04-10 17:05:26776content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31777 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34778}
779
[email protected]86ef6a392012-05-11 22:03:11780void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22781 if (GetUserAgentOverride() == override)
782 return;
783
784 renderer_preferences_.user_agent_override = override;
785
786 // Send the new override string to the renderer.
787 RenderViewHost* host = GetRenderViewHost();
788 if (host)
789 host->SyncRendererPrefs();
790
791 // Reload the page if a load is currently in progress to avoid having
792 // different parts of the page loaded using different user agents.
793 NavigationEntry* entry = controller_.GetActiveEntry();
794 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
795 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11796}
797
798const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22799 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11800}
801
[email protected]b172aee2012-04-10 17:05:26802const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55803 // Transient entries take precedence. They are used for interstitial pages
804 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23805 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08806 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20807 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30808 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23809 if (entry) {
[email protected]b5cca982011-05-26 04:42:08810 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23811 }
[email protected]7ade2732011-02-10 00:13:58812 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
813 render_manager_.pending_web_ui() : render_manager_.web_ui();
814 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54815 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55816 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54817 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35818 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22819 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54820 if (!title.empty())
821 return title;
822 }
823 }
824
825 // We use the title for the last committed entry rather than a pending
826 // navigation entry. For example, when the user types in a URL, we want to
827 // keep the old page's title until the new load has committed and we get a new
828 // title.
[email protected]96d185d2009-04-24 03:28:54829 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23830 if (entry) {
[email protected]b5cca982011-05-26 04:42:08831 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23832 }
[email protected]987fc3a2011-05-26 14:18:09833
834 // |page_title_when_no_navigation_entry_| is finally used
835 // if no title cannot be retrieved.
836 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54837}
838
[email protected]b172aee2012-04-10 17:05:26839int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46840 return GetMaxPageIDForSiteInstance(GetSiteInstance());
841}
842
[email protected]b172aee2012-04-10 17:05:26843int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
844 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33845 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
846 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46847
[email protected]b6583592012-01-25 19:52:33848 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34849}
850
[email protected]b172aee2012-04-10 17:05:26851void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46852 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
853}
854
[email protected]b172aee2012-04-10 17:05:26855void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33856 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46857 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33858 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34859}
860
[email protected]b172aee2012-04-10 17:05:26861void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
862 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57863}
864
[email protected]b172aee2012-04-10 17:05:26865SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58866 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54867}
868
[email protected]b172aee2012-04-10 17:05:26869SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38870 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
871 render_manager_.pending_render_view_host() :
872 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58873 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38874}
875
[email protected]b172aee2012-04-10 17:05:26876bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31877 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49878}
879
[email protected]b172aee2012-04-10 17:05:26880bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31881 return waiting_for_response_;
882}
883
[email protected]b172aee2012-04-10 17:05:26884const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31885 return load_state_;
886}
887
[email protected]b172aee2012-04-10 17:05:26888const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return load_state_host_;
890}
891
[email protected]b172aee2012-04-10 17:05:26892uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return upload_size_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31897 return upload_position_;
898}
899
[email protected]b172aee2012-04-10 17:05:26900const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31901 return encoding_;
902}
903
[email protected]b172aee2012-04-10 17:05:26904bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31905 return displayed_insecure_content_;
906}
907
[email protected]b172aee2012-04-10 17:05:26908void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31909 capturing_contents_ = cap;
910}
911
[email protected]b172aee2012-04-10 17:05:26912bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
914 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
915 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49916}
917
[email protected]b172aee2012-04-10 17:05:26918void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
919 int error_code) {
[email protected]443b80e2010-12-14 00:42:23920 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34921 return;
922
[email protected]443b80e2010-12-14 00:42:23923 crashed_status_ = status;
924 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46925 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34926}
927
[email protected]b172aee2012-04-10 17:05:26928base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31929 return crashed_status_;
930}
931
[email protected]b172aee2012-04-10 17:05:26932bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return is_being_destroyed_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34937 if (delegate_)
938 delegate_->NavigationStateChanged(this, changed_flags);
939}
940
[email protected]3e324142012-06-25 18:26:33941base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
942 return last_selected_time_;
943}
944
[email protected]9e2e4632012-07-27 16:38:41945void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54946 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04947 RenderWidgetHostViewPort* rwhv =
948 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16949 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41950 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43951#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16952 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43953#endif
954 }
[email protected]96d185d2009-04-24 03:28:54955
[email protected]5ac20162010-11-24 23:33:11956 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38957
[email protected]9e2e4632012-07-27 16:38:41958 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59959
960 // The resize rect might have changed while this was inactive -- send the new
961 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58962 RenderViewHostImpl* rvh =
963 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59964 if (rvh) {
965 rvh->ResizeRectChanged(GetRootWindowResizerRect());
966 }
[email protected]96d185d2009-04-24 03:28:54967
[email protected]3e324142012-06-25 18:26:33968 bool is_visible = true;
969 content::NotificationService::current()->Notify(
970 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
971 content::Source<WebContents>(this),
972 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31973}
974
[email protected]b172aee2012-04-10 17:05:26975void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31976 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52977 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
978 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26979 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52980 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33981 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52982 // calls us).
[email protected]c30585c2012-02-16 15:02:04983 RenderWidgetHostViewPort* rwhv =
984 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16985 if (rwhv)
986 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54987 }
988
[email protected]375fa1b2012-05-22 22:05:37989 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07990 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37991 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09992 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37993 content::Details<bool>(&is_visible));
994}
995
[email protected]b172aee2012-04-10 17:05:26996bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31997 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27998 return WillNotifyDisconnection() &&
999 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581000 !static_cast<RenderViewHostImpl*>(
1001 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311002}
1003
[email protected]b172aee2012-04-10 17:05:261004void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271005 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251006 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271007}
1008
[email protected]b172aee2012-04-10 17:05:261009WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441010 // We use our current SiteInstance since the cloned entry will use it anyway.
1011 // We pass |this| for the |base_web_contents| to size the view correctly, and
1012 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191013 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1014 GetSiteInstance(), MSG_ROUTING_NONE,
1015 this, opener_);
1016 tc->GetController().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271017 return tc;
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020void WebContentsImpl::AddNewContents(WebContents* new_contents,
1021 WindowOpenDisposition disposition,
1022 const gfx::Rect& initial_pos,
1023 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271024 if (!delegate_)
1025 return;
1026
1027 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1028 user_gesture);
1029}
1030
[email protected]b172aee2012-04-10 17:05:261031gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271032 return view_->GetContentNativeView();
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271036 return view_->GetNativeView();
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271040 view_->GetContainerBounds(out);
1041}
1042
[email protected]b172aee2012-04-10 17:05:261043void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271044 view_->Focus();
1045}
1046
[email protected]14392a52012-05-02 20:28:441047void WebContentsImpl::Observe(int type,
1048 const content::NotificationSource& source,
1049 const content::NotificationDetails& details) {
1050 switch (type) {
1051 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1052 OnWebContentsDestroyed(
1053 content::Source<content::WebContents>(source).ptr());
1054 break;
[email protected]bafe6cd2012-05-23 23:09:501055 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1056 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1057 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1058 i != pending_widget_views_.end(); ++i) {
1059 if (host->GetView() == i->second) {
1060 pending_widget_views_.erase(i);
1061 break;
1062 }
1063 }
1064 break;
1065 }
[email protected]14392a52012-05-02 20:28:441066 default:
1067 NOTREACHED();
1068 }
1069}
1070
[email protected]d1198fd2012-08-13 22:50:191071void WebContentsImpl::Init(BrowserContext* browser_context,
1072 SiteInstance* site_instance,
1073 int routing_id,
1074 const WebContents* base_web_contents) {
1075 render_manager_.Init(browser_context, site_instance, routing_id);
1076
1077 view_.reset(content::GetContentClient()->browser()->
1078 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1079 if (view_.get()) {
1080 CHECK(render_view_host_delegate_view_);
1081 } else {
1082 content::WebContentsViewDelegate* delegate =
1083 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1084 this);
1085 view_.reset(CreateWebContentsView(
1086 this, delegate, &render_view_host_delegate_view_));
1087 CHECK(render_view_host_delegate_view_);
1088 }
1089 CHECK(view_.get());
1090
1091 // We have the initial size of the view be based on the size of the view of
1092 // the passed in WebContents.
1093 view_->CreateView(base_web_contents ?
1094 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1095
1096 // Listen for whether our opener gets destroyed.
1097 if (opener_) {
1098 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1099 content::Source<WebContents>(opener_));
1100 }
1101
1102 registrar_.Add(this,
1103 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1104 content::NotificationService::AllBrowserContextsAndSources());
1105#if defined(ENABLE_JAVA_BRIDGE)
1106 java_bridge_dispatcher_host_manager_.reset(
1107 new JavaBridgeDispatcherHostManager(this));
1108#endif
1109
1110 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1111}
1112
[email protected]14392a52012-05-02 20:28:441113void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1114 // Clear the opener if it has been closed.
1115 if (web_contents == opener_) {
1116 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1117 content::Source<WebContents>(opener_));
1118 opener_ = NULL;
1119 }
1120}
1121
[email protected]b172aee2012-04-10 17:05:261122void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311123 observers_.AddObserver(observer);
1124}
1125
[email protected]b172aee2012-04-10 17:05:261126void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311127 observers_.RemoveObserver(observer);
1128}
1129
[email protected]b172aee2012-04-10 17:05:261130void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341131 if (delegate_)
1132 delegate_->ActivateContents(this);
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121136 if (delegate_)
1137 delegate_->DeactivateContents(this);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481141 if (delegate_)
1142 delegate_->LostCapture();
1143}
1144
[email protected]b172aee2012-04-10 17:05:261145bool WebContentsImpl::PreHandleKeyboardEvent(
1146 const NativeWebKeyboardEvent& event,
1147 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481148 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131149 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481150}
1151
[email protected]b172aee2012-04-10 17:05:261152void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481153 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131154 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481155}
1156
[email protected]b172aee2012-04-10 17:05:261157void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431158 if (delegate_)
1159 delegate_->HandleMouseDown();
1160}
1161
[email protected]b172aee2012-04-10 17:05:261162void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481163 if (delegate_)
1164 delegate_->HandleMouseUp();
1165}
1166
[email protected]590a634e2012-07-19 16:38:231167void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481168 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231169 delegate_->HandlePointerActivate();
1170}
1171
1172void WebContentsImpl::HandleGestureBegin() {
1173 if (delegate_)
1174 delegate_->HandleGestureBegin();
1175}
1176
1177void WebContentsImpl::HandleGestureEnd() {
1178 if (delegate_)
1179 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481180}
1181
[email protected]b172aee2012-04-10 17:05:261182void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471183 if (delegate_)
1184 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1185}
1186
[email protected]b172aee2012-04-10 17:05:261187bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381188 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121189}
1190
[email protected]a9c81f02012-06-01 00:15:441191void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1192 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371193 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441194 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371195 } else {
1196 GotResponseToLockMouseRequest(false);
1197 }
1198}
1199
[email protected]b172aee2012-04-10 17:05:261200void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371201 if (delegate_)
1202 delegate_->LostMouseLock();
1203}
1204
[email protected]bafe6cd2012-05-23 23:09:501205void WebContentsImpl::CreateNewWindow(
1206 int route_id,
[email protected]97714c82012-06-06 10:15:131207 const ViewHostMsg_CreateWindow_Params& params,
1208 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501209 if (delegate_ && !delegate_->ShouldCreateWebContents(
1210 this, route_id, params.window_container_type, params.frame_name,
1211 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091212 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501213 return;
1214 }
1215
1216 // We usually create the new window in the same BrowsingInstance (group of
1217 // script-related windows), by passing in the current SiteInstance. However,
1218 // if the opener is being suppressed, we create a new SiteInstance in its own
1219 // BrowsingInstance.
1220 scoped_refptr<SiteInstance> site_instance =
1221 params.opener_suppressed ?
1222 SiteInstance::Create(GetBrowserContext()) :
1223 GetSiteInstance();
1224
1225 // Create the new web contents. This will automatically create the new
1226 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191227 WebContentsImpl* new_contents =
1228 new WebContentsImpl(GetBrowserContext(),
1229 params.opener_suppressed ? NULL : this);
1230
1231 // We must assign the SessionStorageNamespace before calling Init().
1232 const std::string& partition_id =
1233 content::GetContentClient()->browser()->
1234 GetStoragePartitionIdForSiteInstance(GetBrowserContext(),
1235 site_instance);
1236 DOMStorageContextImpl* dom_storage_context =
1237 static_cast<DOMStorageContextImpl*>(
1238 BrowserContext::GetDOMStorageContextByPartitionId(
1239 GetBrowserContext(), partition_id));
1240 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1241 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1242 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1243 new_contents->GetController().SetSessionStorageNamespace(
1244 partition_id,
1245 session_storage_namespace);
1246 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1247
[email protected]bafe6cd2012-05-23 23:09:501248 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1249
1250 if (!params.opener_suppressed) {
1251 content::WebContentsView* new_view = new_contents->GetView();
1252
1253 // TODO(brettw): It seems bogus that we have to call this function on the
1254 // newly created object and give it one of its own member variables.
1255 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1256
1257 // Save the created window associated with the route so we can show it
1258 // later.
1259 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1260 pending_contents_[route_id] = new_contents;
1261 }
1262
1263 if (delegate_) {
1264 delegate_->WebContentsCreated(
1265 this, params.opener_frame_id, params.target_url, new_contents);
1266 }
1267
1268 if (params.opener_suppressed) {
1269 // When the opener is suppressed, the original renderer cannot access the
1270 // new window. As a result, we need to show and navigate the window here.
1271 gfx::Rect initial_pos;
1272 AddNewContents(
1273 new_contents, params.disposition, initial_pos, params.user_gesture);
1274
1275 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1276 CURRENT_TAB,
1277 content::PAGE_TRANSITION_LINK,
1278 true /* is_renderer_initiated */);
1279 new_contents->OpenURL(open_params);
1280 }
1281}
1282
1283void WebContentsImpl::CreateNewWidget(int route_id,
1284 WebKit::WebPopupType popup_type) {
1285 CreateNewWidget(route_id, false, popup_type);
1286}
1287
1288void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1289 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1290}
1291
1292void WebContentsImpl::CreateNewWidget(int route_id,
1293 bool is_fullscreen,
1294 WebKit::WebPopupType popup_type) {
1295 content::RenderProcessHost* process = GetRenderProcessHost();
1296 RenderWidgetHostImpl* widget_host =
1297 new RenderWidgetHostImpl(this, process, route_id);
1298 RenderWidgetHostViewPort* widget_view =
1299 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1300 if (!is_fullscreen) {
1301 // Popups should not get activated.
1302 widget_view->SetPopupType(popup_type);
1303 }
1304 // Save the created widget associated with the route so we can show it later.
1305 pending_widget_views_[route_id] = widget_view;
1306
1307#if defined(OS_MACOSX)
1308 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1309 // to allow it to survive the trip without being hosted.
1310 base::mac::NSObjectRetain(widget_view->GetNativeView());
1311#endif
1312}
1313
1314void WebContentsImpl::ShowCreatedWindow(int route_id,
1315 WindowOpenDisposition disposition,
1316 const gfx::Rect& initial_pos,
1317 bool user_gesture) {
1318 WebContentsImpl* contents = GetCreatedWindow(route_id);
1319 if (contents)
1320 AddNewContents(contents, disposition, initial_pos, user_gesture);
1321}
1322
1323void WebContentsImpl::ShowCreatedWidget(int route_id,
1324 const gfx::Rect& initial_pos) {
1325 ShowCreatedWidget(route_id, false, initial_pos);
1326}
1327
1328void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1329 ShowCreatedWidget(route_id, true, gfx::Rect());
1330}
1331
1332void WebContentsImpl::ShowCreatedWidget(int route_id,
1333 bool is_fullscreen,
1334 const gfx::Rect& initial_pos) {
1335 if (delegate_)
1336 delegate_->RenderWidgetShowing();
1337
1338 RenderWidgetHostViewPort* widget_host_view =
1339 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1340 if (!widget_host_view)
1341 return;
1342 if (is_fullscreen) {
1343 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1344 } else {
1345 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1346 }
[email protected]89054502012-06-03 10:29:241347
1348 RenderWidgetHostImpl* render_widget_host_impl =
1349 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1350 render_widget_host_impl->Init();
1351 // Only allow privileged mouse lock for fullscreen render widget, which is
1352 // used to implement Pepper Flash fullscreen.
1353 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501354
1355#if defined(OS_MACOSX)
1356 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1357 // properly embedded (or purposefully ignored) we can release the retain we
1358 // took in CreateNewWidget().
1359 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1360#endif
1361}
1362
1363WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1364 PendingContents::iterator iter = pending_contents_.find(route_id);
1365
1366 // Certain systems can block the creation of new windows. If we didn't succeed
1367 // in creating one, just return NULL.
1368 if (iter == pending_contents_.end()) {
1369 return NULL;
1370 }
1371
1372 WebContentsImpl* new_contents = iter->second;
1373 pending_contents_.erase(route_id);
1374
1375 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1376 !new_contents->GetRenderViewHost()->GetView())
1377 return NULL;
1378
1379 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1380 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1381 return new_contents;
1382}
1383
1384RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1385 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1386 if (iter == pending_widget_views_.end()) {
1387 DCHECK(false);
1388 return NULL;
1389 }
1390
1391 RenderWidgetHostView* widget_host_view = iter->second;
1392 pending_widget_views_.erase(route_id);
1393
1394 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1395 if (!widget_host->GetProcess()->HasConnection()) {
1396 // The view has gone away or the renderer crashed. Nothing to do.
1397 return NULL;
1398 }
1399
1400 return widget_host_view;
1401}
1402
1403void WebContentsImpl::ShowContextMenu(
1404 const content::ContextMenuParams& params) {
1405 // Allow WebContentsDelegates to handle the context menu operation first.
1406 if (delegate_ && delegate_->HandleContextMenu(params))
1407 return;
1408
[email protected]5a3bdf52012-05-24 15:12:571409 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501410}
1411
[email protected]f13b4202012-06-12 23:53:231412void WebContentsImpl::RequestMediaAccessPermission(
1413 const content::MediaStreamRequest* request,
1414 const content::MediaResponseCallback& callback) {
1415 if (delegate_)
1416 delegate_->RequestMediaAccessPermission(this, request, callback);
1417 else
1418 callback.Run(content::MediaStreamDevices());
1419}
1420
[email protected]b172aee2012-04-10 17:05:261421void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231422 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331423 if (delegate_)
1424 delegate_->UpdatePreferredSize(this, pref_size);
1425}
1426
[email protected]b172aee2012-04-10 17:05:261427void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341428 if (delegate_)
1429 delegate_->ResizeDueToAutoResize(this, new_size);
1430}
1431
[email protected]b172aee2012-04-10 17:05:261432WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201433 if (!delegate_)
1434 return NULL;
[email protected]00c37fc2011-08-02 00:22:501435
[email protected]e5d549d2011-12-28 01:29:201436 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1437 // Notify observers.
1438 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1439 DidOpenURL(params.url, params.referrer,
1440 params.disposition, params.transition));
1441 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341442}
1443
[email protected]b172aee2012-04-10 17:05:261444bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501445 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251446 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231447 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251448 reload_type);
[email protected]876bc832010-09-07 16:29:541449}
[email protected]96d185d2009-04-24 03:28:541450
[email protected]ba45bfd2012-05-22 21:51:441451void WebContentsImpl::RenderViewForInterstitialPageCreated(
1452 content::RenderViewHost* render_view_host) {
1453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1454 RenderViewForInterstitialPageCreated(render_view_host));
1455}
1456
[email protected]b172aee2012-04-10 17:05:261457bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231458 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501459 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401460 // The renderer will reject IPC messages with URLs longer than
1461 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511462 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401463 return false;
1464
[email protected]9f76c1e2012-03-05 15:15:581465 RenderViewHostImpl* dest_render_view_host =
1466 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401467 if (!dest_render_view_host)
1468 return false; // Unable to create the desired render view host.
1469
[email protected]80a8fad2011-01-29 04:02:381470 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071471 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581472 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501473 WebUIControllerFactory* factory =
1474 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271475 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501476 bool is_allowed_in_web_ui_renderer =
1477 factory &&
[email protected]24e18252012-04-16 21:26:271478 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1479 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231480 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1481 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271482 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231483 content::GetContentClient()->SetActiveURL(entry.GetURL());
1484 CHECK(0);
1485 }
[email protected]54ec6472010-04-09 19:39:581486
[email protected]96d185d2009-04-24 03:28:541487 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441488 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521489 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441490 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511491 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541492
[email protected]7bb761892012-07-20 09:32:471493 // Notify observers that we will navigate in this RV.
1494 FOR_EACH_OBSERVER(WebContentsObserver,
1495 observers_,
1496 AboutToNavigateRenderView(dest_render_view_host));
1497
[email protected]96d185d2009-04-24 03:28:541498 // Used for page load time metrics.
1499 current_load_start_ = base::TimeTicks::Now();
1500
1501 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241502 std::string embedder_channel_name;
1503 int embedder_container_id;
1504 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1505 &embedder_channel_name,
1506 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341507 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271508 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241509 embedder_channel_name,
1510 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471511 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341512 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541513
[email protected]36fc0392011-12-25 03:59:511514 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541515 // HACK!! This code suppresses javascript: URLs from being added to
1516 // session history, which is what we want to do for javascript: URLs that
1517 // do not generate content. What we really need is a message from the
1518 // renderer telling us that a new page was not created. The same message
1519 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511520 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541521 return false;
1522 }
1523
[email protected]3c9e1872010-11-18 16:17:491524 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251525 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041526 observers_,
[email protected]36fc0392011-12-25 03:59:511527 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541528
[email protected]09b29342011-06-24 19:18:481529 if (delegate_)
1530 delegate_->DidNavigateToPendingEntry(this);
1531
[email protected]d5f942ba2008-09-26 19:30:341532 return true;
1533}
1534
[email protected]b172aee2012-04-10 17:05:261535void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331536 const SiteInstance* site_instance,
1537 int history_length,
1538 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411539 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1540 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191541 if (render_manager_.pending_render_view_host()) {
1542 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141543 return;
[email protected]9e1ad4b2011-08-14 16:49:191544 }
[email protected]9f76c1e2012-03-05 15:15:581545 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191546 if (!rvh) {
1547 NOTREACHED();
1548 return;
1549 }
[email protected]9f76c1e2012-03-05 15:15:581550 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191551 NOTREACHED();
1552 return;
1553 }
[email protected]9f76c1e2012-03-05 15:15:581554 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191555 history_length,
1556 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141557}
1558
[email protected]b172aee2012-04-10 17:05:261559void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271560 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541561 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1562 return;
1563 }
[email protected]9f76c1e2012-03-05 15:15:581564 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541565}
1566
[email protected]b172aee2012-04-10 17:05:261567bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271568 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541569}
1570
[email protected]b172aee2012-04-10 17:05:261571InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271572 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221573}
1574
[email protected]b172aee2012-04-10 17:05:261575bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161576 // WebKit creates Document object when MIME type is application/xhtml+xml,
1577 // so we also support this MIME type.
1578 return contents_mime_type_ == "text/html" ||
1579 contents_mime_type_ == "text/xml" ||
1580 contents_mime_type_ == "application/xhtml+xml" ||
1581 contents_mime_type_ == "text/plain" ||
1582 contents_mime_type_ == "text/css" ||
1583 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1584}
1585
[email protected]b172aee2012-04-10 17:05:261586void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591587 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161588 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481589 download_stats::RecordDownloadSource(
1590 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461591 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141592 return;
[email protected]c7dd2f62011-07-18 15:57:591593 }
1594
1595 Stop();
1596
1597 // Create the save package and possibly prompt the user for the name to save
1598 // the page as. The user prompt is an asynchronous operation that runs on
1599 // another thread.
1600 save_package_ = new SavePackage(this);
1601 save_package_->GetSaveInfo();
1602}
1603
1604// Used in automated testing to bypass prompting the user for file names.
1605// Instead, the names and paths are hard coded rather than running them through
1606// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261607bool WebContentsImpl::SavePage(const FilePath& main_file,
1608 const FilePath& dir_path,
1609 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591610 // Stop the page from navigating.
1611 Stop();
1612
1613 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271614 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591615}
1616
[email protected]b172aee2012-04-10 17:05:261617void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121618 const FilePath& file,
1619 const base::Callback<void(const FilePath&, int64)>& callback) {
1620 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1621}
1622
[email protected]b172aee2012-04-10 17:05:261623bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231624 NavigationEntryImpl* active_entry =
1625 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321626 return (active_entry != NULL &&
1627 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511628 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321629}
1630
[email protected]b172aee2012-04-10 17:05:261631const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271632 return contents_mime_type_;
1633}
1634
[email protected]b172aee2012-04-10 17:05:261635bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271636 return notify_disconnection_;
1637}
1638
[email protected]b172aee2012-04-10 17:05:261639void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311640 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581641 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1642 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161643}
1644
[email protected]b172aee2012-04-10 17:05:261645void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311646 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581647 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1648 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161649}
1650
[email protected]b172aee2012-04-10 17:05:261651content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271652 return &renderer_preferences_;
1653}
1654
[email protected]b172aee2012-04-10 17:05:261655void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271656 new_tab_start_time_ = time;
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271660 return new_tab_start_time_;
1661}
1662
[email protected]e35ccd52012-05-23 16:22:471663void WebContentsImpl::Close() {
1664 Close(GetRenderViewHost());
1665}
1666
[email protected]b172aee2012-04-10 17:05:261667void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151668 if (close_start_time_.is_null())
1669 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011670}
1671
[email protected]b172aee2012-04-10 17:05:261672bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191673#if defined(OS_CHROMEOS)
1674 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1675 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511676 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201677 return false;
1678 return true;
[email protected]46624bf2010-06-09 16:04:191679#else
1680 return true;
1681#endif
1682}
1683
[email protected]b172aee2012-04-10 17:05:261684void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521685 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581686 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511687 if (delegate_)
1688 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341689}
1690
[email protected]e35ccd52012-05-23 16:22:471691void WebContentsImpl::UserGestureDone() {
1692 OnUserGesture();
1693}
1694
[email protected]b172aee2012-04-10 17:05:261695void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271696 closed_by_user_gesture_ = value;
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271700 return closed_by_user_gesture_;
1701}
1702
[email protected]b172aee2012-04-10 17:05:261703double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051704 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561705 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251706 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171707 return 0;
[email protected]b75b8292010-10-01 07:28:251708
1709 double zoom_level;
1710 if (temporary_zoom_settings_) {
1711 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581712 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251713 } else {
[email protected]2ae88d12011-10-14 09:11:191714 GURL url;
[email protected]10f417c52011-12-28 21:04:231715 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191716 // Since zoom map is updated using rewritten URL, use rewritten URL
1717 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511718 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191719 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251720 }
[email protected]d0b8d092010-10-25 04:05:171721 return zoom_level;
1722}
[email protected]b75b8292010-10-01 07:28:251723
[email protected]b172aee2012-04-10 17:05:261724int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1725 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171726 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011727 // Calculate the zoom percent from the factor. Round up to the nearest whole
1728 // number.
[email protected]b75b8292010-10-01 07:28:251729 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011730 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251731 *enable_decrement = percent > minimum_zoom_percent_;
1732 *enable_increment = percent < maximum_zoom_percent_;
1733 return percent;
1734}
1735
[email protected]b172aee2012-04-10 17:05:261736void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501737 if (!delegate_)
1738 return;
1739
[email protected]10f417c52011-12-28 21:04:231740 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501741 if (!active_entry)
1742 return;
1743
[email protected]36fc0392011-12-25 03:59:511744 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121745}
1746
[email protected]b172aee2012-04-10 17:05:261747void WebContentsImpl::ViewFrameSource(const GURL& url,
1748 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271749 if (!delegate_)
1750 return;
1751
1752 delegate_->ViewSourceForFrame(this, url, content_state);
1753}
1754
[email protected]b172aee2012-04-10 17:05:261755int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271756 return minimum_zoom_percent_;
1757}
1758
[email protected]b172aee2012-04-10 17:05:261759int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271760 return maximum_zoom_percent_;
1761}
1762
[email protected]b172aee2012-04-10 17:05:261763gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231764 return preferred_size_;
1765}
1766
[email protected]b172aee2012-04-10 17:05:261767int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271768 return content_restrictions_;
1769}
1770
[email protected]b172aee2012-04-10 17:05:261771WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501772 WebUIControllerFactory* factory =
1773 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1774 if (!factory)
1775 return WebUI::kNoWebUI;
1776 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271777}
1778
[email protected]b172aee2012-04-10 17:05:261779content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271780 // When there is a pending navigation entry, we want to use the pending WebUI
1781 // that goes along with it to control the basic flags. For example, we want to
1782 // show the pending URL in the URL bar, so we want the display_url flag to
1783 // be from the pending entry.
1784 //
1785 // The confusion comes because there are multiple possibilities for the
1786 // initial load in a tab as a side effect of the way the RenderViewHostManager
1787 // works.
1788 //
1789 // - For the very first tab the load looks "normal". The new tab Web UI is
1790 // the pending one, and we want it to apply here.
1791 //
1792 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1793 // get switched to the one previously associated with the new tab pages.
1794 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1795 // have a committed Web UI in this case.
1796 //
1797 // This condition handles all of these cases:
1798 //
1799 // - First load in first tab: no committed nav entry + pending nav entry +
1800 // pending dom ui:
1801 // -> Use pending Web UI if any.
1802 //
1803 // - First load in second tab: no committed nav entry + pending nav entry +
1804 // no pending Web UI:
1805 // -> Use the committed Web UI if any.
1806 //
1807 // - Second navigation in any tab: committed nav entry + pending nav entry:
1808 // -> Use pending Web UI if any.
1809 //
1810 // - Normal state with no load: committed nav entry + no pending nav entry:
1811 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251812 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271813 (controller_.GetLastCommittedEntry() ||
1814 render_manager_.pending_web_ui()))
1815 return render_manager_.pending_web_ui();
1816 return render_manager_.web_ui();
1817}
1818
[email protected]b172aee2012-04-10 17:05:261819bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271820 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581821 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271822}
1823
[email protected]b172aee2012-04-10 17:05:261824bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441825 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501826}
1827
[email protected]b172aee2012-04-10 17:05:261828void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321829 SkColor color) {
[email protected]da8543762012-03-20 08:52:201830 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1831 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1832}
1833
[email protected]b172aee2012-04-10 17:05:261834void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201835 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1836 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1837 if (delegate_)
1838 delegate_->DidEndColorChooser();
1839 color_chooser_ = NULL;
1840}
1841
[email protected]b172aee2012-04-10 17:05:261842bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471843 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271844 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221845 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231846 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411847 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271848}
1849
[email protected]b172aee2012-04-10 17:05:261850void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271851 if (delegate_)
1852 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211853}
1854
[email protected]3a3b75a2012-06-01 08:38:361855void WebContentsImpl::OnRegisterIntentService(
1856 const webkit_glue::WebIntentServiceData& data,
1857 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431858 if (delegate_)
1859 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301860}
1861
[email protected]b172aee2012-04-10 17:05:261862void WebContentsImpl::OnWebIntentDispatch(
1863 const webkit_glue::WebIntentData& intent,
1864 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431865 if (!delegate_)
1866 return;
1867
[email protected]0d9989d2011-12-21 20:26:001868 WebIntentsDispatcherImpl* intents_dispatcher =
1869 new WebIntentsDispatcherImpl(this, intent, intent_id);
1870 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301871}
1872
[email protected]54047eb52012-05-08 21:45:571873void WebContentsImpl::DidStartProvisionalLoadForFrame(
1874 content::RenderViewHost* render_view_host,
1875 int64 frame_id,
1876 bool is_main_frame,
1877 const GURL& opener_url,
1878 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281879 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181880 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451881 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571882 content::RenderProcessHost* render_process_host =
1883 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541884 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571885 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451886 false,
[email protected]9f76c1e2012-03-05 15:15:581887 &validated_url);
[email protected]ef108e72012-06-20 14:03:541888 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571889 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451890 true,
1891 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181892
[email protected]0d60f0192011-04-14 12:40:101893 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251894 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101895 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571896 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541897
1898 if (is_main_frame) {
1899 // Notify observers about the provisional change in the main frame URL.
1900 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1901 ProvisionalChangeToMainFrameUrl(validated_url,
1902 validated_opener_url,
1903 render_view_host));
1904 }
1905}
1906
1907void WebContentsImpl::DidRedirectProvisionalLoad(
1908 content::RenderViewHost* render_view_host,
1909 int32 page_id,
1910 const GURL& opener_url,
1911 const GURL& source_url,
1912 const GURL& target_url) {
1913 // TODO(creis): Remove this method and have the pre-rendering code listen to
1914 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1915 // instead. See http://crbug.com/78512.
1916 GURL validated_source_url(source_url);
1917 GURL validated_target_url(target_url);
1918 GURL validated_opener_url(opener_url);
1919 content::RenderProcessHost* render_process_host =
1920 render_view_host->GetProcess();
1921 RenderViewHostImpl::FilterURL(
1922 ChildProcessSecurityPolicyImpl::GetInstance(),
1923 render_process_host->GetID(),
1924 false,
1925 &validated_source_url);
1926 RenderViewHostImpl::FilterURL(
1927 ChildProcessSecurityPolicyImpl::GetInstance(),
1928 render_process_host->GetID(),
1929 false,
1930 &validated_target_url);
1931 RenderViewHostImpl::FilterURL(
1932 ChildProcessSecurityPolicyImpl::GetInstance(),
1933 render_process_host->GetID(),
1934 true,
1935 &validated_opener_url);
1936 NavigationEntry* entry;
1937 if (page_id == -1) {
1938 entry = controller_.GetPendingEntry();
1939 } else {
1940 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1941 page_id);
1942 }
1943 if (!entry || entry->GetURL() != validated_source_url)
1944 return;
1945
1946 // Notify observers about the provisional change in the main frame URL.
1947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1948 ProvisionalChangeToMainFrameUrl(validated_target_url,
1949 validated_opener_url,
1950 render_view_host));
[email protected]724159a2010-12-30 01:11:181951}
1952
[email protected]54047eb52012-05-08 21:45:571953void WebContentsImpl::DidFailProvisionalLoadWithError(
1954 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581955 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1956 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1957 << ", error_code: " << params.error_code
1958 << ", error_description: " << params.error_description
1959 << ", is_main_frame: " << params.is_main_frame
1960 << ", showing_repost_interstitial: " <<
1961 params.showing_repost_interstitial
1962 << ", frame_id: " << params.frame_id;
1963 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571964 content::RenderProcessHost* render_process_host =
1965 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541966 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571967 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451968 false,
[email protected]9f76c1e2012-03-05 15:15:581969 &validated_url);
[email protected]724159a2010-12-30 01:11:181970
[email protected]d7b175e2011-10-11 15:31:581971 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181972 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1973 // This means that the interstitial won't be torn down properly, which is
1974 // bad. But if we have an interstitial, go back to another tab type, and
1975 // then load the same interstitial again, we could end up getting the first
1976 // interstitial's "failed" message (as a result of the cancel) when we're on
1977 // the second one.
1978 //
1979 // We can't tell this apart, so we think we're tearing down the current page
1980 // which will cause a crash later one. There is also some code in
1981 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1982 // out because of this problem.
1983 //
1984 // http://code.google.com/p/chromium/issues/detail?id=2855
1985 // Because this will not tear down the interstitial properly, if "back" is
1986 // back to another tab type, the interstitial will still be somewhat alive
1987 // in the previous tab type. If you navigate somewhere that activates the
1988 // tab with the interstitial again, you'll see a flash before the new load
1989 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271990 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181991 LOG(WARNING) << "Discarding message during interstitial.";
1992 return;
1993 }
1994
[email protected]a16690732012-07-13 19:22:171995 // Do not clear the pending entry if one exists, so that the user's typed
1996 // URL is not lost when a navigation fails or is aborted. We'll allow
1997 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:181998
[email protected]54047eb52012-05-08 21:45:571999 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182000 }
2001
[email protected]d8c660432011-12-22 20:51:252002 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582003 observers_,
2004 DidFailProvisionalLoad(params.frame_id,
2005 params.is_main_frame,
2006 validated_url,
2007 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462008 params.error_description,
2009 render_view_host));
[email protected]724159a2010-12-30 01:11:182010}
2011
[email protected]b172aee2012-04-10 17:05:262012void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182013 const GURL& url,
[email protected]70435962011-08-02 20:13:282014 const std::string& security_info,
2015 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182016 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282017 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192018 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182019 cache.Increment();
2020
2021 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082022 int cert_id = 0;
2023 net::CertStatus cert_status = 0;
2024 int security_bits = -1;
2025 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512026 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2027 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002028 content::LoadFromMemoryCacheDetails details(
2029 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2030 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182031
[email protected]ad50def52011-10-19 23:17:072032 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272033 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502034 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002035 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382039 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182040 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192041 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182042}
2043
[email protected]b172aee2012-04-10 17:05:262044void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022045 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232046 LOG(INFO) << security_origin << " ran insecure content from "
2047 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382048 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412049 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2050 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182051 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412052 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192053 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182054}
2055
[email protected]b172aee2012-04-10 17:05:262056void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182057 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252058 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472059 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182060}
2061
[email protected]b172aee2012-04-10 17:05:262062void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312063 int64 frame_id,
2064 const GURL& validated_url,
2065 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252066 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472067 DidFinishLoad(frame_id, validated_url, is_main_frame,
2068 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312069}
2070
[email protected]b172aee2012-04-10 17:05:262071void WebContentsImpl::OnDidFailLoadWithError(
2072 int64 frame_id,
2073 const GURL& validated_url,
2074 bool is_main_frame,
2075 int error_code,
2076 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252077 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312078 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472079 error_code, error_description,
2080 message_source_));
[email protected]724159a2010-12-30 01:11:182081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272084 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432085 if (delegate_)
2086 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172087}
2088
[email protected]b172aee2012-04-10 17:05:262089void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262090 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232091 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252092 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262093 if (!entry)
2094 return;
2095 // Note that we don't call NavigationController::GotToOffset() as we don't
2096 // want to create a pending navigation entry (it might end up lingering
2097 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252098 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582099 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512100 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582101 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472102 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572103
2104 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2105 // it in now that we know. This allows us to find the entry when it commits.
2106 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232107 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332108 entry->set_site_instance(
2109 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572110 }
[email protected]216813952011-05-19 22:21:262111 }
2112}
2113
[email protected]b172aee2012-04-10 17:05:262114void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2115 int maximum_percent,
2116 bool remember) {
[email protected]216813952011-05-19 22:21:262117 minimum_zoom_percent_ = minimum_percent;
2118 maximum_zoom_percent_ = maximum_percent;
2119 temporary_zoom_settings_ = !remember;
2120}
2121
[email protected]20b433a2012-05-15 21:23:462122void WebContentsImpl::OnSaveURL(const GURL& url,
2123 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482124 download_stats::RecordDownloadSource(
2125 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262126 // Check if the URL to save matches the URL of the main frame. Since this
2127 // message originates from Pepper plugins, it may not be the case if the
2128 // plugin is an embedded element.
2129 GURL main_frame_url = GetURL();
2130 if (!main_frame_url.is_valid())
2131 return;
2132 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462133 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::OnEnumerateDirectory(int request_id,
2137 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432138 if (!delegate_)
2139 return;
2140
[email protected]b9535422012-02-09 01:47:592141 ChildProcessSecurityPolicyImpl* policy =
2142 ChildProcessSecurityPolicyImpl::GetInstance();
2143 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2144 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432148 if (delegate_)
2149 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202150}
2151
[email protected]b172aee2012-04-10 17:05:262152void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2153 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362154 const string16& title,
2155 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432156 if (!delegate_)
2157 return;
2158
[email protected]b9535422012-02-09 01:47:592159 ChildProcessSecurityPolicyImpl* policy =
2160 ChildProcessSecurityPolicyImpl::GetInstance();
2161 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2162 return;
[email protected]3a3b75a2012-06-01 08:38:362163 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202164}
2165
[email protected]b172aee2012-04-10 17:05:262166void WebContentsImpl::OnFindReply(int request_id,
2167 int number_of_matches,
2168 const gfx::Rect& selection_rect,
2169 int active_match_ordinal,
2170 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432171 if (delegate_) {
2172 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2173 active_match_ordinal, final_update);
2174 }
[email protected]b888919c2011-09-02 00:32:162175}
2176
[email protected]b172aee2012-04-10 17:05:262177void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442178 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2179 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452180}
2181
[email protected]b172aee2012-04-10 17:05:262182void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2183 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102184 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252185 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102186 AppCacheAccessed(manifest_url, blocked_by_policy));
2187}
2188
[email protected]b172aee2012-04-10 17:05:262189void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322190 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432191 color_chooser_ = delegate_ ?
2192 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202196 if (color_chooser_ &&
2197 color_chooser_id == color_chooser_->identifier())
2198 color_chooser_->End();
2199}
2200
[email protected]b172aee2012-04-10 17:05:262201void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322202 SkColor color) {
[email protected]da8543762012-03-20 08:52:202203 if (color_chooser_ &&
2204 color_chooser_id == color_chooser_->identifier())
2205 color_chooser_->SetSelectedColor(color);
2206}
2207
[email protected]9f2a9d72012-04-16 16:02:222208void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2209 const FilePath& path,
2210 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442211 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2212 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292213}
2214
[email protected]d0759f492012-04-19 22:50:502215// This exists for render views that don't have a WebUI, but do have WebUI
2216// bindings enabled.
2217void WebContentsImpl::OnWebUISend(const GURL& source_url,
2218 const std::string& name,
2219 const base::ListValue& args) {
2220 if (delegate_)
2221 delegate_->WebUISend(this, source_url, name, args);
2222}
2223
[email protected]96d185d2009-04-24 03:28:542224// Notifies the RenderWidgetHost instance about the fact that the page is
2225// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262226void WebContentsImpl::SetIsLoading(bool is_loading,
2227 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542228 if (is_loading == is_loading_)
2229 return;
2230
2231 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212232 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542233 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562234 upload_size_ = 0;
2235 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542236 }
2237
2238 render_manager_.SetIsLoading(is_loading);
2239
2240 is_loading_ = is_loading;
2241 waiting_for_response_ = is_loading;
2242
[email protected]6ebdc9b2010-09-27 16:55:572243 if (delegate_)
2244 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462245 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542246
[email protected]432115822011-07-10 15:52:272247 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2248 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072249 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542250 if (details)
[email protected]6c2381d2011-10-19 02:52:532251 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072252 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502253 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542254 det);
2255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132258 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322259 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562260 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382261 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442262 // that opened the window, as long as both renderers have the same
2263 // privileges.
[email protected]1fd1a502011-03-30 16:55:562264 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562265 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582266 // web_ui might be NULL if the URL refers to a non-existent extension.
2267 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402268 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522269 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442270 }
2271 }
[email protected]1fd1a502011-03-30 16:55:562272 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442273 }
2274
[email protected]4e697b042011-07-08 06:44:562275 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322276 // Clear the status bubble. This is a workaround for a bug where WebKit
2277 // doesn't let us know that the cursor left an element during a
2278 // transition (this is also why the mouse cursor remains as a hand after
2279 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2280 // clear the bubble when a user navigates to a named anchor in the same
2281 // page.
[email protected]36fc0392011-12-25 03:59:512282 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322283 }
2284
[email protected]a6e82fc2010-02-24 22:28:142285 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472286 // Once the main frame is navigated, we're no longer considered to have
2287 // displayed insecure content.
2288 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172289 }
[email protected]ce5c4502009-05-06 16:46:112290
[email protected]3c9e1872010-11-18 16:17:492291 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042293 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322297 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132298 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322299 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062300 // If we navigate off the page, reset JavaScript state. This does nothing
2301 // to prevent a malicious script from spamming messages, since the script
2302 // could just reload the page to stop blocking.
2303 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552304 dialog_creator_->ResetJavaScriptState(this);
2305 dialog_creator_ = NULL;
2306 }
[email protected]420ae012009-04-24 05:16:322307
[email protected]3c9e1872010-11-18 16:17:492308 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252309 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042310 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462314 // If we are creating a RVH for a restored controller, then we need to make
2315 // sure the RenderView starts with a next_page_id_ larger than the number
2316 // of restored entries. This must be called before the RenderView starts
2317 // navigating (to avoid a race between the browser updating max_page_id and
2318 // the renderer updating next_page_id_). Because of this, we only call this
2319 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562320 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582321 if (max_restored_page_id >
2322 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2323 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2324 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322325}
2326
[email protected]b172aee2012-04-10 17:05:262327bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2328 const string16& title) {
[email protected]420ae012009-04-24 05:16:322329 // For file URLs without a title, use the pathname instead. In the case of a
2330 // synthesized title, we don't want the update to count toward the "one set
2331 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512332 string16 final_title;
[email protected]420ae012009-04-24 05:16:322333 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512334 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2335 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322336 explicit_set = false; // Don't count synthetic titles toward the set limit.
2337 } else {
[email protected]acafd272011-07-26 17:35:572338 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322339 explicit_set = true;
2340 }
2341
[email protected]987fc3a2011-05-26 14:18:092342 // If a page is created via window.open and never navigated,
2343 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552344 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092345 if (entry) {
[email protected]36fc0392011-12-25 03:59:512346 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092347 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322348
[email protected]36fc0392011-12-25 03:59:512349 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092350 } else {
2351 if (page_title_when_no_navigation_entry_ == final_title)
2352 return false; // Nothing changed, don't bother.
2353
2354 page_title_when_no_navigation_entry_ = final_title;
2355 }
[email protected]420ae012009-04-24 05:16:322356
[email protected]420ae012009-04-24 05:16:322357 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232358 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322359
[email protected]2bb171882012-03-07 02:09:462360 std::pair<content::NavigationEntry*, bool> details =
2361 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142362
[email protected]ad50def52011-10-19 23:17:072363 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442364 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2365 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462366 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042367
[email protected]420ae012009-04-24 05:16:322368 return true;
2369}
2370
[email protected]b172aee2012-04-10 17:05:262371void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322372 // After sending out a swap notification, we need to send a disconnect
2373 // notification so that clients that pick up a pointer to |this| can NULL the
2374 // pointer. See Bug 1230284.
2375 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072376 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202377 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2378 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072379 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322380}
2381
[email protected]b172aee2012-04-10 17:05:262382void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322383 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072384 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122385 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2386 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072387 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322391 if (!notify_disconnection_)
2392 return;
2393
2394 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072395 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322396 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2397 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072398 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322399}
2400
[email protected]5a3bdf52012-05-24 15:12:572401RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2402 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322403}
2404
[email protected]8d3347f2009-07-09 22:00:212405RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262406WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212407 return &render_manager_;
2408}
2409
[email protected]b172aee2012-04-10 17:05:262410content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372411 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462412 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512413}
2414
[email protected]b172aee2012-04-10 17:05:262415WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172416 return this;
2417}
2418
[email protected]b172aee2012-04-10 17:05:262419gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172420 if (delegate_)
2421 return delegate_->GetRootWindowResizerRect();
2422 return gfx::Rect();
2423}
2424
[email protected]b172aee2012-04-10 17:05:262425void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442426 // Don't send notifications if we are just creating a swapped-out RVH for
2427 // the opener chain. These won't be used for view-source or WebUI, so it's
2428 // ok to return early.
2429 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2430 return;
2431
[email protected]ad50def52011-10-19 23:17:072432 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302433 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322434 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532435 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232436 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322437 if (!entry)
2438 return;
2439
2440 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352441 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562442 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582443 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322444
2445 if (entry->IsViewSourceMode()) {
2446 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582447 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2448 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322449 }
[email protected]0666aef2009-05-13 19:48:082450
[email protected]d487beefe2011-12-21 05:41:212451 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262452
2453 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252454 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322455}
2456
[email protected]b172aee2012-04-10 17:05:262457void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522458 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322459 // Don't notify the world, since this came from a renderer in the
2460 // background.
2461 return;
2462 }
2463
2464 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312465 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232466 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302467
2468 // Restore the focus to the tab (otherwise the focus will be on the top
2469 // window).
[email protected]484ae5912010-09-29 19:16:142470 if (was_crashed && !FocusLocationBarByDefault() &&
2471 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302472 Focus();
[email protected]484ae5912010-09-29 19:16:142473 }
[email protected]32ded2212011-11-10 18:51:432474
[email protected]d8c660432011-12-22 20:51:252475 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322476}
2477
[email protected]b172aee2012-04-10 17:05:262478void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2479 base::TerminationStatus status,
2480 int error_code) {
[email protected]151a63d2011-12-20 22:32:522481 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322482 // The pending page's RenderViewHost is gone.
2483 return;
2484 }
2485
2486 SetIsLoading(false, NULL);
2487 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232488 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312489 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322490
[email protected]d8c660432011-12-22 20:51:252491 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272492 observers_,
[email protected]be1f56ab2011-12-22 06:55:312493 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322494}
2495
[email protected]b172aee2012-04-10 17:05:262496void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482497 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252498 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062499}
2500
[email protected]b172aee2012-04-10 17:05:262501void WebContentsImpl::DidNavigate(
2502 RenderViewHost* rvh,
2503 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582504 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322505 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372506
[email protected]434f69f2012-02-06 21:56:522507 // Update the site of the SiteInstance if it doesn't have one yet, unless
2508 // this is for about:blank. In that case, the SiteInstance can still be
2509 // considered unused until a navigation to a real page.
2510 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2511 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332512 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522513 }
[email protected]420ae012009-04-24 05:16:322514
2515 // Need to update MIME type here because it's referred to in
2516 // UpdateNavigationCommands() called by RendererDidNavigate() to
2517 // determine whether or not to enable the encoding menu.
2518 // It's updated only for the main frame. For a subframe,
2519 // RenderView::UpdateURL does not set params.contents_mime_type.
2520 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2521 // TODO(jungshik): Add a test for the encoding menu to avoid
2522 // regressing it again.
[email protected]2905f742011-10-13 03:51:582523 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322524 contents_mime_type_ = params.contents_mime_type;
2525
[email protected]8286f51a2011-05-31 17:39:132526 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002527 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392528
[email protected]a9c0bfe2010-09-17 08:35:222529 // Send notification about committed provisional loads. This notification is
2530 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2531 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082532 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072533 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2534 // that is not recorded in the navigation history. For the purpose of
2535 // tracking navigation events, we treat this event as a sub frame navigation
2536 // event.
2537 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582538 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222539 // Whether or not a page transition was triggered by going backward or
2540 // forward in the history is only stored in the navigation controller's
2541 // entry list.
2542 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512543 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582544 content::PAGE_TRANSITION_FORWARD_BACK)) {
2545 transition_type = content::PageTransitionFromInt(
2546 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222547 }
[email protected]0d60f0192011-04-14 12:40:102548 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252549 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102550 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462551 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222552 }
2553
[email protected]76543b92009-08-31 17:27:452554 if (!did_navigate)
2555 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322556
2557 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2558 // for the appropriate notification (best) or you can add it to
2559 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2560 // necessary, please).
2561
2562 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002563 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322564 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512565 if (delegate_)
2566 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002567 }
[email protected]420ae012009-04-24 05:16:322568 DidNavigateAnyFramePostCommit(rvh, details, params);
2569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2572 int32 page_id,
2573 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152574 // Ensure that this state update comes from either the active RVH or one of
2575 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522576 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322577
2578 // We must be prepared to handle state updates for any page, these occur
2579 // when the user is scrolling and entering form data, as well as when we're
2580 // leaving a page, in which case our state may have already been moved to
2581 // the next page. The navigation controller will look up the appropriate
2582 // NavigationEntry and update it when it is notified via the delegate.
2583
2584 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582585 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322586 if (entry_index < 0)
2587 return;
[email protected]10f417c52011-12-28 21:04:232588 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322589
[email protected]36fc0392011-12-25 03:59:512590 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322591 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512592 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322593 controller_.NotifyEntryChanged(entry, entry_index);
2594}
2595
[email protected]b172aee2012-04-10 17:05:262596void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2597 int32 page_id,
2598 const string16& title,
2599 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322600 // If we have a title, that's a pretty good indication that we've started
2601 // getting useful data.
2602 SetNotWaitingForResponse();
2603
[email protected]73eb2602012-02-09 19:50:552604 // Try to find the navigation entry, which might not be the current one.
2605 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232606 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582607 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092608
[email protected]73eb2602012-02-09 19:50:552609 // We can handle title updates when we don't have an entry in
2610 // UpdateTitleForEntry, but only if the update is from the current RVH.
2611 if (!entry && rvh != GetRenderViewHost())
2612 return;
2613
[email protected]a49e10b2011-08-01 23:57:462614 // TODO(evan): make use of title_direction.
2615 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092616 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322617 return;
2618
2619 // Broadcast notifications when the UI should be updated.
2620 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462621 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322622}
2623
[email protected]b172aee2012-04-10 17:05:262624void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2625 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312626 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322627}
2628
[email protected]b172aee2012-04-10 17:05:262629void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512630 if (delegate_)
2631 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322632}
2633
[email protected]b172aee2012-04-10 17:05:262634void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292635 // The UI may be in an event-tracking loop, such as between the
2636 // mouse-down and mouse-up in text selection or a button click.
2637 // Defer the close until after tracking is complete, so that we
2638 // don't free objects out from under the UI.
2639 // TODO(shess): This could probably be integrated with the
2640 // IsDoingDrag() test below. Punting for now because I need more
2641 // research to understand how this impacts platforms other than Mac.
2642 // TODO(shess): This could get more fine-grained. For instance,
2643 // closing a tab in another window while selecting text in the
2644 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212645 if (GetView()->IsEventTracking()) {
2646 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292647 return;
2648 }
2649
[email protected]24a4d1062009-07-10 23:10:422650 // If we close the tab while we're in the middle of a drag, we'll crash.
2651 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212652 if (GetView()->IsDoingDrag()) {
2653 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422654 return;
2655 }
2656
[email protected]420ae012009-04-24 05:16:322657 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522658 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512659 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322660}
2661
[email protected]b172aee2012-04-10 17:05:262662void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522663 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512664 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572665}
2666
[email protected]b172aee2012-04-10 17:05:262667void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512668 if (delegate_ && delegate_->IsPopupOrPanel(this))
2669 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322670}
2671
[email protected]89793072012-07-23 22:25:292672void WebContentsImpl::DidStartLoading(
2673 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322674 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492675
[email protected]82114f52012-03-20 22:53:412676 if (delegate_ && content_restrictions_)
2677 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492678
2679 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292680 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2681 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322682}
2683
[email protected]89793072012-07-23 22:25:292684void WebContentsImpl::DidStopLoading(
2685 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322686 scoped_ptr<LoadNotificationDetails> details;
2687
[email protected]10f417c52011-12-28 21:04:232688 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322689 // An entry may not exist for a stop when loading an initial blank page or
2690 // if an iframe injected by script into a blank page finishes loading.
2691 if (entry) {
[email protected]420ae012009-04-24 05:16:322692 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2693
2694 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512695 entry->GetVirtualURL(),
2696 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322697 elapsed,
2698 &controller_,
2699 controller_.GetCurrentEntryIndex()));
2700 }
2701
[email protected]420ae012009-04-24 05:16:322702 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492703
2704 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292705 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2706 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322707}
2708
[email protected]b172aee2012-04-10 17:05:262709void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162710 controller_.DiscardNonCommittedEntries();
2711
2712 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462713 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512717 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132718 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402719}
2720
[email protected]87717d0e2012-04-26 02:58:432721void WebContentsImpl::DocumentAvailableInMainFrame(
2722 RenderViewHost* render_view_host) {
2723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2724 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102725}
2726
[email protected]b172aee2012-04-10 17:05:262727void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082728 RenderViewHost* render_view_host,
2729 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072730 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272731 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322732 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532733 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082734}
2735
[email protected]196159d2012-05-04 17:26:542736void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2737 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262738 const content::Referrer& referrer,
2739 WindowOpenDisposition disposition,
2740 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542741 // If this came from a swapped out RenderViewHost, we only allow the request
2742 // if we are still in the same BrowsingInstance.
2743 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2744 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2745 return;
2746 }
2747
[email protected]4ad5d77d2011-12-03 02:00:482748 // Delegate to RequestTransferURL because this is just the generic
2749 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582750 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482751 GlobalRequestID());
2752}
2753
[email protected]b172aee2012-04-10 17:05:262754void WebContentsImpl::RequestTransferURL(
2755 const GURL& url,
2756 const content::Referrer& referrer,
2757 WindowOpenDisposition disposition,
2758 int64 source_frame_id,
2759 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202760 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582761 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582762 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352763 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322764 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2765 // generated suggestions).
2766 //
[email protected]e0112912011-02-02 22:54:352767 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162768 // want web sites to see a referrer of "chrome://blah" (and some
2769 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322770 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432771 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222772 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482773 false /* is_renderer_initiated */);
2774 params.transferred_global_request_id = old_request_id;
2775 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222776 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322777 } else {
[email protected]6bf6a6b52012-02-03 15:41:432778 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482779 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2780 params.transferred_global_request_id = old_request_id;
2781 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582782 }
2783 if (new_contents) {
2784 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252785 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582786 DidOpenRequestedURL(new_contents,
2787 url,
2788 referrer,
2789 disposition,
2790 transition_type,
2791 source_frame_id));
[email protected]420ae012009-04-24 05:16:322792 }
2793}
2794
[email protected]e1c3a552012-05-04 20:51:322795void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2796 // Tell the active RenderViewHost to run unload handlers and close, as long
2797 // as the request came from a RenderViewHost in the same BrowsingInstance.
2798 // In most cases, we receive this from a swapped out RenderViewHost.
2799 // It is possible to receive it from one that has just been swapped in,
2800 // in which case we might as well deliver the message anyway.
2801 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2802 GetRenderViewHost()->ClosePage();
2803}
2804
[email protected]f546640b2012-05-15 00:03:492805void WebContentsImpl::RouteMessageEvent(
2806 RenderViewHost* rvh,
2807 const ViewMsg_PostMessage_Params& params) {
2808 // Only deliver the message to the active RenderViewHost if the request
2809 // came from a RenderViewHost in the same BrowsingInstance.
2810 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2811 return;
2812
2813 ViewMsg_PostMessage_Params new_params(params);
2814
2815 // If there is a source_routing_id, translate it to the routing ID for
2816 // the equivalent swapped out RVH in the target process. If we need
2817 // to create a swapped out RVH for the source tab, we create its opener
2818 // chain as well, since those will also be accessible to the target page.
2819 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2820 // Try to look up the WebContents for the source page.
2821 WebContentsImpl* source_contents = NULL;
2822 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2823 rvh->GetProcess()->GetID(), params.source_routing_id);
2824 if (source_rvh) {
2825 source_contents = static_cast<WebContentsImpl*>(
2826 source_rvh->GetDelegate()->GetAsWebContents());
2827 }
2828
2829 if (source_contents) {
2830 new_params.source_routing_id =
2831 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2832 } else {
2833 // We couldn't find it, so don't pass a source frame.
2834 new_params.source_routing_id = MSG_ROUTING_NONE;
2835 }
2836 }
2837
2838 // In most cases, we receive this from a swapped out RenderViewHost.
2839 // It is possible to receive it from one that has just been swapped in,
2840 // in which case we might as well deliver the message anyway.
2841 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2842 GetRenderViewHost()->GetRoutingID(), new_params));
2843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342846 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412847 const string16& message,
2848 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322849 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142850 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322851 IPC::Message* reply_msg,
2852 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072853 // Suppress JavaScript dialogs when requested. Also suppress messages when
2854 // showing an interstitial as it's shown over the previous page and we don't
2855 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502856 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582857 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272858 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072859 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522860 delegate_->ShouldSuppressDialogs() ||
2861 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322862
2863 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432864 std::string accept_lang = content::GetContentClient()->browser()->
2865 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552866 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522867 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432868 this,
2869 frame_url.GetOrigin(),
2870 accept_lang,
2871 javascript_message_type,
2872 message,
[email protected]51da7e32012-01-30 19:24:522873 default_prompt,
[email protected]b172aee2012-04-10 17:05:262874 base::Bind(&WebContentsImpl::OnDialogClosed,
2875 base::Unretained(this),
2876 rvh,
2877 reply_msg),
[email protected]51da7e32012-01-30 19:24:522878 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322879 }
[email protected]3ab9cb82011-06-03 18:02:072880
2881 if (suppress_this_message) {
2882 // If we are suppressing messages, just reply as if the user immediately
2883 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342884 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072885 }
2886
2887 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322888}
2889
[email protected]b172aee2012-04-10 17:05:262890void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2891 const string16& message,
2892 bool is_reload,
2893 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582894 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512895 if (delegate_)
2896 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072897
2898 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582899 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072900 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522901 delegate_->ShouldSuppressDialogs() ||
2902 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152903 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342904 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582905 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502906 return;
2907 }
[email protected]3ab9cb82011-06-03 18:02:072908
[email protected]7ab1e7d62009-10-14 23:32:012909 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552910 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522911 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322912 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262913 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522914 reply_msg));
[email protected]420ae012009-04-24 05:16:322915}
2916
[email protected]a796f202012-05-30 14:14:252917bool WebContentsImpl::AddMessageToConsole(int32 level,
2918 const string16& message,
2919 int32 line_no,
2920 const string16& source_id) {
2921 if (!delegate_)
2922 return false;
2923 return delegate_->AddMessageToConsole(this, level, message, line_no,
2924 source_id);
2925}
2926
[email protected]b172aee2012-04-10 17:05:262927WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332928 // We want to base the page config off of the real URL, rather than the
2929 // display URL.
2930 GURL url = controller_.GetActiveEntry()
2931 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2932 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322933}
2934
[email protected]b172aee2012-04-10 17:05:262935void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272936 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252937 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222938
[email protected]ea114722012-03-12 01:11:252939 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172940 if (rdh) // NULL in unittests.
2941 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442945 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252946 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442947}
2948
[email protected]b172aee2012-04-10 17:05:262949void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2950 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152951 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522952 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152953 return;
2954
[email protected]9f76c1e2012-03-05 15:15:582955 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2956
[email protected]e5fc1632011-08-08 07:51:532957 // Ignore renderer unresponsive event if debugger is attached to the tab
2958 // since the event may be a result of the renderer sitting on a breakpoint.
2959 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442960 DevToolsAgentHost* agent =
2961 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2962 if (agent &&
2963 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532964 return;
2965
[email protected]420ae012009-04-24 05:16:322966 if (is_during_unload) {
2967 // Hang occurred while firing the beforeunload/unload handler.
2968 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582969 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322970
2971 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2972 return;
2973
2974 // If the tab hangs in the beforeunload/unload handler there's really
2975 // nothing we can do to recover. Pretend the unload listeners have
2976 // all fired and close the tab. If the hang is in the beforeunload handler
2977 // then the user will not have the option of cancelling the close.
2978 Close(rvh);
2979 return;
2980 }
2981
[email protected]9f76c1e2012-03-05 15:15:582982 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472983 return;
2984
[email protected]6934a702011-12-20 00:04:512985 if (delegate_)
2986 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322987}
2988
[email protected]b172aee2012-04-10 17:05:262989void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512990 if (delegate_)
2991 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322992}
2993
[email protected]b172aee2012-04-10 17:05:262994void WebContentsImpl::LoadStateChanged(
2995 const GURL& url,
2996 const net::LoadStateWithParam& load_state,
2997 uint64 upload_position,
2998 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322999 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563000 upload_position_ = upload_position;
3001 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503002 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203003 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303004 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213005 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323006 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463007 if (IsLoading()) {
3008 NotifyNavigationStateChanged(
3009 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3010 }
[email protected]420ae012009-04-24 05:16:323011}
3012
[email protected]b172aee2012-04-10 17:05:263013void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513014 if (delegate_)
3015 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253016}
3017
[email protected]b172aee2012-04-10 17:05:263018void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323019 bool proceed,
3020 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513021 if (delegate_)
3022 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323023}
3024
[email protected]b172aee2012-04-10 17:05:263025void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543026 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233027 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3028 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543029}
3030
[email protected]b172aee2012-04-10 17:05:263031void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103032 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263033 gfx::Size size = view_->GetContainerSize();
3034 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3035 // here during container initialization and normal window size will be set
3036 // later. In case of tab duplication this resizing to 0x0 prevents setting
3037 // normal size later so just ignore it.
3038 if (!size.IsEmpty())
3039 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323040}
3041
[email protected]b172aee2012-04-10 17:05:263042void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543043 NotifySwapped();
3044}
3045
[email protected]14392a52012-05-02 20:28:443046int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3047 SiteInstance* instance) {
3048 if (!opener_)
3049 return MSG_ROUTING_NONE;
3050
3051 // Recursively create RenderViews for anything else in the opener chain.
3052 return opener_->CreateOpenerRenderViews(instance);
3053}
3054
3055int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3056 int opener_route_id = MSG_ROUTING_NONE;
3057
3058 // If this tab has an opener, ensure it has a RenderView in the given
3059 // SiteInstance as well.
3060 if (opener_)
3061 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3062
3063 // Create a swapped out RenderView in the given SiteInstance if none exists,
3064 // setting its opener to the given route_id. Return the new view's route_id.
3065 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3066}
3067
[email protected]b172aee2012-04-10 17:05:263068NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193069 return GetController();
[email protected]3a3d47472010-07-15 21:03:543070}
3071
[email protected]b172aee2012-04-10 17:05:263072WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563073 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323074}
3075
[email protected]10f417c52011-12-28 21:04:233076NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263077 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323078 return controller_.GetLastCommittedEntry();
3079}
3080
[email protected]b172aee2012-04-10 17:05:263081bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443082 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443083 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323084 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523085
[email protected]420ae012009-04-24 05:16:323086 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443087 if (rwh_view)
3088 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323089
[email protected]74ce1ad2011-12-16 21:51:463090 // Make sure we use the correct starting page_id in the new RenderView.
3091 UpdateMaxPageIDIfNecessary(render_view_host);
3092 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583093 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463094
[email protected]7900bfdb2012-05-24 19:31:243095 std::string embedder_channel_name;
3096 int embedder_container_id;
3097 GetBrowserPluginEmbedderInfo(render_view_host,
3098 &embedder_channel_name,
3099 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583100 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493101 render_view_host)->CreateRenderView(string16(),
3102 opener_route_id,
3103 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243104 embedder_channel_name,
3105 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523106 return false;
[email protected]14392a52012-05-02 20:28:443107 }
[email protected]a4127722011-04-27 23:13:523108
[email protected]e60c0232011-11-11 19:56:353109#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503110 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3111 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443112 if (rwh_view) {
3113 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3114 render_widget_host->WasResized();
3115 }
[email protected]f8233cc2011-05-31 20:24:503116#endif
3117
[email protected]420ae012009-04-24 05:16:323118 return true;
3119}
3120
[email protected]b172aee2012-04-10 17:05:263121void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3122 IPC::Message* reply_msg,
3123 bool success,
3124 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543125 if (is_showing_before_unload_dialog_ && !success) {
3126 // If a beforeunload dialog is canceled, we need to stop the throbber from
3127 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293128 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353129 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543130
[email protected]3bbacc5b2012-04-17 17:46:153131 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543132 }
3133 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583134 static_cast<RenderViewHostImpl*>(
3135 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543136}
3137
[email protected]b172aee2012-04-10 17:05:263138void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123139 encoding_ = content::GetContentClient()->browser()->
3140 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103141}
[email protected]f45d2a72010-03-08 23:28:353142
[email protected]b172aee2012-04-10 17:05:263143void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463144 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263145 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573146 DownloadManager* dlm =
3147 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143148 if (!dlm)
3149 return;
3150 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263151 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143152 const NavigationEntry* entry = controller_.GetActiveEntry();
3153 if (entry)
3154 post_id = entry->GetPostID();
3155 }
[email protected]29a5ffc82012-03-13 19:35:583156 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143157 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143158 scoped_ptr<DownloadUrlParameters> params(
3159 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493160 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143161 params->set_post_id(post_id);
3162 params->set_prefer_cache(true);
3163 if (post_id >= 0)
3164 params->set_method("POST");
3165 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143166}
3167
[email protected]b172aee2012-04-10 17:05:263168void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213169 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443170 // Can be NULL during tests.
3171 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213172 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363173}
[email protected]9f76c1e2012-03-05 15:15:583174
[email protected]b172aee2012-04-10 17:05:263175RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583176 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3177}
[email protected]7900bfdb2012-05-24 19:31:243178
3179void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3180 content::RenderViewHost* render_view_host,
3181 std::string* embedder_channel_name,
3182 int* embedder_container_id) {
3183 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283184 old_browser_plugin_host()->embedder_render_process_host();
3185 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243186 int embedder_process_id =
3187 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3188 if (embedder_process_id != -1) {
3189 *embedder_channel_name =
3190 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3191 embedder_process_id);
3192 }
3193}