blob: a14bf00b396de805ab673a83de700799769fe16d [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]4c3a23582012-08-18 08:54:3457#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3858#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4259#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2560#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1061#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5062#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2163#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4864#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1865#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5466#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0367#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1668#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2969#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5470#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3471#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3772#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5673#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4174#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0175#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4176#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5277#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2478#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3679#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3180#include "webkit/glue/webpreferences.h"
81
[email protected]f66df822012-05-18 16:52:1782#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5083#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4184#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5785#endif
[email protected]3e45ba92009-02-20 21:09:0086
[email protected]c71fe6402012-08-15 15:22:5587#if defined(USE_AURA) && defined(USE_X11)
88#include "ui/base/touch/touch_factory.h"
89#endif // defined (USE_AURA) && defined(USE_X11)
90
[email protected]420ae012009-04-24 05:16:3291// Cross-Site Navigations
92//
[email protected]b172aee2012-04-10 17:05:2693// If a WebContentsImpl is told to navigate to a different web site (as
94// determined by SiteInstance), it will replace its current RenderViewHost with
95// a new RenderViewHost dedicated to the new SiteInstance. This works as
96// follows:
[email protected]420ae012009-04-24 05:16:3297//
98// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4699// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32100// - The pending RVH is "suspended," so that no navigation messages are sent to
101// its renderer until the onbeforeunload JavaScript handler has a chance to
102// run in the current RVH.
103// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
104// that it has a pending cross-site request. ResourceDispatcherHost will
105// check for this when the response arrives.
106// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46107// cancel all the pending logic. Otherwise we allow the pending RVH to send
108// the navigation request to its renderer.
109// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
110// main resource load on the pending RVH. It checks CrossSiteRequestManager
111// to see that it is a cross-site request, and installs a
112// CrossSiteResourceHandler.
113// - When RDH receives a response, the BufferedResourceHandler determines
114// whether it is a download. If so, it sends a message to the new renderer
115// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26116// pending RVH remains until the next DidNavigate event for this
117// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32118// - After RDH receives a response and determines that it is safe and not a
119// download, it pauses the response to first run the old page's onunload
120// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26121// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32122// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15123// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32124// the ResourceDispatcherHost, who unpauses the response. Data is then sent
125// to the pending RVH.
126// - The pending renderer sends a FrameNavigate message that invokes the
127// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46128// pending RVH.
[email protected]992db4c2011-05-12 15:37:15129// - The previous renderer is kept swapped out in RenderViewHostManager in case
130// the user goes back. The process only stays live if another tab is using
131// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32132
[email protected]b441a8492012-06-06 14:55:57133using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44134using content::DevToolsAgentHost;
135using content::DevToolsAgentHostRegistry;
136using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17137using content::DownloadItem;
138using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14139using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20140using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56141using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13142using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27143using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54144using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50145using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23146using content::NavigationEntry;
147using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20148using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11149using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57150using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57151using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27152using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11153using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50154using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58155using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04156using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25157using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14158using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43159using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33160using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38161using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09162using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25163using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56164using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22165using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50166using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25167using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44168
[email protected]420ae012009-04-24 05:16:32169namespace {
170
171// Amount of time we wait between when a key event is received and the renderer
172// is queried for its state and pushed to the NavigationEntry.
173const int kQueryStateDelay = 5000;
174
[email protected]6ebdc9b2010-09-27 16:55:57175const int kSyncWaitDelay = 40;
176
[email protected]82114f52012-03-20 22:53:41177const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05178
[email protected]420ae012009-04-24 05:16:32179#if defined(OS_WIN)
180
181BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
182 // Note: erase is required to properly paint some widgets borders. This can
183 // be seen with textfields.
184 InvalidateRect(hwnd, NULL, TRUE);
185 return TRUE;
186}
187#endif
188
[email protected]2c5569662011-03-22 20:45:02189ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23190 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50191 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16192 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47193 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47195 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23197 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
198 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47199 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16200 break; // Fall through to rest of function.
201 }
[email protected]5e369672009-11-03 23:48:30202
[email protected]59246c572012-02-10 13:32:13203 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
204 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23205 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13206 browser_context->DidLastSessionExitCleanly()) {
207 if (entry.GetHasPostData())
208 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02209 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13210 }
[email protected]5e369672009-11-03 23:48:30211
[email protected]2c5569662011-03-22 20:45:02212 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30213}
214
[email protected]10f417c52011-12-28 21:04:23215void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47216 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42217 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50218 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24219 const std::string& embedder_channel_name,
220 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16221 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51222 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54223 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55224 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
225 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36226 if (!entry.GetBaseURLForDataURL().is_empty()) {
227 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
228 params->history_url_for_data_url = entry.GetVirtualURL();
229 }
[email protected]36fc0392011-12-25 03:59:51230 params->referrer = entry.GetReferrer();
231 params->transition = entry.GetTransitionType();
232 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00233 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55234 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34235 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47236 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48237 params->transferred_request_child_id =
238 entry.transferred_global_request_id().child_id;
239 params->transferred_request_request_id =
240 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22241 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00242 // Avoid downloading when in view-source mode.
243 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24244 params->embedder_channel_name = embedder_channel_name;
245 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44246 params->is_post = entry.GetHasPostData();
247 if(entry.GetBrowserInitiatedPostData()) {
248 params->browser_initiated_post_data.assign(
249 entry.GetBrowserInitiatedPostData()->front(),
250 entry.GetBrowserInitiatedPostData()->front() +
251 entry.GetBrowserInitiatedPostData()->size());
252
253 }
[email protected]6c6b02d2011-09-02 03:36:47254
[email protected]7c16976c2012-08-04 02:38:23255 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
256 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
257 // We may have been redirected when navigating to the current URL.
258 // Use the URL the user originally intended to visit, if it's valid and if a
259 // POST wasn't involved; the latter case avoids issues with sending data to
260 // the wrong page.
261 params->url = entry.GetOriginalRequestURL();
262 } else {
263 params->url = entry.GetURL();
264 }
265
[email protected]6c6b02d2011-09-02 03:36:47266 if (delegate)
267 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34268}
269
[email protected]f98f5092012-05-19 00:08:14270int GetSwitchValueAsInt(
271 const CommandLine& command_line,
272 const std::string& switch_string,
273 int min_value) {
274 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
275 int int_value;
276 if (base::StringToInt(string_value, &int_value))
277 return std::max(min_value, int_value);
278 else
279 return min_value;
280}
281
[email protected]420ae012009-04-24 05:16:32282} // namespace
283
[email protected]a81343d232011-12-27 07:39:20284namespace content {
285
286WebContents* WebContents::Create(
287 BrowserContext* browser_context,
288 SiteInstance* site_instance,
289 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19290 const WebContents* base_web_contents) {
291 return WebContentsImpl::Create(
292 browser_context, site_instance, routing_id,
293 static_cast<const WebContentsImpl*>(base_web_contents));
294}
295
296WebContents* WebContents::CreateWithSessionStorage(
297 BrowserContext* browser_context,
298 SiteInstance* site_instance,
299 int routing_id,
[email protected]b172aee2012-04-10 17:05:26300 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19301 const SessionStorageNamespaceMap& session_storage_namespace_map) {
302 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
303
304 for (SessionStorageNamespaceMap::const_iterator it =
305 session_storage_namespace_map.begin();
306 it != session_storage_namespace_map.end();
307 ++it) {
308 new_contents->GetController().SetSessionStorageNamespace(it->first,
309 it->second);
310 }
311
312 new_contents->Init(browser_context, site_instance, routing_id,
313 static_cast<const WebContentsImpl*>(base_web_contents));
314 return new_contents;
[email protected]a81343d232011-12-27 07:39:20315}
[email protected]746d3052012-05-22 15:15:47316
[email protected]299d7f12012-05-23 05:31:15317WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47318 return rvh->GetDelegate()->GetAsWebContents();
319}
320
[email protected]a81343d232011-12-27 07:39:20321}
[email protected]f4f50ef2011-01-21 19:01:19322
[email protected]b172aee2012-04-10 17:05:26323// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32324
[email protected]b172aee2012-04-10 17:05:26325WebContentsImpl::WebContentsImpl(
326 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19327 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42328 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19329 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57330 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44331 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05332 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34333 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23334 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
335 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34336 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21337 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56338 upload_size_(0),
339 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47340 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57341 capturing_contents_(false),
342 is_being_destroyed_(false),
343 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55344 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57345#if defined(OS_WIN)
346 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
347#endif
[email protected]7ab1e7d62009-10-14 23:32:01348 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56349 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38350 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25351 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01352 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25353 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01354 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00355 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43356 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20357 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35358}
initial.commit09911bf2008-07-26 23:55:29359
[email protected]b172aee2012-04-10 17:05:26360WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32361 is_being_destroyed_ = true;
362
[email protected]3ab9cb82011-06-03 18:02:07363 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55364 if (dialog_creator_)
365 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07366
[email protected]da8543762012-03-20 08:52:20367 if (color_chooser_)
368 color_chooser_->End();
369
[email protected]420ae012009-04-24 05:16:32370 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32371
[email protected]ca13a442012-04-17 14:00:12372 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07373 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09374 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
375 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32377
378 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07379#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32380 // If we still have a window handle, destroy it. GetNativeView can return
381 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42382 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52383 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58384 if (host && host->GetView())
385 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42386 }
[email protected]420ae012009-04-24 05:16:32387#endif
[email protected]7ab1e7d62009-10-14 23:32:01388
389 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15390 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01391 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15392 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01393 }
[email protected]b5a1d11c2011-02-17 03:09:42394
[email protected]2db9bd72012-04-13 20:20:56395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
397 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08398
[email protected]6934a702011-12-20 00:04:51399 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42400}
401
[email protected]d1198fd2012-08-13 22:50:19402WebContentsImpl* WebContentsImpl::Create(
403 BrowserContext* browser_context,
404 SiteInstance* site_instance,
405 int routing_id,
406 const WebContentsImpl* base_web_contents) {
407 return CreateWithOpener(browser_context, site_instance, routing_id,
408 base_web_contents, NULL);
409}
410
411WebContentsImpl* WebContentsImpl::CreateWithOpener(
412 BrowserContext* browser_context,
413 SiteInstance* site_instance,
414 int routing_id,
415 const WebContentsImpl* base_web_contents,
416 WebContentsImpl* opener) {
417 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
418
419 new_contents->Init(browser_context, site_instance, routing_id,
420 static_cast<const WebContentsImpl*>(base_web_contents));
421 return new_contents;
422}
423
[email protected]b172aee2012-04-10 17:05:26424WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
425 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54426 WebPreferences prefs;
427
428 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
429
430 prefs.developer_extras_enabled = true;
431 prefs.javascript_enabled =
432 !command_line.HasSwitch(switches::kDisableJavaScript);
433 prefs.web_security_enabled =
434 !command_line.HasSwitch(switches::kDisableWebSecurity);
435 prefs.plugins_enabled =
436 !command_line.HasSwitch(switches::kDisablePlugins);
437 prefs.java_enabled =
438 !command_line.HasSwitch(switches::kDisableJava);
439
440 prefs.uses_page_cache =
441 command_line.HasSwitch(switches::kEnableFastback);
442 prefs.remote_fonts_enabled =
443 !command_line.HasSwitch(switches::kDisableRemoteFonts);
444 prefs.xss_auditor_enabled =
445 !command_line.HasSwitch(switches::kDisableXSSAuditor);
446 prefs.application_cache_enabled =
447 !command_line.HasSwitch(switches::kDisableApplicationCache);
448
449 prefs.local_storage_enabled =
450 !command_line.HasSwitch(switches::kDisableLocalStorage);
451 prefs.databases_enabled =
452 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01453#if defined(OS_ANDROID)
454 prefs.webaudio_enabled =
455 command_line.HasSwitch(switches::kEnableWebAudio);
456#else
[email protected]64d69de42012-02-06 00:19:54457 prefs.webaudio_enabled =
458 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01459#endif
[email protected]64d69de42012-02-06 00:19:54460
461 prefs.experimental_webgl_enabled =
462 GpuProcessHost::gpu_enabled() &&
463 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07464#if defined(OS_ANDROID)
465 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
466#else
[email protected]64d69de42012-02-06 00:19:54467 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07468#endif
[email protected]64d69de42012-02-06 00:19:54469
[email protected]5a073092012-06-08 00:42:51470 prefs.flash_3d_enabled =
471 GpuProcessHost::gpu_enabled() &&
472 !command_line.HasSwitch(switches::kDisableFlash3d);
473 prefs.flash_stage3d_enabled =
474 GpuProcessHost::gpu_enabled() &&
475 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19476
[email protected]64d69de42012-02-06 00:19:54477 prefs.gl_multisampling_enabled =
478 !command_line.HasSwitch(switches::kDisableGLMultisampling);
479 prefs.privileged_webgl_extensions_enabled =
480 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
481 prefs.site_specific_quirks_enabled =
482 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
483 prefs.allow_file_access_from_file_urls =
484 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
485 prefs.show_composited_layer_borders =
486 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
487 prefs.show_composited_layer_tree =
488 command_line.HasSwitch(switches::kShowCompositedLayerTree);
489 prefs.show_fps_counter =
490 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19491 prefs.show_paint_rects =
492 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52493 prefs.render_vsync_enabled =
494 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54495 prefs.accelerated_compositing_enabled =
496 GpuProcessHost::gpu_enabled() &&
497 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54498 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23499 command_line.HasSwitch(switches::kForceCompositingMode) &&
500 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54501 prefs.fixed_position_compositing_enabled =
502 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
503 prefs.accelerated_2d_canvas_enabled =
504 GpuProcessHost::gpu_enabled() &&
505 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58506 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27507 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54508 prefs.accelerated_painting_enabled =
509 GpuProcessHost::gpu_enabled() &&
510 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
511 prefs.accelerated_filters_enabled =
512 GpuProcessHost::gpu_enabled() &&
513 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
514 prefs.accelerated_layers_enabled =
515 prefs.accelerated_animation_enabled =
516 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54517 prefs.accelerated_plugins_enabled =
518 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
519 prefs.accelerated_video_enabled =
520 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54521 prefs.fullscreen_enabled =
522 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16523 prefs.css_regions_enabled =
524 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29525 prefs.css_shaders_enabled =
526 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01527 prefs.css_variables_enabled =
528 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56529 prefs.device_supports_touch =
530 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]c71fe6402012-08-15 15:22:55531#if defined(USE_AURA) && defined(USE_X11)
532 prefs.device_supports_touch |=
533 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
534#endif
[email protected]d849b122012-07-18 07:35:26535#if defined(OS_ANDROID)
536 prefs.device_supports_mouse = false;
537#endif
[email protected]64d69de42012-02-06 00:19:54538
539#if defined(OS_MACOSX)
540 bool default_enable_scroll_animator = true;
541#else
542 // On CrOS, the launcher always passes in the --enable flag.
543 bool default_enable_scroll_animator = false;
544#endif
545 prefs.enable_scroll_animator = default_enable_scroll_animator;
546 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
547 prefs.enable_scroll_animator = true;
548 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
549 prefs.enable_scroll_animator = false;
550
551 prefs.visual_word_movement_enabled =
552 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54553
554 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32555 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54556 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39557 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]d56ecf922012-02-15 16:03:11558 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54559 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11560 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54561 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19562 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
563 prefs.flash_3d_enabled = false;
564 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
565 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11566 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54567 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11568 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54569 prefs.gl_multisampling_enabled = false;
570
571 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45572 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32573 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54574 prefs.accelerated_video_enabled = false;
575 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45576 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09577 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54578 }
579 }
580
[email protected]b9535422012-02-09 01:47:59581 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58582 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54583 prefs.loads_images_automatically = true;
584 prefs.javascript_enabled = true;
585 }
586
587 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
588
589 // Force accelerated compositing and 2d canvas off for chrome:, about: and
590 // chrome-devtools: pages (unless it's specifically allowed).
591 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54592 url.SchemeIs(chrome::kChromeUIScheme) ||
593 (url.SchemeIs(chrome::kAboutScheme) &&
594 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25595 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54596 prefs.accelerated_compositing_enabled = false;
597 prefs.accelerated_2d_canvas_enabled = false;
598 }
[email protected]43d9d782012-03-01 15:40:09599
[email protected]f98f5092012-05-19 00:08:14600 if (command_line.HasSwitch(switches::kDefaultTileWidth))
601 prefs.default_tile_width =
602 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
603 if (command_line.HasSwitch(switches::kDefaultTileHeight))
604 prefs.default_tile_height =
605 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
606 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
607 prefs.max_untiled_layer_width =
608 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
609 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
610 prefs.max_untiled_layer_height =
611 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
612
[email protected]2486dce2012-05-23 17:18:19613 if (gfx::Screen::IsDIPEnabled()) {
614 // Only apply when using DIP coordinate system as this setting interferes
615 // with fixed layout mode.
616 prefs.apply_default_device_scale_factor_in_compositor = true;
617 }
618
[email protected]de023762012-07-26 17:10:17619 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
620 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10621
[email protected]3f7e2062012-09-04 16:38:12622 prefs.gesture_tap_highlight_enabled = !command_line.HasSwitch(
623 switches::kDisableGestureTapHighlight);
624
[email protected]6b4dcb072012-06-18 22:26:51625 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
626
[email protected]2e21fe292012-03-02 22:52:32627 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54628
629 return prefs;
630}
631
[email protected]b172aee2012-04-10 17:05:26632RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28633 return &render_manager_;
634}
635
[email protected]7bb761892012-07-20 09:32:47636bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
637 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56638 if (GetWebUI() &&
639 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17640 return true;
[email protected]d2353452012-01-19 19:53:56641 }
[email protected]f82d57b52011-04-27 19:13:17642
[email protected]d8c660432011-12-22 20:51:25643 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
644 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10645 while ((observer = it.GetNext()) != NULL)
646 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53647 return true;
[email protected]403415a2011-01-10 18:57:53648
[email protected]7bb761892012-07-20 09:32:47649 // Message handlers should be aware of which RenderViewHost sent the
650 // message, which is temporarily stored in message_source_.
651 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18652 bool handled = true;
653 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26654 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58655 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
656 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24657 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
658 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18659 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
660 OnDidLoadResourceFromMemoryCache)
661 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
662 OnDidDisplayInsecureContent)
663 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
664 OnDidRunInsecureContent)
665 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
666 OnDocumentLoadedInFrame)
667 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26668 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
669 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17670 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
671 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25672 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26673 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59674 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21675 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20676 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
677 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
678 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16679 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45680 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10681 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20682 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
683 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
684 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
685 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29686 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50687 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50688 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
689 OnRequestPpapiBrokerPermission)
[email protected]724159a2010-12-30 01:11:18690 IPC_MESSAGE_UNHANDLED(handled = false)
691 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47692 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18693
694 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38695 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18696 GetRenderProcessHost()->ReceivedBadMessage();
697 }
698
699 return handled;
700}
701
[email protected]b172aee2012-04-10 17:05:26702void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18703 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23704 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43705 if (delegate_)
706 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18707}
708
[email protected]d1198fd2012-08-13 22:50:19709NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56710 return controller_;
711}
712
[email protected]d1198fd2012-08-13 22:50:19713const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56714 return controller_;
715}
716
[email protected]b172aee2012-04-10 17:05:26717content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55718 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30719}
720
[email protected]b172aee2012-04-10 17:05:26721const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31722 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23723 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51724 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31725}
726
[email protected]b172aee2012-04-10 17:05:26727content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31728 return delegate_;
729}
730
[email protected]b172aee2012-04-10 17:05:26731void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31732 // TODO(cbentzel): remove this debugging code?
733 if (delegate == delegate_)
734 return;
735 if (delegate_)
736 delegate_->Detach(this);
737 delegate_ = delegate;
738 if (delegate_)
739 delegate_->Attach(this);
740}
741
[email protected]b172aee2012-04-10 17:05:26742content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41743 RenderViewHostImpl* host = render_manager_.current_host();
744 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16745}
746
[email protected]b172aee2012-04-10 17:05:26747RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31748 return render_manager_.current_host();
749}
750
[email protected]6b618e62012-08-16 12:59:18751int WebContentsImpl::GetRoutingID() const {
752 if (!GetRenderViewHost())
753 return MSG_ROUTING_NONE;
754
755 return GetRenderViewHost()->GetRoutingID();
756}
757
[email protected]b172aee2012-04-10 17:05:26758RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31759 return render_manager_.GetRenderWidgetHostView();
760}
761
[email protected]b172aee2012-04-10 17:05:26762content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31763 return view_.get();
764}
765
[email protected]b172aee2012-04-10 17:05:26766content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50767 WebUIControllerFactory* factory =
768 content::GetContentClient()->browser()->GetWebUIControllerFactory();
769 if (!factory)
770 return NULL;
[email protected]d2353452012-01-19 19:53:56771 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22772 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50773 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22774 if (controller) {
775 web_ui->SetController(controller);
776 return web_ui;
777 }
778
779 delete web_ui;
780 return NULL;
781}
782
[email protected]b172aee2012-04-10 17:05:26783content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31784 return render_manager_.web_ui() ? render_manager_.web_ui()
785 : render_manager_.pending_web_ui();
786}
787
[email protected]b172aee2012-04-10 17:05:26788content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31789 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34790}
791
[email protected]86ef6a392012-05-11 22:03:11792void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22793 if (GetUserAgentOverride() == override)
794 return;
795
796 renderer_preferences_.user_agent_override = override;
797
798 // Send the new override string to the renderer.
799 RenderViewHost* host = GetRenderViewHost();
800 if (host)
801 host->SyncRendererPrefs();
802
803 // Reload the page if a load is currently in progress to avoid having
804 // different parts of the page loaded using different user agents.
805 NavigationEntry* entry = controller_.GetActiveEntry();
806 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
807 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53808
809 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
810 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11811}
812
813const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22814 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11815}
816
[email protected]b172aee2012-04-10 17:05:26817const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55818 // Transient entries take precedence. They are used for interstitial pages
819 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23820 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08821 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20822 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30823 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23824 if (entry) {
[email protected]b5cca982011-05-26 04:42:08825 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23826 }
[email protected]7ade2732011-02-10 00:13:58827 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
828 render_manager_.pending_web_ui() : render_manager_.web_ui();
829 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54830 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55831 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54832 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35833 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22834 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54835 if (!title.empty())
836 return title;
837 }
838 }
839
840 // We use the title for the last committed entry rather than a pending
841 // navigation entry. For example, when the user types in a URL, we want to
842 // keep the old page's title until the new load has committed and we get a new
843 // title.
[email protected]96d185d2009-04-24 03:28:54844 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23845 if (entry) {
[email protected]b5cca982011-05-26 04:42:08846 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23847 }
[email protected]987fc3a2011-05-26 14:18:09848
849 // |page_title_when_no_navigation_entry_| is finally used
850 // if no title cannot be retrieved.
851 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54852}
853
[email protected]b172aee2012-04-10 17:05:26854int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46855 return GetMaxPageIDForSiteInstance(GetSiteInstance());
856}
857
[email protected]b172aee2012-04-10 17:05:26858int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
859 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33860 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
861 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46862
[email protected]b6583592012-01-25 19:52:33863 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34864}
865
[email protected]b172aee2012-04-10 17:05:26866void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46867 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
868}
869
[email protected]b172aee2012-04-10 17:05:26870void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33871 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46872 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33873 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34874}
875
[email protected]b172aee2012-04-10 17:05:26876void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
877 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57878}
879
[email protected]b172aee2012-04-10 17:05:26880SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58881 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54882}
883
[email protected]b172aee2012-04-10 17:05:26884SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38885 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
886 render_manager_.pending_render_view_host() :
887 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58888 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38889}
890
[email protected]b172aee2012-04-10 17:05:26891bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31892 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49893}
894
[email protected]b172aee2012-04-10 17:05:26895bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31896 return waiting_for_response_;
897}
898
[email protected]b172aee2012-04-10 17:05:26899const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31900 return load_state_;
901}
902
[email protected]b172aee2012-04-10 17:05:26903const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31904 return load_state_host_;
905}
906
[email protected]b172aee2012-04-10 17:05:26907uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return upload_size_;
909}
910
[email protected]b172aee2012-04-10 17:05:26911uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31912 return upload_position_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31916 return encoding_;
917}
918
[email protected]b172aee2012-04-10 17:05:26919bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31920 return displayed_insecure_content_;
921}
922
[email protected]b172aee2012-04-10 17:05:26923void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31924 capturing_contents_ = cap;
925}
926
[email protected]b172aee2012-04-10 17:05:26927bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
929 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
930 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49931}
932
[email protected]b172aee2012-04-10 17:05:26933void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
934 int error_code) {
[email protected]443b80e2010-12-14 00:42:23935 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34936 return;
937
[email protected]443b80e2010-12-14 00:42:23938 crashed_status_ = status;
939 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46940 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34941}
942
[email protected]b172aee2012-04-10 17:05:26943base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31944 return crashed_status_;
945}
946
[email protected]b172aee2012-04-10 17:05:26947bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31948 return is_being_destroyed_;
949}
950
[email protected]b172aee2012-04-10 17:05:26951void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34952 if (delegate_)
953 delegate_->NavigationStateChanged(this, changed_flags);
954}
955
[email protected]3e324142012-06-25 18:26:33956base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
957 return last_selected_time_;
958}
959
[email protected]9e2e4632012-07-27 16:38:41960void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54961 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04962 RenderWidgetHostViewPort* rwhv =
963 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16964 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41965 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43966#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16967 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43968#endif
969 }
[email protected]96d185d2009-04-24 03:28:54970
[email protected]5ac20162010-11-24 23:33:11971 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38972
[email protected]9e2e4632012-07-27 16:38:41973 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59974
975 // The resize rect might have changed while this was inactive -- send the new
976 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58977 RenderViewHostImpl* rvh =
978 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59979 if (rvh) {
980 rvh->ResizeRectChanged(GetRootWindowResizerRect());
981 }
[email protected]96d185d2009-04-24 03:28:54982
[email protected]3e324142012-06-25 18:26:33983 bool is_visible = true;
984 content::NotificationService::current()->Notify(
985 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
986 content::Source<WebContents>(this),
987 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31988}
989
[email protected]b172aee2012-04-10 17:05:26990void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31991 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52992 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
993 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26994 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52995 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33996 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52997 // calls us).
[email protected]c30585c2012-02-16 15:02:04998 RenderWidgetHostViewPort* rwhv =
999 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161000 if (rwhv)
1001 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541002 }
1003
[email protected]375fa1b2012-05-22 22:05:371004 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071005 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371006 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091007 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371008 content::Details<bool>(&is_visible));
1009}
1010
[email protected]b172aee2012-04-10 17:05:261011bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311012 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271013 return WillNotifyDisconnection() &&
1014 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581015 !static_cast<RenderViewHostImpl*>(
1016 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311017}
1018
[email protected]b172aee2012-04-10 17:05:261019void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271020 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251021 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271022}
1023
[email protected]b172aee2012-04-10 17:05:261024WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441025 // We use our current SiteInstance since the cloned entry will use it anyway.
1026 // We pass |this| for the |base_web_contents| to size the view correctly, and
1027 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191028 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1029 GetSiteInstance(), MSG_ROUTING_NONE,
1030 this, opener_);
1031 tc->GetController().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271032 return tc;
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035void WebContentsImpl::AddNewContents(WebContents* new_contents,
1036 WindowOpenDisposition disposition,
1037 const gfx::Rect& initial_pos,
1038 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271039 if (!delegate_)
1040 return;
1041
1042 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1043 user_gesture);
1044}
1045
[email protected]b172aee2012-04-10 17:05:261046gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271047 return view_->GetContentNativeView();
1048}
1049
[email protected]b172aee2012-04-10 17:05:261050gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271051 return view_->GetNativeView();
1052}
1053
[email protected]b172aee2012-04-10 17:05:261054void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271055 view_->GetContainerBounds(out);
1056}
1057
[email protected]b172aee2012-04-10 17:05:261058void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271059 view_->Focus();
1060}
1061
[email protected]14392a52012-05-02 20:28:441062void WebContentsImpl::Observe(int type,
1063 const content::NotificationSource& source,
1064 const content::NotificationDetails& details) {
1065 switch (type) {
1066 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1067 OnWebContentsDestroyed(
1068 content::Source<content::WebContents>(source).ptr());
1069 break;
[email protected]bafe6cd2012-05-23 23:09:501070 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1071 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1072 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1073 i != pending_widget_views_.end(); ++i) {
1074 if (host->GetView() == i->second) {
1075 pending_widget_views_.erase(i);
1076 break;
1077 }
1078 }
1079 break;
1080 }
[email protected]14392a52012-05-02 20:28:441081 default:
1082 NOTREACHED();
1083 }
1084}
1085
[email protected]d1198fd2012-08-13 22:50:191086void WebContentsImpl::Init(BrowserContext* browser_context,
1087 SiteInstance* site_instance,
1088 int routing_id,
1089 const WebContents* base_web_contents) {
1090 render_manager_.Init(browser_context, site_instance, routing_id);
1091
1092 view_.reset(content::GetContentClient()->browser()->
1093 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1094 if (view_.get()) {
1095 CHECK(render_view_host_delegate_view_);
1096 } else {
1097 content::WebContentsViewDelegate* delegate =
1098 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1099 this);
1100 view_.reset(CreateWebContentsView(
1101 this, delegate, &render_view_host_delegate_view_));
1102 CHECK(render_view_host_delegate_view_);
1103 }
1104 CHECK(view_.get());
1105
1106 // We have the initial size of the view be based on the size of the view of
1107 // the passed in WebContents.
1108 view_->CreateView(base_web_contents ?
1109 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1110
1111 // Listen for whether our opener gets destroyed.
1112 if (opener_) {
1113 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1114 content::Source<WebContents>(opener_));
1115 }
1116
1117 registrar_.Add(this,
1118 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1119 content::NotificationService::AllBrowserContextsAndSources());
1120#if defined(ENABLE_JAVA_BRIDGE)
1121 java_bridge_dispatcher_host_manager_.reset(
1122 new JavaBridgeDispatcherHostManager(this));
1123#endif
1124
1125 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1126}
1127
[email protected]14392a52012-05-02 20:28:441128void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1129 // Clear the opener if it has been closed.
1130 if (web_contents == opener_) {
1131 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1132 content::Source<WebContents>(opener_));
1133 opener_ = NULL;
1134 }
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311138 observers_.AddObserver(observer);
1139}
1140
[email protected]b172aee2012-04-10 17:05:261141void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311142 observers_.RemoveObserver(observer);
1143}
1144
[email protected]b172aee2012-04-10 17:05:261145void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341146 if (delegate_)
1147 delegate_->ActivateContents(this);
1148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121151 if (delegate_)
1152 delegate_->DeactivateContents(this);
1153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481156 if (delegate_)
1157 delegate_->LostCapture();
1158}
1159
[email protected]b172aee2012-04-10 17:05:261160bool WebContentsImpl::PreHandleKeyboardEvent(
1161 const NativeWebKeyboardEvent& event,
1162 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481163 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131164 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481165}
1166
[email protected]b172aee2012-04-10 17:05:261167void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481168 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131169 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481170}
1171
[email protected]b172aee2012-04-10 17:05:261172void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431173 if (delegate_)
1174 delegate_->HandleMouseDown();
1175}
1176
[email protected]b172aee2012-04-10 17:05:261177void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481178 if (delegate_)
1179 delegate_->HandleMouseUp();
1180}
1181
[email protected]590a634e2012-07-19 16:38:231182void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481183 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231184 delegate_->HandlePointerActivate();
1185}
1186
1187void WebContentsImpl::HandleGestureBegin() {
1188 if (delegate_)
1189 delegate_->HandleGestureBegin();
1190}
1191
1192void WebContentsImpl::HandleGestureEnd() {
1193 if (delegate_)
1194 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481195}
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471198 if (delegate_)
1199 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1200}
1201
[email protected]b172aee2012-04-10 17:05:261202bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381203 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121204}
1205
[email protected]a9c81f02012-06-01 00:15:441206void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1207 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371208 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441209 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371210 } else {
1211 GotResponseToLockMouseRequest(false);
1212 }
1213}
1214
[email protected]b172aee2012-04-10 17:05:261215void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371216 if (delegate_)
1217 delegate_->LostMouseLock();
1218}
1219
[email protected]bafe6cd2012-05-23 23:09:501220void WebContentsImpl::CreateNewWindow(
1221 int route_id,
[email protected]97714c82012-06-06 10:15:131222 const ViewHostMsg_CreateWindow_Params& params,
1223 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501224 if (delegate_ && !delegate_->ShouldCreateWebContents(
1225 this, route_id, params.window_container_type, params.frame_name,
1226 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091227 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501228 return;
1229 }
1230
1231 // We usually create the new window in the same BrowsingInstance (group of
1232 // script-related windows), by passing in the current SiteInstance. However,
1233 // if the opener is being suppressed, we create a new SiteInstance in its own
1234 // BrowsingInstance.
1235 scoped_refptr<SiteInstance> site_instance =
1236 params.opener_suppressed ?
1237 SiteInstance::Create(GetBrowserContext()) :
1238 GetSiteInstance();
1239
1240 // Create the new web contents. This will automatically create the new
1241 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191242 WebContentsImpl* new_contents =
1243 new WebContentsImpl(GetBrowserContext(),
1244 params.opener_suppressed ? NULL : this);
1245
1246 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341247 //
1248 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191249 const std::string& partition_id =
1250 content::GetContentClient()->browser()->
1251 GetStoragePartitionIdForSiteInstance(GetBrowserContext(),
1252 site_instance);
[email protected]4c3a23582012-08-18 08:54:341253 content::StoragePartition* partition =
1254 BrowserContext::GetStoragePartition(GetBrowserContext(),
1255 site_instance);
[email protected]d1198fd2012-08-13 22:50:191256 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341257 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191258 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1259 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1260 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1261 new_contents->GetController().SetSessionStorageNamespace(
1262 partition_id,
1263 session_storage_namespace);
1264 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1265
[email protected]bafe6cd2012-05-23 23:09:501266 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1267
1268 if (!params.opener_suppressed) {
1269 content::WebContentsView* new_view = new_contents->GetView();
1270
1271 // TODO(brettw): It seems bogus that we have to call this function on the
1272 // newly created object and give it one of its own member variables.
1273 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1274
1275 // Save the created window associated with the route so we can show it
1276 // later.
1277 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1278 pending_contents_[route_id] = new_contents;
1279 }
1280
1281 if (delegate_) {
1282 delegate_->WebContentsCreated(
1283 this, params.opener_frame_id, params.target_url, new_contents);
1284 }
1285
1286 if (params.opener_suppressed) {
1287 // When the opener is suppressed, the original renderer cannot access the
1288 // new window. As a result, we need to show and navigate the window here.
1289 gfx::Rect initial_pos;
[email protected]dbcdffc2012-08-27 21:17:491290 // TODO(cdn) Fix popup white-listing for links that open in a new process.
[email protected]bafe6cd2012-05-23 23:09:501291 AddNewContents(
[email protected]dbcdffc2012-08-27 21:17:491292 new_contents, params.user_gesture ? params.disposition : NEW_POPUP,
1293 initial_pos, params.user_gesture);
[email protected]bafe6cd2012-05-23 23:09:501294
1295 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1296 CURRENT_TAB,
1297 content::PAGE_TRANSITION_LINK,
1298 true /* is_renderer_initiated */);
1299 new_contents->OpenURL(open_params);
1300 }
1301}
1302
1303void WebContentsImpl::CreateNewWidget(int route_id,
1304 WebKit::WebPopupType popup_type) {
1305 CreateNewWidget(route_id, false, popup_type);
1306}
1307
1308void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1309 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1310}
1311
1312void WebContentsImpl::CreateNewWidget(int route_id,
1313 bool is_fullscreen,
1314 WebKit::WebPopupType popup_type) {
1315 content::RenderProcessHost* process = GetRenderProcessHost();
1316 RenderWidgetHostImpl* widget_host =
1317 new RenderWidgetHostImpl(this, process, route_id);
1318 RenderWidgetHostViewPort* widget_view =
1319 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1320 if (!is_fullscreen) {
1321 // Popups should not get activated.
1322 widget_view->SetPopupType(popup_type);
1323 }
1324 // Save the created widget associated with the route so we can show it later.
1325 pending_widget_views_[route_id] = widget_view;
1326
1327#if defined(OS_MACOSX)
1328 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1329 // to allow it to survive the trip without being hosted.
1330 base::mac::NSObjectRetain(widget_view->GetNativeView());
1331#endif
1332}
1333
1334void WebContentsImpl::ShowCreatedWindow(int route_id,
1335 WindowOpenDisposition disposition,
1336 const gfx::Rect& initial_pos,
1337 bool user_gesture) {
1338 WebContentsImpl* contents = GetCreatedWindow(route_id);
1339 if (contents)
1340 AddNewContents(contents, disposition, initial_pos, user_gesture);
1341}
1342
1343void WebContentsImpl::ShowCreatedWidget(int route_id,
1344 const gfx::Rect& initial_pos) {
1345 ShowCreatedWidget(route_id, false, initial_pos);
1346}
1347
1348void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1349 ShowCreatedWidget(route_id, true, gfx::Rect());
1350}
1351
1352void WebContentsImpl::ShowCreatedWidget(int route_id,
1353 bool is_fullscreen,
1354 const gfx::Rect& initial_pos) {
1355 if (delegate_)
1356 delegate_->RenderWidgetShowing();
1357
1358 RenderWidgetHostViewPort* widget_host_view =
1359 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1360 if (!widget_host_view)
1361 return;
1362 if (is_fullscreen) {
1363 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1364 } else {
1365 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1366 }
[email protected]89054502012-06-03 10:29:241367
1368 RenderWidgetHostImpl* render_widget_host_impl =
1369 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1370 render_widget_host_impl->Init();
1371 // Only allow privileged mouse lock for fullscreen render widget, which is
1372 // used to implement Pepper Flash fullscreen.
1373 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501374
1375#if defined(OS_MACOSX)
1376 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1377 // properly embedded (or purposefully ignored) we can release the retain we
1378 // took in CreateNewWidget().
1379 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1380#endif
1381}
1382
1383WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1384 PendingContents::iterator iter = pending_contents_.find(route_id);
1385
1386 // Certain systems can block the creation of new windows. If we didn't succeed
1387 // in creating one, just return NULL.
1388 if (iter == pending_contents_.end()) {
1389 return NULL;
1390 }
1391
1392 WebContentsImpl* new_contents = iter->second;
1393 pending_contents_.erase(route_id);
1394
1395 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1396 !new_contents->GetRenderViewHost()->GetView())
1397 return NULL;
1398
1399 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1400 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1401 return new_contents;
1402}
1403
1404RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1405 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1406 if (iter == pending_widget_views_.end()) {
1407 DCHECK(false);
1408 return NULL;
1409 }
1410
1411 RenderWidgetHostView* widget_host_view = iter->second;
1412 pending_widget_views_.erase(route_id);
1413
1414 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1415 if (!widget_host->GetProcess()->HasConnection()) {
1416 // The view has gone away or the renderer crashed. Nothing to do.
1417 return NULL;
1418 }
1419
1420 return widget_host_view;
1421}
1422
1423void WebContentsImpl::ShowContextMenu(
1424 const content::ContextMenuParams& params) {
1425 // Allow WebContentsDelegates to handle the context menu operation first.
1426 if (delegate_ && delegate_->HandleContextMenu(params))
1427 return;
1428
[email protected]5a3bdf52012-05-24 15:12:571429 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501430}
1431
[email protected]f13b4202012-06-12 23:53:231432void WebContentsImpl::RequestMediaAccessPermission(
1433 const content::MediaStreamRequest* request,
1434 const content::MediaResponseCallback& callback) {
1435 if (delegate_)
1436 delegate_->RequestMediaAccessPermission(this, request, callback);
1437 else
1438 callback.Run(content::MediaStreamDevices());
1439}
1440
[email protected]b172aee2012-04-10 17:05:261441void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231442 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331443 if (delegate_)
1444 delegate_->UpdatePreferredSize(this, pref_size);
1445}
1446
[email protected]b172aee2012-04-10 17:05:261447void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341448 if (delegate_)
1449 delegate_->ResizeDueToAutoResize(this, new_size);
1450}
1451
[email protected]b172aee2012-04-10 17:05:261452WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201453 if (!delegate_)
1454 return NULL;
[email protected]00c37fc2011-08-02 00:22:501455
[email protected]e5d549d2011-12-28 01:29:201456 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1457 // Notify observers.
1458 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1459 DidOpenURL(params.url, params.referrer,
1460 params.disposition, params.transition));
1461 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341462}
1463
[email protected]6b618e62012-08-16 12:59:181464bool WebContentsImpl::Send(IPC::Message* message) {
1465 if (!GetRenderViewHost()) {
1466 delete message;
1467 return false;
1468 }
1469
1470 return GetRenderViewHost()->Send(message);
1471}
1472
[email protected]b172aee2012-04-10 17:05:261473bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501474 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251475 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231476 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251477 reload_type);
[email protected]876bc832010-09-07 16:29:541478}
[email protected]96d185d2009-04-24 03:28:541479
[email protected]ba45bfd2012-05-22 21:51:441480void WebContentsImpl::RenderViewForInterstitialPageCreated(
1481 content::RenderViewHost* render_view_host) {
1482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1483 RenderViewForInterstitialPageCreated(render_view_host));
1484}
1485
[email protected]b172aee2012-04-10 17:05:261486bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231487 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501488 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401489 // The renderer will reject IPC messages with URLs longer than
1490 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511491 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401492 return false;
1493
[email protected]9f76c1e2012-03-05 15:15:581494 RenderViewHostImpl* dest_render_view_host =
1495 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401496 if (!dest_render_view_host)
1497 return false; // Unable to create the desired render view host.
1498
[email protected]80a8fad2011-01-29 04:02:381499 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071500 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581501 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501502 WebUIControllerFactory* factory =
1503 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271504 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501505 bool is_allowed_in_web_ui_renderer =
1506 factory &&
[email protected]24e18252012-04-16 21:26:271507 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1508 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231509 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1510 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271511 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231512 content::GetContentClient()->SetActiveURL(entry.GetURL());
1513 CHECK(0);
1514 }
[email protected]54ec6472010-04-09 19:39:581515
[email protected]96d185d2009-04-24 03:28:541516 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441517 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521518 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441519 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511520 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541521
[email protected]7bb761892012-07-20 09:32:471522 // Notify observers that we will navigate in this RV.
1523 FOR_EACH_OBSERVER(WebContentsObserver,
1524 observers_,
1525 AboutToNavigateRenderView(dest_render_view_host));
1526
[email protected]96d185d2009-04-24 03:28:541527 // Used for page load time metrics.
1528 current_load_start_ = base::TimeTicks::Now();
1529
1530 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241531 std::string embedder_channel_name;
1532 int embedder_container_id;
1533 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1534 &embedder_channel_name,
1535 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341536 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271537 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241538 embedder_channel_name,
1539 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471540 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341541 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541542
[email protected]36fc0392011-12-25 03:59:511543 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541544 // HACK!! This code suppresses javascript: URLs from being added to
1545 // session history, which is what we want to do for javascript: URLs that
1546 // do not generate content. What we really need is a message from the
1547 // renderer telling us that a new page was not created. The same message
1548 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511549 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541550 return false;
1551 }
1552
[email protected]3c9e1872010-11-18 16:17:491553 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251554 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041555 observers_,
[email protected]36fc0392011-12-25 03:59:511556 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541557
[email protected]09b29342011-06-24 19:18:481558 if (delegate_)
1559 delegate_->DidNavigateToPendingEntry(this);
1560
[email protected]d5f942ba2008-09-26 19:30:341561 return true;
1562}
1563
[email protected]b172aee2012-04-10 17:05:261564void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331565 const SiteInstance* site_instance,
1566 int history_length,
1567 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411568 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1569 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191570 if (render_manager_.pending_render_view_host()) {
1571 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141572 return;
[email protected]9e1ad4b2011-08-14 16:49:191573 }
[email protected]9f76c1e2012-03-05 15:15:581574 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191575 if (!rvh) {
1576 NOTREACHED();
1577 return;
1578 }
[email protected]9f76c1e2012-03-05 15:15:581579 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191580 NOTREACHED();
1581 return;
1582 }
[email protected]6b618e62012-08-16 12:59:181583 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1584 history_length,
1585 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141586}
1587
[email protected]b172aee2012-04-10 17:05:261588void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271589 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541590 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1591 return;
1592 }
[email protected]9f76c1e2012-03-05 15:15:581593 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541594}
1595
[email protected]b172aee2012-04-10 17:05:261596bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271597 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541598}
1599
[email protected]b172aee2012-04-10 17:05:261600InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271601 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221602}
1603
[email protected]b172aee2012-04-10 17:05:261604bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161605 // WebKit creates Document object when MIME type is application/xhtml+xml,
1606 // so we also support this MIME type.
1607 return contents_mime_type_ == "text/html" ||
1608 contents_mime_type_ == "text/xml" ||
1609 contents_mime_type_ == "application/xhtml+xml" ||
1610 contents_mime_type_ == "text/plain" ||
1611 contents_mime_type_ == "text/css" ||
1612 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1613}
1614
[email protected]b172aee2012-04-10 17:05:261615void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591616 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161617 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481618 download_stats::RecordDownloadSource(
1619 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461620 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141621 return;
[email protected]c7dd2f62011-07-18 15:57:591622 }
1623
1624 Stop();
1625
1626 // Create the save package and possibly prompt the user for the name to save
1627 // the page as. The user prompt is an asynchronous operation that runs on
1628 // another thread.
1629 save_package_ = new SavePackage(this);
1630 save_package_->GetSaveInfo();
1631}
1632
1633// Used in automated testing to bypass prompting the user for file names.
1634// Instead, the names and paths are hard coded rather than running them through
1635// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261636bool WebContentsImpl::SavePage(const FilePath& main_file,
1637 const FilePath& dir_path,
1638 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591639 // Stop the page from navigating.
1640 Stop();
1641
1642 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271643 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591644}
1645
[email protected]b172aee2012-04-10 17:05:261646void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121647 const FilePath& file,
1648 const base::Callback<void(const FilePath&, int64)>& callback) {
1649 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1650}
1651
[email protected]b172aee2012-04-10 17:05:261652bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231653 NavigationEntryImpl* active_entry =
1654 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321655 return (active_entry != NULL &&
1656 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511657 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321658}
1659
[email protected]b172aee2012-04-10 17:05:261660const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271661 return contents_mime_type_;
1662}
1663
[email protected]b172aee2012-04-10 17:05:261664bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271665 return notify_disconnection_;
1666}
1667
[email protected]b172aee2012-04-10 17:05:261668void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311669 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181670 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161671}
1672
[email protected]b172aee2012-04-10 17:05:261673void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311674 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181675 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161676}
1677
[email protected]b172aee2012-04-10 17:05:261678content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271679 return &renderer_preferences_;
1680}
1681
[email protected]b172aee2012-04-10 17:05:261682void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271683 new_tab_start_time_ = time;
1684}
1685
[email protected]b172aee2012-04-10 17:05:261686base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271687 return new_tab_start_time_;
1688}
1689
[email protected]e35ccd52012-05-23 16:22:471690void WebContentsImpl::Close() {
1691 Close(GetRenderViewHost());
1692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151695 if (close_start_time_.is_null())
1696 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011697}
1698
[email protected]b172aee2012-04-10 17:05:261699bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191700#if defined(OS_CHROMEOS)
1701 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1702 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511703 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201704 return false;
1705 return true;
[email protected]46624bf2010-06-09 16:04:191706#else
1707 return true;
1708#endif
1709}
1710
[email protected]b172aee2012-04-10 17:05:261711void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521712 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581713 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511714 if (delegate_)
1715 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341716}
1717
[email protected]e35ccd52012-05-23 16:22:471718void WebContentsImpl::UserGestureDone() {
1719 OnUserGesture();
1720}
1721
[email protected]b172aee2012-04-10 17:05:261722void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271723 closed_by_user_gesture_ = value;
1724}
1725
[email protected]b172aee2012-04-10 17:05:261726bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271727 return closed_by_user_gesture_;
1728}
1729
[email protected]b172aee2012-04-10 17:05:261730double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051731 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561732 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251733 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171734 return 0;
[email protected]b75b8292010-10-01 07:28:251735
1736 double zoom_level;
1737 if (temporary_zoom_settings_) {
1738 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581739 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251740 } else {
[email protected]2ae88d12011-10-14 09:11:191741 GURL url;
[email protected]10f417c52011-12-28 21:04:231742 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191743 // Since zoom map is updated using rewritten URL, use rewritten URL
1744 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511745 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191746 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251747 }
[email protected]d0b8d092010-10-25 04:05:171748 return zoom_level;
1749}
[email protected]b75b8292010-10-01 07:28:251750
[email protected]b172aee2012-04-10 17:05:261751int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1752 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171753 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011754 // Calculate the zoom percent from the factor. Round up to the nearest whole
1755 // number.
[email protected]b75b8292010-10-01 07:28:251756 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011757 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251758 *enable_decrement = percent > minimum_zoom_percent_;
1759 *enable_increment = percent < maximum_zoom_percent_;
1760 return percent;
1761}
1762
[email protected]b172aee2012-04-10 17:05:261763void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501764 if (!delegate_)
1765 return;
1766
[email protected]10f417c52011-12-28 21:04:231767 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501768 if (!active_entry)
1769 return;
1770
[email protected]36fc0392011-12-25 03:59:511771 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::ViewFrameSource(const GURL& url,
1775 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271776 if (!delegate_)
1777 return;
1778
1779 delegate_->ViewSourceForFrame(this, url, content_state);
1780}
1781
[email protected]b172aee2012-04-10 17:05:261782int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271783 return minimum_zoom_percent_;
1784}
1785
[email protected]b172aee2012-04-10 17:05:261786int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271787 return maximum_zoom_percent_;
1788}
1789
[email protected]b172aee2012-04-10 17:05:261790gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231791 return preferred_size_;
1792}
1793
[email protected]b172aee2012-04-10 17:05:261794int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271795 return content_restrictions_;
1796}
1797
[email protected]b172aee2012-04-10 17:05:261798WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501799 WebUIControllerFactory* factory =
1800 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1801 if (!factory)
1802 return WebUI::kNoWebUI;
1803 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271804}
1805
[email protected]b172aee2012-04-10 17:05:261806content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271807 // When there is a pending navigation entry, we want to use the pending WebUI
1808 // that goes along with it to control the basic flags. For example, we want to
1809 // show the pending URL in the URL bar, so we want the display_url flag to
1810 // be from the pending entry.
1811 //
1812 // The confusion comes because there are multiple possibilities for the
1813 // initial load in a tab as a side effect of the way the RenderViewHostManager
1814 // works.
1815 //
1816 // - For the very first tab the load looks "normal". The new tab Web UI is
1817 // the pending one, and we want it to apply here.
1818 //
1819 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1820 // get switched to the one previously associated with the new tab pages.
1821 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1822 // have a committed Web UI in this case.
1823 //
1824 // This condition handles all of these cases:
1825 //
1826 // - First load in first tab: no committed nav entry + pending nav entry +
1827 // pending dom ui:
1828 // -> Use pending Web UI if any.
1829 //
1830 // - First load in second tab: no committed nav entry + pending nav entry +
1831 // no pending Web UI:
1832 // -> Use the committed Web UI if any.
1833 //
1834 // - Second navigation in any tab: committed nav entry + pending nav entry:
1835 // -> Use pending Web UI if any.
1836 //
1837 // - Normal state with no load: committed nav entry + no pending nav entry:
1838 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251839 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271840 (controller_.GetLastCommittedEntry() ||
1841 render_manager_.pending_web_ui()))
1842 return render_manager_.pending_web_ui();
1843 return render_manager_.web_ui();
1844}
1845
[email protected]b172aee2012-04-10 17:05:261846bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271847 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581848 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271849}
1850
[email protected]b172aee2012-04-10 17:05:261851bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441852 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501853}
1854
[email protected]b172aee2012-04-10 17:05:261855void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321856 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181857 Send(new ViewMsg_DidChooseColorResponse(
1858 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201859}
1860
[email protected]b172aee2012-04-10 17:05:261861void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181862 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201863 if (delegate_)
1864 delegate_->DidEndColorChooser();
1865 color_chooser_ = NULL;
1866}
1867
[email protected]b172aee2012-04-10 17:05:261868bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471869 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271870 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221871 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231872 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411873 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271874}
1875
[email protected]b172aee2012-04-10 17:05:261876void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271877 if (delegate_)
1878 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211879}
1880
[email protected]3a3b75a2012-06-01 08:38:361881void WebContentsImpl::OnRegisterIntentService(
1882 const webkit_glue::WebIntentServiceData& data,
1883 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431884 if (delegate_)
1885 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301886}
1887
[email protected]b172aee2012-04-10 17:05:261888void WebContentsImpl::OnWebIntentDispatch(
1889 const webkit_glue::WebIntentData& intent,
1890 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431891 if (!delegate_)
1892 return;
1893
[email protected]0d9989d2011-12-21 20:26:001894 WebIntentsDispatcherImpl* intents_dispatcher =
1895 new WebIntentsDispatcherImpl(this, intent, intent_id);
1896 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301897}
1898
[email protected]54047eb52012-05-08 21:45:571899void WebContentsImpl::DidStartProvisionalLoadForFrame(
1900 content::RenderViewHost* render_view_host,
1901 int64 frame_id,
1902 bool is_main_frame,
1903 const GURL& opener_url,
1904 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281905 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181906 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451907 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571908 content::RenderProcessHost* render_process_host =
1909 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541910 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571911 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451912 false,
[email protected]9f76c1e2012-03-05 15:15:581913 &validated_url);
[email protected]ef108e72012-06-20 14:03:541914 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571915 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451916 true,
1917 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181918
[email protected]0d60f0192011-04-14 12:40:101919 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251920 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101921 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571922 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541923
1924 if (is_main_frame) {
1925 // Notify observers about the provisional change in the main frame URL.
1926 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1927 ProvisionalChangeToMainFrameUrl(validated_url,
1928 validated_opener_url,
1929 render_view_host));
1930 }
1931}
1932
1933void WebContentsImpl::DidRedirectProvisionalLoad(
1934 content::RenderViewHost* render_view_host,
1935 int32 page_id,
1936 const GURL& opener_url,
1937 const GURL& source_url,
1938 const GURL& target_url) {
1939 // TODO(creis): Remove this method and have the pre-rendering code listen to
1940 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1941 // instead. See http://crbug.com/78512.
1942 GURL validated_source_url(source_url);
1943 GURL validated_target_url(target_url);
1944 GURL validated_opener_url(opener_url);
1945 content::RenderProcessHost* render_process_host =
1946 render_view_host->GetProcess();
1947 RenderViewHostImpl::FilterURL(
1948 ChildProcessSecurityPolicyImpl::GetInstance(),
1949 render_process_host->GetID(),
1950 false,
1951 &validated_source_url);
1952 RenderViewHostImpl::FilterURL(
1953 ChildProcessSecurityPolicyImpl::GetInstance(),
1954 render_process_host->GetID(),
1955 false,
1956 &validated_target_url);
1957 RenderViewHostImpl::FilterURL(
1958 ChildProcessSecurityPolicyImpl::GetInstance(),
1959 render_process_host->GetID(),
1960 true,
1961 &validated_opener_url);
1962 NavigationEntry* entry;
1963 if (page_id == -1) {
1964 entry = controller_.GetPendingEntry();
1965 } else {
1966 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1967 page_id);
1968 }
1969 if (!entry || entry->GetURL() != validated_source_url)
1970 return;
1971
1972 // Notify observers about the provisional change in the main frame URL.
1973 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1974 ProvisionalChangeToMainFrameUrl(validated_target_url,
1975 validated_opener_url,
1976 render_view_host));
[email protected]724159a2010-12-30 01:11:181977}
1978
[email protected]54047eb52012-05-08 21:45:571979void WebContentsImpl::DidFailProvisionalLoadWithError(
1980 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581981 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1982 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1983 << ", error_code: " << params.error_code
1984 << ", error_description: " << params.error_description
1985 << ", is_main_frame: " << params.is_main_frame
1986 << ", showing_repost_interstitial: " <<
1987 params.showing_repost_interstitial
1988 << ", frame_id: " << params.frame_id;
1989 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571990 content::RenderProcessHost* render_process_host =
1991 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541992 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571993 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451994 false,
[email protected]9f76c1e2012-03-05 15:15:581995 &validated_url);
[email protected]724159a2010-12-30 01:11:181996
[email protected]d7b175e2011-10-11 15:31:581997 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181998 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1999 // This means that the interstitial won't be torn down properly, which is
2000 // bad. But if we have an interstitial, go back to another tab type, and
2001 // then load the same interstitial again, we could end up getting the first
2002 // interstitial's "failed" message (as a result of the cancel) when we're on
2003 // the second one.
2004 //
2005 // We can't tell this apart, so we think we're tearing down the current page
2006 // which will cause a crash later one. There is also some code in
2007 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2008 // out because of this problem.
2009 //
2010 // http://code.google.com/p/chromium/issues/detail?id=2855
2011 // Because this will not tear down the interstitial properly, if "back" is
2012 // back to another tab type, the interstitial will still be somewhat alive
2013 // in the previous tab type. If you navigate somewhere that activates the
2014 // tab with the interstitial again, you'll see a flash before the new load
2015 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272016 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182017 LOG(WARNING) << "Discarding message during interstitial.";
2018 return;
2019 }
2020
[email protected]a16690732012-07-13 19:22:172021 // Do not clear the pending entry if one exists, so that the user's typed
2022 // URL is not lost when a navigation fails or is aborted. We'll allow
2023 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182024
[email protected]54047eb52012-05-08 21:45:572025 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182026 }
2027
[email protected]d8c660432011-12-22 20:51:252028 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582029 observers_,
2030 DidFailProvisionalLoad(params.frame_id,
2031 params.is_main_frame,
2032 validated_url,
2033 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462034 params.error_description,
2035 render_view_host));
[email protected]724159a2010-12-30 01:11:182036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182039 const GURL& url,
[email protected]70435962011-08-02 20:13:282040 const std::string& security_info,
2041 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182042 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282043 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192044 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182045 cache.Increment();
2046
2047 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082048 int cert_id = 0;
2049 net::CertStatus cert_status = 0;
2050 int security_bits = -1;
2051 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512052 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2053 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002054 content::LoadFromMemoryCacheDetails details(
2055 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2056 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182057
[email protected]ad50def52011-10-19 23:17:072058 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272059 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502060 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002061 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182062}
2063
[email protected]b172aee2012-04-10 17:05:262064void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382065 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182066 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192067 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182068}
2069
[email protected]b172aee2012-04-10 17:05:262070void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022071 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232072 LOG(INFO) << security_origin << " ran insecure content from "
2073 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382074 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412075 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2076 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182077 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412078 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192079 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182080}
2081
[email protected]b172aee2012-04-10 17:05:262082void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182083 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252084 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472085 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182086}
2087
[email protected]b172aee2012-04-10 17:05:262088void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312089 int64 frame_id,
2090 const GURL& validated_url,
2091 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252092 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472093 DidFinishLoad(frame_id, validated_url, is_main_frame,
2094 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312095}
2096
[email protected]b172aee2012-04-10 17:05:262097void WebContentsImpl::OnDidFailLoadWithError(
2098 int64 frame_id,
2099 const GURL& validated_url,
2100 bool is_main_frame,
2101 int error_code,
2102 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252103 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312104 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472105 error_code, error_description,
2106 message_source_));
[email protected]724159a2010-12-30 01:11:182107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272110 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432111 if (delegate_)
2112 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172113}
2114
[email protected]b172aee2012-04-10 17:05:262115void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262116 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232117 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252118 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262119 if (!entry)
2120 return;
2121 // Note that we don't call NavigationController::GotToOffset() as we don't
2122 // want to create a pending navigation entry (it might end up lingering
2123 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252124 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582125 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512126 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582127 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472128 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572129
2130 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2131 // it in now that we know. This allows us to find the entry when it commits.
2132 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232133 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332134 entry->set_site_instance(
2135 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572136 }
[email protected]216813952011-05-19 22:21:262137 }
2138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2141 int maximum_percent,
2142 bool remember) {
[email protected]216813952011-05-19 22:21:262143 minimum_zoom_percent_ = minimum_percent;
2144 maximum_zoom_percent_ = maximum_percent;
2145 temporary_zoom_settings_ = !remember;
2146}
2147
[email protected]20b433a2012-05-15 21:23:462148void WebContentsImpl::OnSaveURL(const GURL& url,
2149 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482150 download_stats::RecordDownloadSource(
2151 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262152 // Check if the URL to save matches the URL of the main frame. Since this
2153 // message originates from Pepper plugins, it may not be the case if the
2154 // plugin is an embedded element.
2155 GURL main_frame_url = GetURL();
2156 if (!main_frame_url.is_valid())
2157 return;
2158 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462159 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272160}
2161
[email protected]b172aee2012-04-10 17:05:262162void WebContentsImpl::OnEnumerateDirectory(int request_id,
2163 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432164 if (!delegate_)
2165 return;
2166
[email protected]b9535422012-02-09 01:47:592167 ChildProcessSecurityPolicyImpl* policy =
2168 ChildProcessSecurityPolicyImpl::GetInstance();
2169 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2170 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212171}
2172
[email protected]b172aee2012-04-10 17:05:262173void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432174 if (delegate_)
2175 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202176}
2177
[email protected]b172aee2012-04-10 17:05:262178void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2179 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362180 const string16& title,
2181 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432182 if (!delegate_)
2183 return;
2184
[email protected]b9535422012-02-09 01:47:592185 ChildProcessSecurityPolicyImpl* policy =
2186 ChildProcessSecurityPolicyImpl::GetInstance();
2187 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2188 return;
[email protected]3a3b75a2012-06-01 08:38:362189 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202190}
2191
[email protected]b172aee2012-04-10 17:05:262192void WebContentsImpl::OnFindReply(int request_id,
2193 int number_of_matches,
2194 const gfx::Rect& selection_rect,
2195 int active_match_ordinal,
2196 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432197 if (delegate_) {
2198 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2199 active_match_ordinal, final_update);
2200 }
[email protected]b888919c2011-09-02 00:32:162201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2205 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452206}
2207
[email protected]b172aee2012-04-10 17:05:262208void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2209 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102210 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252211 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102212 AppCacheAccessed(manifest_url, blocked_by_policy));
2213}
2214
[email protected]b172aee2012-04-10 17:05:262215void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322216 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432217 color_chooser_ = delegate_ ?
2218 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202219}
2220
[email protected]b172aee2012-04-10 17:05:262221void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202222 if (color_chooser_ &&
2223 color_chooser_id == color_chooser_->identifier())
2224 color_chooser_->End();
2225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322228 SkColor color) {
[email protected]da8543762012-03-20 08:52:202229 if (color_chooser_ &&
2230 color_chooser_id == color_chooser_->identifier())
2231 color_chooser_->SetSelectedColor(color);
2232}
2233
[email protected]9f2a9d72012-04-16 16:02:222234void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2235 const FilePath& path,
2236 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442237 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2238 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292239}
2240
[email protected]d0759f492012-04-19 22:50:502241// This exists for render views that don't have a WebUI, but do have WebUI
2242// bindings enabled.
2243void WebContentsImpl::OnWebUISend(const GURL& source_url,
2244 const std::string& name,
2245 const base::ListValue& args) {
2246 if (delegate_)
2247 delegate_->WebUISend(this, source_url, name, args);
2248}
2249
[email protected]d8415ad92012-08-23 14:40:502250void WebContentsImpl::OnRequestPpapiBrokerPermission(
2251 int request_id,
2252 const GURL& url,
2253 const FilePath& plugin_path) {
2254 base::Callback<void(bool)> callback =
2255 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2256 base::Unretained(this), request_id);
2257 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2258 WebContentsObserver* observer;
2259 while ((observer = it.GetNext()) != NULL) {
2260 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2261 callback))
2262 return;
2263 }
2264
2265 // Fall back to allowing the request if no observer handled it.
2266 OnPpapiBrokerPermissionResult(request_id, true);
2267}
2268
2269void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2270 bool result) {
2271 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2272 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2273 request_id,
2274 result));
2275}
2276
[email protected]96d185d2009-04-24 03:28:542277// Notifies the RenderWidgetHost instance about the fact that the page is
2278// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::SetIsLoading(bool is_loading,
2280 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542281 if (is_loading == is_loading_)
2282 return;
2283
2284 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212285 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542286 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562287 upload_size_ = 0;
2288 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542289 }
2290
2291 render_manager_.SetIsLoading(is_loading);
2292
2293 is_loading_ = is_loading;
2294 waiting_for_response_ = is_loading;
2295
[email protected]6ebdc9b2010-09-27 16:55:572296 if (delegate_)
2297 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462298 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542299
[email protected]432115822011-07-10 15:52:272300 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2301 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072302 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542303 if (details)
[email protected]6c2381d2011-10-19 02:52:532304 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072305 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502306 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542307 det);
2308}
2309
[email protected]b172aee2012-04-10 17:05:262310void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132311 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322312 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562313 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382314 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442315 // that opened the window, as long as both renderers have the same
2316 // privileges.
[email protected]1fd1a502011-03-30 16:55:562317 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562318 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582319 // web_ui might be NULL if the URL refers to a non-existent extension.
2320 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402321 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522322 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442323 }
2324 }
[email protected]1fd1a502011-03-30 16:55:562325 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442326 }
2327
[email protected]4e697b042011-07-08 06:44:562328 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322329 // Clear the status bubble. This is a workaround for a bug where WebKit
2330 // doesn't let us know that the cursor left an element during a
2331 // transition (this is also why the mouse cursor remains as a hand after
2332 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2333 // clear the bubble when a user navigates to a named anchor in the same
2334 // page.
[email protected]36fc0392011-12-25 03:59:512335 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322336 }
2337
[email protected]a6e82fc2010-02-24 22:28:142338 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472339 // Once the main frame is navigated, we're no longer considered to have
2340 // displayed insecure content.
2341 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172342 }
[email protected]ce5c4502009-05-06 16:46:112343
[email protected]3c9e1872010-11-18 16:17:492344 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252345 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042346 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322347}
2348
[email protected]b172aee2012-04-10 17:05:262349void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322350 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132351 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322352 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062353 // If we navigate off the page, reset JavaScript state. This does nothing
2354 // to prevent a malicious script from spamming messages, since the script
2355 // could just reload the page to stop blocking.
2356 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552357 dialog_creator_->ResetJavaScriptState(this);
2358 dialog_creator_ = NULL;
2359 }
[email protected]420ae012009-04-24 05:16:322360
[email protected]3c9e1872010-11-18 16:17:492361 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252362 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042363 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322364}
2365
[email protected]b172aee2012-04-10 17:05:262366void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462367 // If we are creating a RVH for a restored controller, then we need to make
2368 // sure the RenderView starts with a next_page_id_ larger than the number
2369 // of restored entries. This must be called before the RenderView starts
2370 // navigating (to avoid a race between the browser updating max_page_id and
2371 // the renderer updating next_page_id_). Because of this, we only call this
2372 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562373 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582374 if (max_restored_page_id >
2375 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2376 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2377 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322378}
2379
[email protected]b172aee2012-04-10 17:05:262380bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2381 const string16& title) {
[email protected]420ae012009-04-24 05:16:322382 // For file URLs without a title, use the pathname instead. In the case of a
2383 // synthesized title, we don't want the update to count toward the "one set
2384 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512385 string16 final_title;
[email protected]420ae012009-04-24 05:16:322386 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512387 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2388 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322389 explicit_set = false; // Don't count synthetic titles toward the set limit.
2390 } else {
[email protected]acafd272011-07-26 17:35:572391 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322392 explicit_set = true;
2393 }
2394
[email protected]987fc3a2011-05-26 14:18:092395 // If a page is created via window.open and never navigated,
2396 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552397 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092398 if (entry) {
[email protected]36fc0392011-12-25 03:59:512399 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092400 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322401
[email protected]36fc0392011-12-25 03:59:512402 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092403 } else {
2404 if (page_title_when_no_navigation_entry_ == final_title)
2405 return false; // Nothing changed, don't bother.
2406
2407 page_title_when_no_navigation_entry_ = final_title;
2408 }
[email protected]420ae012009-04-24 05:16:322409
[email protected]420ae012009-04-24 05:16:322410 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232411 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322412
[email protected]2bb171882012-03-07 02:09:462413 std::pair<content::NavigationEntry*, bool> details =
2414 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142415
[email protected]ad50def52011-10-19 23:17:072416 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442417 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2418 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462419 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042420
[email protected]420ae012009-04-24 05:16:322421 return true;
2422}
2423
[email protected]b172aee2012-04-10 17:05:262424void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322425 // After sending out a swap notification, we need to send a disconnect
2426 // notification so that clients that pick up a pointer to |this| can NULL the
2427 // pointer. See Bug 1230284.
2428 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072429 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202430 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2431 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072432 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322433}
2434
[email protected]b172aee2012-04-10 17:05:262435void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322436 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072437 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122438 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2439 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072440 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322441}
2442
[email protected]b172aee2012-04-10 17:05:262443void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322444 if (!notify_disconnection_)
2445 return;
2446
2447 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072448 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322449 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2450 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072451 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322452}
2453
[email protected]5a3bdf52012-05-24 15:12:572454RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2455 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322456}
2457
[email protected]8d3347f2009-07-09 22:00:212458RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262459WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212460 return &render_manager_;
2461}
2462
[email protected]b172aee2012-04-10 17:05:262463content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372464 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462465 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512466}
2467
[email protected]b172aee2012-04-10 17:05:262468WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172469 return this;
2470}
2471
[email protected]b172aee2012-04-10 17:05:262472gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172473 if (delegate_)
2474 return delegate_->GetRootWindowResizerRect();
2475 return gfx::Rect();
2476}
2477
[email protected]b172aee2012-04-10 17:05:262478void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442479 // Don't send notifications if we are just creating a swapped-out RVH for
2480 // the opener chain. These won't be used for view-source or WebUI, so it's
2481 // ok to return early.
2482 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2483 return;
2484
[email protected]ad50def52011-10-19 23:17:072485 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302486 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322487 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532488 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232489 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322490 if (!entry)
2491 return;
2492
2493 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352494 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562495 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582496 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322497
2498 if (entry->IsViewSourceMode()) {
2499 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182500 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582501 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322502 }
[email protected]0666aef2009-05-13 19:48:082503
[email protected]d487beefe2011-12-21 05:41:212504 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262505
2506 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252507 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322508}
2509
[email protected]b172aee2012-04-10 17:05:262510void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522511 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322512 // Don't notify the world, since this came from a renderer in the
2513 // background.
2514 return;
2515 }
2516
2517 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312518 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232519 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302520
2521 // Restore the focus to the tab (otherwise the focus will be on the top
2522 // window).
[email protected]484ae5912010-09-29 19:16:142523 if (was_crashed && !FocusLocationBarByDefault() &&
2524 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302525 Focus();
[email protected]484ae5912010-09-29 19:16:142526 }
[email protected]32ded2212011-11-10 18:51:432527
[email protected]d8c660432011-12-22 20:51:252528 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2532 base::TerminationStatus status,
2533 int error_code) {
[email protected]151a63d2011-12-20 22:32:522534 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322535 // The pending page's RenderViewHost is gone.
2536 return;
2537 }
2538
2539 SetIsLoading(false, NULL);
2540 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232541 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312542 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322543
[email protected]d8c660432011-12-22 20:51:252544 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272545 observers_,
[email protected]be1f56ab2011-12-22 06:55:312546 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322547}
2548
[email protected]b172aee2012-04-10 17:05:262549void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482550 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252551 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062552}
2553
[email protected]b172aee2012-04-10 17:05:262554void WebContentsImpl::DidNavigate(
2555 RenderViewHost* rvh,
2556 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582557 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322558 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372559
[email protected]434f69f2012-02-06 21:56:522560 // Update the site of the SiteInstance if it doesn't have one yet, unless
2561 // this is for about:blank. In that case, the SiteInstance can still be
2562 // considered unused until a navigation to a real page.
2563 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2564 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332565 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522566 }
[email protected]420ae012009-04-24 05:16:322567
2568 // Need to update MIME type here because it's referred to in
2569 // UpdateNavigationCommands() called by RendererDidNavigate() to
2570 // determine whether or not to enable the encoding menu.
2571 // It's updated only for the main frame. For a subframe,
2572 // RenderView::UpdateURL does not set params.contents_mime_type.
2573 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2574 // TODO(jungshik): Add a test for the encoding menu to avoid
2575 // regressing it again.
[email protected]2905f742011-10-13 03:51:582576 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322577 contents_mime_type_ = params.contents_mime_type;
2578
[email protected]8286f51a2011-05-31 17:39:132579 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002580 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392581
[email protected]a9c0bfe2010-09-17 08:35:222582 // Send notification about committed provisional loads. This notification is
2583 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2584 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082585 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072586 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2587 // that is not recorded in the navigation history. For the purpose of
2588 // tracking navigation events, we treat this event as a sub frame navigation
2589 // event.
2590 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582591 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222592 // Whether or not a page transition was triggered by going backward or
2593 // forward in the history is only stored in the navigation controller's
2594 // entry list.
2595 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512596 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582597 content::PAGE_TRANSITION_FORWARD_BACK)) {
2598 transition_type = content::PageTransitionFromInt(
2599 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222600 }
[email protected]0d60f0192011-04-14 12:40:102601 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252602 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102603 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462604 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222605 }
2606
[email protected]76543b92009-08-31 17:27:452607 if (!did_navigate)
2608 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322609
2610 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2611 // for the appropriate notification (best) or you can add it to
2612 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2613 // necessary, please).
2614
2615 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002616 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322617 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512618 if (delegate_)
2619 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002620 }
[email protected]420ae012009-04-24 05:16:322621 DidNavigateAnyFramePostCommit(rvh, details, params);
2622}
2623
[email protected]b172aee2012-04-10 17:05:262624void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2625 int32 page_id,
2626 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152627 // Ensure that this state update comes from either the active RVH or one of
2628 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522629 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322630
2631 // We must be prepared to handle state updates for any page, these occur
2632 // when the user is scrolling and entering form data, as well as when we're
2633 // leaving a page, in which case our state may have already been moved to
2634 // the next page. The navigation controller will look up the appropriate
2635 // NavigationEntry and update it when it is notified via the delegate.
2636
2637 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582638 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322639 if (entry_index < 0)
2640 return;
[email protected]10f417c52011-12-28 21:04:232641 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322642
[email protected]36fc0392011-12-25 03:59:512643 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322644 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512645 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322646 controller_.NotifyEntryChanged(entry, entry_index);
2647}
2648
[email protected]b172aee2012-04-10 17:05:262649void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2650 int32 page_id,
2651 const string16& title,
2652 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322653 // If we have a title, that's a pretty good indication that we've started
2654 // getting useful data.
2655 SetNotWaitingForResponse();
2656
[email protected]73eb2602012-02-09 19:50:552657 // Try to find the navigation entry, which might not be the current one.
2658 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232659 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582660 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092661
[email protected]73eb2602012-02-09 19:50:552662 // We can handle title updates when we don't have an entry in
2663 // UpdateTitleForEntry, but only if the update is from the current RVH.
2664 if (!entry && rvh != GetRenderViewHost())
2665 return;
2666
[email protected]a49e10b2011-08-01 23:57:462667 // TODO(evan): make use of title_direction.
2668 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092669 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322670 return;
2671
2672 // Broadcast notifications when the UI should be updated.
2673 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462674 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322675}
2676
[email protected]b172aee2012-04-10 17:05:262677void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2678 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312679 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322680}
2681
[email protected]b172aee2012-04-10 17:05:262682void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512683 if (delegate_)
2684 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322685}
2686
[email protected]b172aee2012-04-10 17:05:262687void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292688 // The UI may be in an event-tracking loop, such as between the
2689 // mouse-down and mouse-up in text selection or a button click.
2690 // Defer the close until after tracking is complete, so that we
2691 // don't free objects out from under the UI.
2692 // TODO(shess): This could probably be integrated with the
2693 // IsDoingDrag() test below. Punting for now because I need more
2694 // research to understand how this impacts platforms other than Mac.
2695 // TODO(shess): This could get more fine-grained. For instance,
2696 // closing a tab in another window while selecting text in the
2697 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212698 if (GetView()->IsEventTracking()) {
2699 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292700 return;
2701 }
2702
[email protected]24a4d1062009-07-10 23:10:422703 // If we close the tab while we're in the middle of a drag, we'll crash.
2704 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212705 if (GetView()->IsDoingDrag()) {
2706 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422707 return;
2708 }
2709
[email protected]420ae012009-04-24 05:16:322710 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522711 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512712 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322713}
2714
[email protected]b172aee2012-04-10 17:05:262715void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522716 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512717 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572718}
2719
[email protected]b172aee2012-04-10 17:05:262720void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512721 if (delegate_ && delegate_->IsPopupOrPanel(this))
2722 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322723}
2724
[email protected]89793072012-07-23 22:25:292725void WebContentsImpl::DidStartLoading(
2726 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322727 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492728
[email protected]82114f52012-03-20 22:53:412729 if (delegate_ && content_restrictions_)
2730 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492731
2732 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292733 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2734 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322735}
2736
[email protected]89793072012-07-23 22:25:292737void WebContentsImpl::DidStopLoading(
2738 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322739 scoped_ptr<LoadNotificationDetails> details;
2740
[email protected]10f417c52011-12-28 21:04:232741 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322742 // An entry may not exist for a stop when loading an initial blank page or
2743 // if an iframe injected by script into a blank page finishes loading.
2744 if (entry) {
[email protected]420ae012009-04-24 05:16:322745 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2746
2747 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512748 entry->GetVirtualURL(),
2749 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322750 elapsed,
2751 &controller_,
2752 controller_.GetCurrentEntryIndex()));
2753 }
2754
[email protected]420ae012009-04-24 05:16:322755 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492756
2757 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292758 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2759 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322760}
2761
[email protected]b172aee2012-04-10 17:05:262762void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162763 controller_.DiscardNonCommittedEntries();
2764
2765 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462766 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162767}
2768
[email protected]b172aee2012-04-10 17:05:262769void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512770 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132771 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402772}
2773
[email protected]0720b532012-08-28 19:23:372774void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2775 render_manager_.DidUpdateFrameTree(rvh);
2776}
2777
[email protected]87717d0e2012-04-26 02:58:432778void WebContentsImpl::DocumentAvailableInMainFrame(
2779 RenderViewHost* render_view_host) {
2780 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2781 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102782}
2783
[email protected]b172aee2012-04-10 17:05:262784void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082785 RenderViewHost* render_view_host,
2786 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072787 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272788 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322789 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532790 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082791}
2792
[email protected]196159d2012-05-04 17:26:542793void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2794 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262795 const content::Referrer& referrer,
2796 WindowOpenDisposition disposition,
2797 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542798 // If this came from a swapped out RenderViewHost, we only allow the request
2799 // if we are still in the same BrowsingInstance.
2800 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2801 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2802 return;
2803 }
2804
[email protected]4ad5d77d2011-12-03 02:00:482805 // Delegate to RequestTransferURL because this is just the generic
2806 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582807 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482808 GlobalRequestID());
2809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::RequestTransferURL(
2812 const GURL& url,
2813 const content::Referrer& referrer,
2814 WindowOpenDisposition disposition,
2815 int64 source_frame_id,
2816 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202817 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582818 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582819 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352820 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322821 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2822 // generated suggestions).
2823 //
[email protected]e0112912011-02-02 22:54:352824 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162825 // want web sites to see a referrer of "chrome://blah" (and some
2826 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322827 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432828 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222829 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482830 false /* is_renderer_initiated */);
2831 params.transferred_global_request_id = old_request_id;
2832 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222833 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322834 } else {
[email protected]6bf6a6b52012-02-03 15:41:432835 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482836 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2837 params.transferred_global_request_id = old_request_id;
2838 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582839 }
2840 if (new_contents) {
2841 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252842 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582843 DidOpenRequestedURL(new_contents,
2844 url,
2845 referrer,
2846 disposition,
2847 transition_type,
2848 source_frame_id));
[email protected]420ae012009-04-24 05:16:322849 }
2850}
2851
[email protected]e1c3a552012-05-04 20:51:322852void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2853 // Tell the active RenderViewHost to run unload handlers and close, as long
2854 // as the request came from a RenderViewHost in the same BrowsingInstance.
2855 // In most cases, we receive this from a swapped out RenderViewHost.
2856 // It is possible to receive it from one that has just been swapped in,
2857 // in which case we might as well deliver the message anyway.
2858 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2859 GetRenderViewHost()->ClosePage();
2860}
2861
[email protected]f546640b2012-05-15 00:03:492862void WebContentsImpl::RouteMessageEvent(
2863 RenderViewHost* rvh,
2864 const ViewMsg_PostMessage_Params& params) {
2865 // Only deliver the message to the active RenderViewHost if the request
2866 // came from a RenderViewHost in the same BrowsingInstance.
2867 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2868 return;
2869
2870 ViewMsg_PostMessage_Params new_params(params);
2871
[email protected]0720b532012-08-28 19:23:372872 // If the renderer has changed while the post message is being routed,
2873 // drop the message, as it will not be delivered to the right target.
2874 if (GetRenderViewHost()->GetProcess()->GetID() != params.target_process_id)
2875 return;
2876 DCHECK(params.target_frame_id != 0);
2877
[email protected]f546640b2012-05-15 00:03:492878 // If there is a source_routing_id, translate it to the routing ID for
2879 // the equivalent swapped out RVH in the target process. If we need
2880 // to create a swapped out RVH for the source tab, we create its opener
2881 // chain as well, since those will also be accessible to the target page.
2882 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2883 // Try to look up the WebContents for the source page.
2884 WebContentsImpl* source_contents = NULL;
2885 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2886 rvh->GetProcess()->GetID(), params.source_routing_id);
2887 if (source_rvh) {
2888 source_contents = static_cast<WebContentsImpl*>(
2889 source_rvh->GetDelegate()->GetAsWebContents());
2890 }
2891
2892 if (source_contents) {
2893 new_params.source_routing_id =
2894 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2895 } else {
2896 // We couldn't find it, so don't pass a source frame.
2897 new_params.source_routing_id = MSG_ROUTING_NONE;
2898 }
2899 }
2900
2901 // In most cases, we receive this from a swapped out RenderViewHost.
2902 // It is possible to receive it from one that has just been swapped in,
2903 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182904 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492905}
2906
[email protected]b172aee2012-04-10 17:05:262907void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342908 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412909 const string16& message,
2910 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322911 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142912 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322913 IPC::Message* reply_msg,
2914 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072915 // Suppress JavaScript dialogs when requested. Also suppress messages when
2916 // showing an interstitial as it's shown over the previous page and we don't
2917 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502918 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582919 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272920 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072921 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522922 delegate_->ShouldSuppressDialogs() ||
2923 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322924
2925 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432926 std::string accept_lang = content::GetContentClient()->browser()->
2927 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552928 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522929 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432930 this,
2931 frame_url.GetOrigin(),
2932 accept_lang,
2933 javascript_message_type,
2934 message,
[email protected]51da7e32012-01-30 19:24:522935 default_prompt,
[email protected]b172aee2012-04-10 17:05:262936 base::Bind(&WebContentsImpl::OnDialogClosed,
2937 base::Unretained(this),
2938 rvh,
2939 reply_msg),
[email protected]51da7e32012-01-30 19:24:522940 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322941 }
[email protected]3ab9cb82011-06-03 18:02:072942
2943 if (suppress_this_message) {
2944 // If we are suppressing messages, just reply as if the user immediately
2945 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342946 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072947 }
2948
2949 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322950}
2951
[email protected]b172aee2012-04-10 17:05:262952void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2953 const string16& message,
2954 bool is_reload,
2955 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582956 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512957 if (delegate_)
2958 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072959
2960 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582961 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072962 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522963 delegate_->ShouldSuppressDialogs() ||
2964 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152965 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342966 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582967 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502968 return;
2969 }
[email protected]3ab9cb82011-06-03 18:02:072970
[email protected]7ab1e7d62009-10-14 23:32:012971 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552972 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522973 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322974 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262975 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522976 reply_msg));
[email protected]420ae012009-04-24 05:16:322977}
2978
[email protected]a796f202012-05-30 14:14:252979bool WebContentsImpl::AddMessageToConsole(int32 level,
2980 const string16& message,
2981 int32 line_no,
2982 const string16& source_id) {
2983 if (!delegate_)
2984 return false;
2985 return delegate_->AddMessageToConsole(this, level, message, line_no,
2986 source_id);
2987}
2988
[email protected]b172aee2012-04-10 17:05:262989WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332990 // We want to base the page config off of the real URL, rather than the
2991 // display URL.
2992 GURL url = controller_.GetActiveEntry()
2993 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2994 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322995}
2996
[email protected]b172aee2012-04-10 17:05:262997void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272998 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252999 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223000
[email protected]ea114722012-03-12 01:11:253001 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173002 if (rdh) // NULL in unittests.
3003 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253004}
3005
[email protected]b172aee2012-04-10 17:05:263006void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443007 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253008 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443009}
3010
[email protected]b172aee2012-04-10 17:05:263011void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3012 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153013 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523014 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153015 return;
3016
[email protected]9f76c1e2012-03-05 15:15:583017 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3018
[email protected]e5fc1632011-08-08 07:51:533019 // Ignore renderer unresponsive event if debugger is attached to the tab
3020 // since the event may be a result of the renderer sitting on a breakpoint.
3021 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443022 DevToolsAgentHost* agent =
3023 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3024 if (agent &&
3025 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533026 return;
3027
[email protected]420ae012009-04-24 05:16:323028 if (is_during_unload) {
3029 // Hang occurred while firing the beforeunload/unload handler.
3030 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583031 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323032
3033 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3034 return;
3035
3036 // If the tab hangs in the beforeunload/unload handler there's really
3037 // nothing we can do to recover. Pretend the unload listeners have
3038 // all fired and close the tab. If the hang is in the beforeunload handler
3039 // then the user will not have the option of cancelling the close.
3040 Close(rvh);
3041 return;
3042 }
3043
[email protected]9f76c1e2012-03-05 15:15:583044 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473045 return;
3046
[email protected]6934a702011-12-20 00:04:513047 if (delegate_)
3048 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323049}
3050
[email protected]b172aee2012-04-10 17:05:263051void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513052 if (delegate_)
3053 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323054}
3055
[email protected]b172aee2012-04-10 17:05:263056void WebContentsImpl::LoadStateChanged(
3057 const GURL& url,
3058 const net::LoadStateWithParam& load_state,
3059 uint64 upload_position,
3060 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323061 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563062 upload_position_ = upload_position;
3063 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503064 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203065 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303066 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213067 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323068 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463069 if (IsLoading()) {
3070 NotifyNavigationStateChanged(
3071 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3072 }
[email protected]420ae012009-04-24 05:16:323073}
3074
[email protected]b172aee2012-04-10 17:05:263075void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513076 if (delegate_)
3077 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253078}
3079
[email protected]b172aee2012-04-10 17:05:263080void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323081 bool proceed,
3082 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513083 if (delegate_)
3084 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323085}
3086
[email protected]b172aee2012-04-10 17:05:263087void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543088 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233089 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3090 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543091}
3092
[email protected]b172aee2012-04-10 17:05:263093void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103094 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263095 gfx::Size size = view_->GetContainerSize();
3096 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3097 // here during container initialization and normal window size will be set
3098 // later. In case of tab duplication this resizing to 0x0 prevents setting
3099 // normal size later so just ignore it.
3100 if (!size.IsEmpty())
3101 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323102}
3103
[email protected]b172aee2012-04-10 17:05:263104void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543105 NotifySwapped();
3106}
3107
[email protected]14392a52012-05-02 20:28:443108int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3109 SiteInstance* instance) {
3110 if (!opener_)
3111 return MSG_ROUTING_NONE;
3112
3113 // Recursively create RenderViews for anything else in the opener chain.
3114 return opener_->CreateOpenerRenderViews(instance);
3115}
3116
3117int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3118 int opener_route_id = MSG_ROUTING_NONE;
3119
3120 // If this tab has an opener, ensure it has a RenderView in the given
3121 // SiteInstance as well.
3122 if (opener_)
3123 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3124
[email protected]0720b532012-08-28 19:23:373125 // If any of the renderers for this WebContents has the same SiteInstance,
3126 // use it.
3127 if (render_manager_.current_host()->GetSiteInstance() == instance)
3128 return render_manager_.current_host()->GetRoutingID();
3129
3130 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3131 instance);
3132 if (rvh)
3133 return rvh->GetRoutingID();
3134
[email protected]14392a52012-05-02 20:28:443135 // Create a swapped out RenderView in the given SiteInstance if none exists,
3136 // setting its opener to the given route_id. Return the new view's route_id.
3137 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3138}
3139
[email protected]b172aee2012-04-10 17:05:263140NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193141 return GetController();
[email protected]3a3d47472010-07-15 21:03:543142}
3143
[email protected]b172aee2012-04-10 17:05:263144WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563145 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323146}
3147
[email protected]10f417c52011-12-28 21:04:233148NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263149 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323150 return controller_.GetLastCommittedEntry();
3151}
3152
[email protected]b172aee2012-04-10 17:05:263153bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443154 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443155 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323156 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523157
[email protected]420ae012009-04-24 05:16:323158 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443159 if (rwh_view)
3160 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323161
[email protected]74ce1ad2011-12-16 21:51:463162 // Make sure we use the correct starting page_id in the new RenderView.
3163 UpdateMaxPageIDIfNecessary(render_view_host);
3164 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583165 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463166
[email protected]7900bfdb2012-05-24 19:31:243167 std::string embedder_channel_name;
3168 int embedder_container_id;
3169 GetBrowserPluginEmbedderInfo(render_view_host,
3170 &embedder_channel_name,
3171 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583172 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493173 render_view_host)->CreateRenderView(string16(),
3174 opener_route_id,
3175 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243176 embedder_channel_name,
3177 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523178 return false;
[email protected]14392a52012-05-02 20:28:443179 }
[email protected]a4127722011-04-27 23:13:523180
[email protected]e60c0232011-11-11 19:56:353181#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503182 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3183 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443184 if (rwh_view) {
3185 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3186 render_widget_host->WasResized();
3187 }
[email protected]f8233cc2011-05-31 20:24:503188#endif
3189
[email protected]420ae012009-04-24 05:16:323190 return true;
3191}
3192
[email protected]b172aee2012-04-10 17:05:263193void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3194 IPC::Message* reply_msg,
3195 bool success,
3196 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543197 if (is_showing_before_unload_dialog_ && !success) {
3198 // If a beforeunload dialog is canceled, we need to stop the throbber from
3199 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293200 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353201 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543202
[email protected]3bbacc5b2012-04-17 17:46:153203 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543204 }
3205 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583206 static_cast<RenderViewHostImpl*>(
3207 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543208}
3209
[email protected]b172aee2012-04-10 17:05:263210void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123211 encoding_ = content::GetContentClient()->browser()->
3212 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103213}
[email protected]f45d2a72010-03-08 23:28:353214
[email protected]b172aee2012-04-10 17:05:263215void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463216 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263217 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573218 DownloadManager* dlm =
3219 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143220 if (!dlm)
3221 return;
3222 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263223 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143224 const NavigationEntry* entry = controller_.GetActiveEntry();
3225 if (entry)
3226 post_id = entry->GetPostID();
3227 }
[email protected]29a5ffc82012-03-13 19:35:583228 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143229 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143230 scoped_ptr<DownloadUrlParameters> params(
3231 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493232 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143233 params->set_post_id(post_id);
3234 params->set_prefer_cache(true);
3235 if (post_id >= 0)
3236 params->set_method("POST");
3237 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143238}
3239
[email protected]b172aee2012-04-10 17:05:263240void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213241 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443242 // Can be NULL during tests.
3243 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213244 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363245}
[email protected]9f76c1e2012-03-05 15:15:583246
[email protected]b172aee2012-04-10 17:05:263247RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583248 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3249}
[email protected]7900bfdb2012-05-24 19:31:243250
3251void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3252 content::RenderViewHost* render_view_host,
3253 std::string* embedder_channel_name,
3254 int* embedder_container_id) {
3255 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283256 old_browser_plugin_host()->embedder_render_process_host();
3257 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243258 int embedder_process_id =
3259 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3260 if (embedder_process_id != -1) {
3261 *embedder_channel_name =
3262 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3263 embedder_process_id);
3264 }
3265}