blob: cee3043ec6c0f9d39b64d34c1fbab5f98f3d9b5f [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]cc510d7e2012-08-08 04:40:1018#include "content/browser/browser_plugin/old/old_browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5919#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4420#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1921#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0422#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4623#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1224#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1625#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3226#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5427#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0528#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0029#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3030#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3231#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5032#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2533#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3334#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3735#include "content/browser/web_contents/interstitial_page_impl.h"
36#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5741#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5842#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1143#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2044#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4445#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4446#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1747#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1448#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4649#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1550#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0051#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2752#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0053#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3754#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1455#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3256#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3857#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4258#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2559#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1060#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5061#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2162#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4863#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1864#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5465#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0366#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1667#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2968#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5469#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3470#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3771#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5672#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4173#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0174#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4175#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5276#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2477#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3678#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3179#include "webkit/glue/webpreferences.h"
80
[email protected]f66df822012-05-18 16:52:1781#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5082#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5784#endif
[email protected]3e45ba92009-02-20 21:09:0085
[email protected]c71fe6402012-08-15 15:22:5586#if defined(USE_AURA) && defined(USE_X11)
87#include "ui/base/touch/touch_factory.h"
88#endif // defined (USE_AURA) && defined(USE_X11)
89
[email protected]420ae012009-04-24 05:16:3290// Cross-Site Navigations
91//
[email protected]b172aee2012-04-10 17:05:2692// If a WebContentsImpl is told to navigate to a different web site (as
93// determined by SiteInstance), it will replace its current RenderViewHost with
94// a new RenderViewHost dedicated to the new SiteInstance. This works as
95// follows:
[email protected]420ae012009-04-24 05:16:3296//
97// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4698// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3299// - The pending RVH is "suspended," so that no navigation messages are sent to
100// its renderer until the onbeforeunload JavaScript handler has a chance to
101// run in the current RVH.
102// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
103// that it has a pending cross-site request. ResourceDispatcherHost will
104// check for this when the response arrives.
105// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46106// cancel all the pending logic. Otherwise we allow the pending RVH to send
107// the navigation request to its renderer.
108// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
109// main resource load on the pending RVH. It checks CrossSiteRequestManager
110// to see that it is a cross-site request, and installs a
111// CrossSiteResourceHandler.
112// - When RDH receives a response, the BufferedResourceHandler determines
113// whether it is a download. If so, it sends a message to the new renderer
114// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26115// pending RVH remains until the next DidNavigate event for this
116// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32117// - After RDH receives a response and determines that it is safe and not a
118// download, it pauses the response to first run the old page's onunload
119// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26120// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32121// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15122// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32123// the ResourceDispatcherHost, who unpauses the response. Data is then sent
124// to the pending RVH.
125// - The pending renderer sends a FrameNavigate message that invokes the
126// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46127// pending RVH.
[email protected]992db4c2011-05-12 15:37:15128// - The previous renderer is kept swapped out in RenderViewHostManager in case
129// the user goes back. The process only stays live if another tab is using
130// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32131
[email protected]b441a8492012-06-06 14:55:57132using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44133using content::DevToolsAgentHost;
134using content::DevToolsAgentHostRegistry;
135using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17136using content::DownloadItem;
137using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14138using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20139using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56140using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13141using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27142using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54143using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50144using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23145using content::NavigationEntry;
146using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20147using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11148using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57149using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57150using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27151using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11152using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50153using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58154using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04155using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25156using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14157using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43158using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33159using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38160using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09161using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25162using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56163using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22164using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50165using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25166using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44167
[email protected]420ae012009-04-24 05:16:32168namespace {
169
170// Amount of time we wait between when a key event is received and the renderer
171// is queried for its state and pushed to the NavigationEntry.
172const int kQueryStateDelay = 5000;
173
[email protected]6ebdc9b2010-09-27 16:55:57174const int kSyncWaitDelay = 40;
175
[email protected]82114f52012-03-20 22:53:41176const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05177
[email protected]420ae012009-04-24 05:16:32178#if defined(OS_WIN)
179
180BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
181 // Note: erase is required to properly paint some widgets borders. This can
182 // be seen with textfields.
183 InvalidateRect(hwnd, NULL, TRUE);
184 return TRUE;
185}
186#endif
187
[email protected]2c5569662011-03-22 20:45:02188ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23189 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50190 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16191 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47192 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47194 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23196 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
197 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47198 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16199 break; // Fall through to rest of function.
200 }
[email protected]5e369672009-11-03 23:48:30201
[email protected]59246c572012-02-10 13:32:13202 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
203 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23204 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13205 browser_context->DidLastSessionExitCleanly()) {
206 if (entry.GetHasPostData())
207 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02208 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13209 }
[email protected]5e369672009-11-03 23:48:30210
[email protected]2c5569662011-03-22 20:45:02211 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30212}
213
[email protected]10f417c52011-12-28 21:04:23214void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47215 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42216 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50217 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24218 const std::string& embedder_channel_name,
219 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16220 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51221 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54222 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55223 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
224 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36225 if (!entry.GetBaseURLForDataURL().is_empty()) {
226 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
227 params->history_url_for_data_url = entry.GetVirtualURL();
228 }
[email protected]36fc0392011-12-25 03:59:51229 params->referrer = entry.GetReferrer();
230 params->transition = entry.GetTransitionType();
231 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00232 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55233 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34234 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47235 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48236 params->transferred_request_child_id =
237 entry.transferred_global_request_id().child_id;
238 params->transferred_request_request_id =
239 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22240 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00241 // Avoid downloading when in view-source mode.
242 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24243 params->embedder_channel_name = embedder_channel_name;
244 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44245 params->is_post = entry.GetHasPostData();
246 if(entry.GetBrowserInitiatedPostData()) {
247 params->browser_initiated_post_data.assign(
248 entry.GetBrowserInitiatedPostData()->front(),
249 entry.GetBrowserInitiatedPostData()->front() +
250 entry.GetBrowserInitiatedPostData()->size());
251
252 }
[email protected]6c6b02d2011-09-02 03:36:47253
[email protected]7c16976c2012-08-04 02:38:23254 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
255 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
256 // We may have been redirected when navigating to the current URL.
257 // Use the URL the user originally intended to visit, if it's valid and if a
258 // POST wasn't involved; the latter case avoids issues with sending data to
259 // the wrong page.
260 params->url = entry.GetOriginalRequestURL();
261 } else {
262 params->url = entry.GetURL();
263 }
264
[email protected]6c6b02d2011-09-02 03:36:47265 if (delegate)
266 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34267}
268
[email protected]f98f5092012-05-19 00:08:14269int GetSwitchValueAsInt(
270 const CommandLine& command_line,
271 const std::string& switch_string,
272 int min_value) {
273 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
274 int int_value;
275 if (base::StringToInt(string_value, &int_value))
276 return std::max(min_value, int_value);
277 else
278 return min_value;
279}
280
[email protected]420ae012009-04-24 05:16:32281} // namespace
282
[email protected]a81343d232011-12-27 07:39:20283namespace content {
284
285WebContents* WebContents::Create(
286 BrowserContext* browser_context,
287 SiteInstance* site_instance,
288 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19289 const WebContents* base_web_contents) {
290 return WebContentsImpl::Create(
291 browser_context, site_instance, routing_id,
292 static_cast<const WebContentsImpl*>(base_web_contents));
293}
294
295WebContents* WebContents::CreateWithSessionStorage(
296 BrowserContext* browser_context,
297 SiteInstance* site_instance,
298 int routing_id,
[email protected]b172aee2012-04-10 17:05:26299 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19300 const SessionStorageNamespaceMap& session_storage_namespace_map) {
301 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
302
303 for (SessionStorageNamespaceMap::const_iterator it =
304 session_storage_namespace_map.begin();
305 it != session_storage_namespace_map.end();
306 ++it) {
307 new_contents->GetController().SetSessionStorageNamespace(it->first,
308 it->second);
309 }
310
311 new_contents->Init(browser_context, site_instance, routing_id,
312 static_cast<const WebContentsImpl*>(base_web_contents));
313 return new_contents;
[email protected]a81343d232011-12-27 07:39:20314}
[email protected]746d3052012-05-22 15:15:47315
[email protected]299d7f12012-05-23 05:31:15316WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47317 return rvh->GetDelegate()->GetAsWebContents();
318}
319
[email protected]a81343d232011-12-27 07:39:20320}
[email protected]f4f50ef2011-01-21 19:01:19321
[email protected]b172aee2012-04-10 17:05:26322// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32323
[email protected]b172aee2012-04-10 17:05:26324WebContentsImpl::WebContentsImpl(
325 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19326 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42327 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19328 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57329 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44330 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05331 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34332 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23333 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
334 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34335 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21336 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56337 upload_size_(0),
338 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47339 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57340 capturing_contents_(false),
341 is_being_destroyed_(false),
342 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55343 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57344#if defined(OS_WIN)
345 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
346#endif
[email protected]7ab1e7d62009-10-14 23:32:01347 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56348 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38349 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25350 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01351 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25352 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01353 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00354 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43355 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20356 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35357}
initial.commit09911bf2008-07-26 23:55:29358
[email protected]b172aee2012-04-10 17:05:26359WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32360 is_being_destroyed_ = true;
361
[email protected]3ab9cb82011-06-03 18:02:07362 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55363 if (dialog_creator_)
364 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07365
[email protected]da8543762012-03-20 08:52:20366 if (color_chooser_)
367 color_chooser_->End();
368
[email protected]420ae012009-04-24 05:16:32369 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32370
[email protected]ca13a442012-04-17 14:00:12371 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07372 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09373 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
374 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07375 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32376
377 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07378#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32379 // If we still have a window handle, destroy it. GetNativeView can return
380 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42381 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52382 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58383 if (host && host->GetView())
384 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42385 }
[email protected]420ae012009-04-24 05:16:32386#endif
[email protected]7ab1e7d62009-10-14 23:32:01387
388 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15389 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01390 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15391 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01392 }
[email protected]b5a1d11c2011-02-17 03:09:42393
[email protected]2db9bd72012-04-13 20:20:56394 FOR_EACH_OBSERVER(WebContentsObserver,
395 observers_,
396 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08397
[email protected]6934a702011-12-20 00:04:51398 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42399}
400
[email protected]d1198fd2012-08-13 22:50:19401WebContentsImpl* WebContentsImpl::Create(
402 BrowserContext* browser_context,
403 SiteInstance* site_instance,
404 int routing_id,
405 const WebContentsImpl* base_web_contents) {
406 return CreateWithOpener(browser_context, site_instance, routing_id,
407 base_web_contents, NULL);
408}
409
410WebContentsImpl* WebContentsImpl::CreateWithOpener(
411 BrowserContext* browser_context,
412 SiteInstance* site_instance,
413 int routing_id,
414 const WebContentsImpl* base_web_contents,
415 WebContentsImpl* opener) {
416 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
417
418 new_contents->Init(browser_context, site_instance, routing_id,
419 static_cast<const WebContentsImpl*>(base_web_contents));
420 return new_contents;
421}
422
[email protected]b172aee2012-04-10 17:05:26423WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
424 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54425 WebPreferences prefs;
426
427 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
428
429 prefs.developer_extras_enabled = true;
430 prefs.javascript_enabled =
431 !command_line.HasSwitch(switches::kDisableJavaScript);
432 prefs.web_security_enabled =
433 !command_line.HasSwitch(switches::kDisableWebSecurity);
434 prefs.plugins_enabled =
435 !command_line.HasSwitch(switches::kDisablePlugins);
436 prefs.java_enabled =
437 !command_line.HasSwitch(switches::kDisableJava);
438
439 prefs.uses_page_cache =
440 command_line.HasSwitch(switches::kEnableFastback);
441 prefs.remote_fonts_enabled =
442 !command_line.HasSwitch(switches::kDisableRemoteFonts);
443 prefs.xss_auditor_enabled =
444 !command_line.HasSwitch(switches::kDisableXSSAuditor);
445 prefs.application_cache_enabled =
446 !command_line.HasSwitch(switches::kDisableApplicationCache);
447
448 prefs.local_storage_enabled =
449 !command_line.HasSwitch(switches::kDisableLocalStorage);
450 prefs.databases_enabled =
451 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01452#if defined(OS_ANDROID)
453 prefs.webaudio_enabled =
454 command_line.HasSwitch(switches::kEnableWebAudio);
455#else
[email protected]64d69de42012-02-06 00:19:54456 prefs.webaudio_enabled =
457 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01458#endif
[email protected]64d69de42012-02-06 00:19:54459
460 prefs.experimental_webgl_enabled =
461 GpuProcessHost::gpu_enabled() &&
462 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07463#if defined(OS_ANDROID)
464 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
465#else
[email protected]64d69de42012-02-06 00:19:54466 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07467#endif
[email protected]64d69de42012-02-06 00:19:54468
[email protected]5a073092012-06-08 00:42:51469 prefs.flash_3d_enabled =
470 GpuProcessHost::gpu_enabled() &&
471 !command_line.HasSwitch(switches::kDisableFlash3d);
472 prefs.flash_stage3d_enabled =
473 GpuProcessHost::gpu_enabled() &&
474 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19475
[email protected]64d69de42012-02-06 00:19:54476 prefs.gl_multisampling_enabled =
477 !command_line.HasSwitch(switches::kDisableGLMultisampling);
478 prefs.privileged_webgl_extensions_enabled =
479 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
480 prefs.site_specific_quirks_enabled =
481 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
482 prefs.allow_file_access_from_file_urls =
483 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
484 prefs.show_composited_layer_borders =
485 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
486 prefs.show_composited_layer_tree =
487 command_line.HasSwitch(switches::kShowCompositedLayerTree);
488 prefs.show_fps_counter =
489 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19490 prefs.show_paint_rects =
491 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52492 prefs.render_vsync_enabled =
493 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54494 prefs.accelerated_compositing_enabled =
495 GpuProcessHost::gpu_enabled() &&
496 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54497 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23498 command_line.HasSwitch(switches::kForceCompositingMode) &&
499 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54500 prefs.fixed_position_compositing_enabled =
501 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
502 prefs.accelerated_2d_canvas_enabled =
503 GpuProcessHost::gpu_enabled() &&
504 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58505 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27506 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54507 prefs.accelerated_painting_enabled =
508 GpuProcessHost::gpu_enabled() &&
509 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
510 prefs.accelerated_filters_enabled =
511 GpuProcessHost::gpu_enabled() &&
512 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
513 prefs.accelerated_layers_enabled =
514 prefs.accelerated_animation_enabled =
515 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54516 prefs.accelerated_plugins_enabled =
517 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
518 prefs.accelerated_video_enabled =
519 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54520 prefs.fullscreen_enabled =
521 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16522 prefs.css_regions_enabled =
523 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29524 prefs.css_shaders_enabled =
525 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01526 prefs.css_variables_enabled =
527 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56528 prefs.device_supports_touch =
529 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]c71fe6402012-08-15 15:22:55530#if defined(USE_AURA) && defined(USE_X11)
531 prefs.device_supports_touch |=
532 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
533#endif
[email protected]d849b122012-07-18 07:35:26534#if defined(OS_ANDROID)
535 prefs.device_supports_mouse = false;
536#endif
[email protected]64d69de42012-02-06 00:19:54537
538#if defined(OS_MACOSX)
539 bool default_enable_scroll_animator = true;
540#else
541 // On CrOS, the launcher always passes in the --enable flag.
542 bool default_enable_scroll_animator = false;
543#endif
544 prefs.enable_scroll_animator = default_enable_scroll_animator;
545 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
546 prefs.enable_scroll_animator = true;
547 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
548 prefs.enable_scroll_animator = false;
549
550 prefs.visual_word_movement_enabled =
551 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54552
553 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32554 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54555 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11556 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
557 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54558 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11559 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54560 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19561 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
562 prefs.flash_3d_enabled = false;
563 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
564 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11565 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54566 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11567 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54568 prefs.gl_multisampling_enabled = false;
569
570 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45571 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32572 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54573 prefs.accelerated_video_enabled = false;
574 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45575 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09576 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54577 }
578 }
579
[email protected]b9535422012-02-09 01:47:59580 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58581 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54582 prefs.loads_images_automatically = true;
583 prefs.javascript_enabled = true;
584 }
585
586 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
587
588 // Force accelerated compositing and 2d canvas off for chrome:, about: and
589 // chrome-devtools: pages (unless it's specifically allowed).
590 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54591 url.SchemeIs(chrome::kChromeUIScheme) ||
592 (url.SchemeIs(chrome::kAboutScheme) &&
593 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25594 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54595 prefs.accelerated_compositing_enabled = false;
596 prefs.accelerated_2d_canvas_enabled = false;
597 }
[email protected]43d9d782012-03-01 15:40:09598
[email protected]f98f5092012-05-19 00:08:14599 if (command_line.HasSwitch(switches::kDefaultTileWidth))
600 prefs.default_tile_width =
601 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
602 if (command_line.HasSwitch(switches::kDefaultTileHeight))
603 prefs.default_tile_height =
604 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
605 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
606 prefs.max_untiled_layer_width =
607 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
608 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
609 prefs.max_untiled_layer_height =
610 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
611
[email protected]2486dce2012-05-23 17:18:19612 if (gfx::Screen::IsDIPEnabled()) {
613 // Only apply when using DIP coordinate system as this setting interferes
614 // with fixed layout mode.
615 prefs.apply_default_device_scale_factor_in_compositor = true;
616 }
617
[email protected]de023762012-07-26 17:10:17618 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
619 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10620
[email protected]6b4dcb072012-06-18 22:26:51621 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
622
[email protected]2e21fe292012-03-02 22:52:32623 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54624
625 return prefs;
626}
627
[email protected]b172aee2012-04-10 17:05:26628RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28629 return &render_manager_;
630}
631
[email protected]7bb761892012-07-20 09:32:47632bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
633 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56634 if (GetWebUI() &&
635 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17636 return true;
[email protected]d2353452012-01-19 19:53:56637 }
[email protected]f82d57b52011-04-27 19:13:17638
[email protected]d8c660432011-12-22 20:51:25639 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
640 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10641 while ((observer = it.GetNext()) != NULL)
642 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53643 return true;
[email protected]403415a2011-01-10 18:57:53644
[email protected]7bb761892012-07-20 09:32:47645 // Message handlers should be aware of which RenderViewHost sent the
646 // message, which is temporarily stored in message_source_.
647 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18648 bool handled = true;
649 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26650 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58651 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
652 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24653 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
654 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18655 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
656 OnDidLoadResourceFromMemoryCache)
657 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
658 OnDidDisplayInsecureContent)
659 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
660 OnDidRunInsecureContent)
661 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
662 OnDocumentLoadedInFrame)
663 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26664 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
665 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17666 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
667 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25668 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26669 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59670 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21671 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20672 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
673 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
674 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16675 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45676 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10677 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20678 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
679 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
681 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29682 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50683 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18684 IPC_MESSAGE_UNHANDLED(handled = false)
685 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47686 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18687
688 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38689 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18690 GetRenderProcessHost()->ReceivedBadMessage();
691 }
692
693 return handled;
694}
695
[email protected]b172aee2012-04-10 17:05:26696void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18697 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23698 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43699 if (delegate_)
700 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18701}
702
[email protected]d1198fd2012-08-13 22:50:19703NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56704 return controller_;
705}
706
[email protected]d1198fd2012-08-13 22:50:19707const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56708 return controller_;
709}
710
[email protected]b172aee2012-04-10 17:05:26711content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55712 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30713}
714
[email protected]b172aee2012-04-10 17:05:26715const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31716 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23717 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51718 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31719}
720
721
[email protected]b172aee2012-04-10 17:05:26722const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31723 return &property_bag_;
724}
725
[email protected]b172aee2012-04-10 17:05:26726base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31727 return &property_bag_;
728}
729
[email protected]b172aee2012-04-10 17:05:26730content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31731 return delegate_;
732}
733
[email protected]b172aee2012-04-10 17:05:26734void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31735 // TODO(cbentzel): remove this debugging code?
736 if (delegate == delegate_)
737 return;
738 if (delegate_)
739 delegate_->Detach(this);
740 delegate_ = delegate;
741 if (delegate_)
742 delegate_->Attach(this);
743}
744
[email protected]b172aee2012-04-10 17:05:26745content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41746 RenderViewHostImpl* host = render_manager_.current_host();
747 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16748}
749
[email protected]b172aee2012-04-10 17:05:26750RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31751 return render_manager_.current_host();
752}
753
[email protected]6b618e62012-08-16 12:59:18754int WebContentsImpl::GetRoutingID() const {
755 if (!GetRenderViewHost())
756 return MSG_ROUTING_NONE;
757
758 return GetRenderViewHost()->GetRoutingID();
759}
760
[email protected]b172aee2012-04-10 17:05:26761RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31762 return render_manager_.GetRenderWidgetHostView();
763}
764
[email protected]b172aee2012-04-10 17:05:26765content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31766 return view_.get();
767}
768
[email protected]b172aee2012-04-10 17:05:26769content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50770 WebUIControllerFactory* factory =
771 content::GetContentClient()->browser()->GetWebUIControllerFactory();
772 if (!factory)
773 return NULL;
[email protected]d2353452012-01-19 19:53:56774 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22775 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50776 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22777 if (controller) {
778 web_ui->SetController(controller);
779 return web_ui;
780 }
781
782 delete web_ui;
783 return NULL;
784}
785
[email protected]b172aee2012-04-10 17:05:26786content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31787 return render_manager_.web_ui() ? render_manager_.web_ui()
788 : render_manager_.pending_web_ui();
789}
790
[email protected]b172aee2012-04-10 17:05:26791content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31792 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34793}
794
[email protected]86ef6a392012-05-11 22:03:11795void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22796 if (GetUserAgentOverride() == override)
797 return;
798
799 renderer_preferences_.user_agent_override = override;
800
801 // Send the new override string to the renderer.
802 RenderViewHost* host = GetRenderViewHost();
803 if (host)
804 host->SyncRendererPrefs();
805
806 // Reload the page if a load is currently in progress to avoid having
807 // different parts of the page loaded using different user agents.
808 NavigationEntry* entry = controller_.GetActiveEntry();
809 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
810 controller_.ReloadIgnoringCache(true);
[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().
1247 const std::string& partition_id =
1248 content::GetContentClient()->browser()->
1249 GetStoragePartitionIdForSiteInstance(GetBrowserContext(),
1250 site_instance);
1251 DOMStorageContextImpl* dom_storage_context =
1252 static_cast<DOMStorageContextImpl*>(
1253 BrowserContext::GetDOMStorageContextByPartitionId(
1254 GetBrowserContext(), partition_id));
1255 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1256 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1257 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1258 new_contents->GetController().SetSessionStorageNamespace(
1259 partition_id,
1260 session_storage_namespace);
1261 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1262
[email protected]bafe6cd2012-05-23 23:09:501263 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1264
1265 if (!params.opener_suppressed) {
1266 content::WebContentsView* new_view = new_contents->GetView();
1267
1268 // TODO(brettw): It seems bogus that we have to call this function on the
1269 // newly created object and give it one of its own member variables.
1270 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1271
1272 // Save the created window associated with the route so we can show it
1273 // later.
1274 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1275 pending_contents_[route_id] = new_contents;
1276 }
1277
1278 if (delegate_) {
1279 delegate_->WebContentsCreated(
1280 this, params.opener_frame_id, params.target_url, new_contents);
1281 }
1282
1283 if (params.opener_suppressed) {
1284 // When the opener is suppressed, the original renderer cannot access the
1285 // new window. As a result, we need to show and navigate the window here.
1286 gfx::Rect initial_pos;
1287 AddNewContents(
1288 new_contents, params.disposition, initial_pos, params.user_gesture);
1289
1290 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1291 CURRENT_TAB,
1292 content::PAGE_TRANSITION_LINK,
1293 true /* is_renderer_initiated */);
1294 new_contents->OpenURL(open_params);
1295 }
1296}
1297
1298void WebContentsImpl::CreateNewWidget(int route_id,
1299 WebKit::WebPopupType popup_type) {
1300 CreateNewWidget(route_id, false, popup_type);
1301}
1302
1303void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1304 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1305}
1306
1307void WebContentsImpl::CreateNewWidget(int route_id,
1308 bool is_fullscreen,
1309 WebKit::WebPopupType popup_type) {
1310 content::RenderProcessHost* process = GetRenderProcessHost();
1311 RenderWidgetHostImpl* widget_host =
1312 new RenderWidgetHostImpl(this, process, route_id);
1313 RenderWidgetHostViewPort* widget_view =
1314 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1315 if (!is_fullscreen) {
1316 // Popups should not get activated.
1317 widget_view->SetPopupType(popup_type);
1318 }
1319 // Save the created widget associated with the route so we can show it later.
1320 pending_widget_views_[route_id] = widget_view;
1321
1322#if defined(OS_MACOSX)
1323 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1324 // to allow it to survive the trip without being hosted.
1325 base::mac::NSObjectRetain(widget_view->GetNativeView());
1326#endif
1327}
1328
1329void WebContentsImpl::ShowCreatedWindow(int route_id,
1330 WindowOpenDisposition disposition,
1331 const gfx::Rect& initial_pos,
1332 bool user_gesture) {
1333 WebContentsImpl* contents = GetCreatedWindow(route_id);
1334 if (contents)
1335 AddNewContents(contents, disposition, initial_pos, user_gesture);
1336}
1337
1338void WebContentsImpl::ShowCreatedWidget(int route_id,
1339 const gfx::Rect& initial_pos) {
1340 ShowCreatedWidget(route_id, false, initial_pos);
1341}
1342
1343void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1344 ShowCreatedWidget(route_id, true, gfx::Rect());
1345}
1346
1347void WebContentsImpl::ShowCreatedWidget(int route_id,
1348 bool is_fullscreen,
1349 const gfx::Rect& initial_pos) {
1350 if (delegate_)
1351 delegate_->RenderWidgetShowing();
1352
1353 RenderWidgetHostViewPort* widget_host_view =
1354 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1355 if (!widget_host_view)
1356 return;
1357 if (is_fullscreen) {
1358 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1359 } else {
1360 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1361 }
[email protected]89054502012-06-03 10:29:241362
1363 RenderWidgetHostImpl* render_widget_host_impl =
1364 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1365 render_widget_host_impl->Init();
1366 // Only allow privileged mouse lock for fullscreen render widget, which is
1367 // used to implement Pepper Flash fullscreen.
1368 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501369
1370#if defined(OS_MACOSX)
1371 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1372 // properly embedded (or purposefully ignored) we can release the retain we
1373 // took in CreateNewWidget().
1374 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1375#endif
1376}
1377
1378WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1379 PendingContents::iterator iter = pending_contents_.find(route_id);
1380
1381 // Certain systems can block the creation of new windows. If we didn't succeed
1382 // in creating one, just return NULL.
1383 if (iter == pending_contents_.end()) {
1384 return NULL;
1385 }
1386
1387 WebContentsImpl* new_contents = iter->second;
1388 pending_contents_.erase(route_id);
1389
1390 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1391 !new_contents->GetRenderViewHost()->GetView())
1392 return NULL;
1393
1394 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1395 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1396 return new_contents;
1397}
1398
1399RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1400 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1401 if (iter == pending_widget_views_.end()) {
1402 DCHECK(false);
1403 return NULL;
1404 }
1405
1406 RenderWidgetHostView* widget_host_view = iter->second;
1407 pending_widget_views_.erase(route_id);
1408
1409 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1410 if (!widget_host->GetProcess()->HasConnection()) {
1411 // The view has gone away or the renderer crashed. Nothing to do.
1412 return NULL;
1413 }
1414
1415 return widget_host_view;
1416}
1417
1418void WebContentsImpl::ShowContextMenu(
1419 const content::ContextMenuParams& params) {
1420 // Allow WebContentsDelegates to handle the context menu operation first.
1421 if (delegate_ && delegate_->HandleContextMenu(params))
1422 return;
1423
[email protected]5a3bdf52012-05-24 15:12:571424 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501425}
1426
[email protected]f13b4202012-06-12 23:53:231427void WebContentsImpl::RequestMediaAccessPermission(
1428 const content::MediaStreamRequest* request,
1429 const content::MediaResponseCallback& callback) {
1430 if (delegate_)
1431 delegate_->RequestMediaAccessPermission(this, request, callback);
1432 else
1433 callback.Run(content::MediaStreamDevices());
1434}
1435
[email protected]b172aee2012-04-10 17:05:261436void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231437 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331438 if (delegate_)
1439 delegate_->UpdatePreferredSize(this, pref_size);
1440}
1441
[email protected]b172aee2012-04-10 17:05:261442void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341443 if (delegate_)
1444 delegate_->ResizeDueToAutoResize(this, new_size);
1445}
1446
[email protected]b172aee2012-04-10 17:05:261447WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201448 if (!delegate_)
1449 return NULL;
[email protected]00c37fc2011-08-02 00:22:501450
[email protected]e5d549d2011-12-28 01:29:201451 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1452 // Notify observers.
1453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1454 DidOpenURL(params.url, params.referrer,
1455 params.disposition, params.transition));
1456 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341457}
1458
[email protected]6b618e62012-08-16 12:59:181459bool WebContentsImpl::Send(IPC::Message* message) {
1460 if (!GetRenderViewHost()) {
1461 delete message;
1462 return false;
1463 }
1464
1465 return GetRenderViewHost()->Send(message);
1466}
1467
[email protected]b172aee2012-04-10 17:05:261468bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501469 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251470 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231471 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251472 reload_type);
[email protected]876bc832010-09-07 16:29:541473}
[email protected]96d185d2009-04-24 03:28:541474
[email protected]ba45bfd2012-05-22 21:51:441475void WebContentsImpl::RenderViewForInterstitialPageCreated(
1476 content::RenderViewHost* render_view_host) {
1477 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1478 RenderViewForInterstitialPageCreated(render_view_host));
1479}
1480
[email protected]b172aee2012-04-10 17:05:261481bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231482 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501483 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401484 // The renderer will reject IPC messages with URLs longer than
1485 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511486 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401487 return false;
1488
[email protected]9f76c1e2012-03-05 15:15:581489 RenderViewHostImpl* dest_render_view_host =
1490 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401491 if (!dest_render_view_host)
1492 return false; // Unable to create the desired render view host.
1493
[email protected]80a8fad2011-01-29 04:02:381494 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071495 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581496 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501497 WebUIControllerFactory* factory =
1498 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271499 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501500 bool is_allowed_in_web_ui_renderer =
1501 factory &&
[email protected]24e18252012-04-16 21:26:271502 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1503 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231504 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1505 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271506 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231507 content::GetContentClient()->SetActiveURL(entry.GetURL());
1508 CHECK(0);
1509 }
[email protected]54ec6472010-04-09 19:39:581510
[email protected]96d185d2009-04-24 03:28:541511 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441512 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521513 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441514 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511515 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541516
[email protected]7bb761892012-07-20 09:32:471517 // Notify observers that we will navigate in this RV.
1518 FOR_EACH_OBSERVER(WebContentsObserver,
1519 observers_,
1520 AboutToNavigateRenderView(dest_render_view_host));
1521
[email protected]96d185d2009-04-24 03:28:541522 // Used for page load time metrics.
1523 current_load_start_ = base::TimeTicks::Now();
1524
1525 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241526 std::string embedder_channel_name;
1527 int embedder_container_id;
1528 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1529 &embedder_channel_name,
1530 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341531 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271532 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241533 embedder_channel_name,
1534 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471535 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341536 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541537
[email protected]36fc0392011-12-25 03:59:511538 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541539 // HACK!! This code suppresses javascript: URLs from being added to
1540 // session history, which is what we want to do for javascript: URLs that
1541 // do not generate content. What we really need is a message from the
1542 // renderer telling us that a new page was not created. The same message
1543 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511544 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541545 return false;
1546 }
1547
[email protected]3c9e1872010-11-18 16:17:491548 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251549 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041550 observers_,
[email protected]36fc0392011-12-25 03:59:511551 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541552
[email protected]09b29342011-06-24 19:18:481553 if (delegate_)
1554 delegate_->DidNavigateToPendingEntry(this);
1555
[email protected]d5f942ba2008-09-26 19:30:341556 return true;
1557}
1558
[email protected]b172aee2012-04-10 17:05:261559void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331560 const SiteInstance* site_instance,
1561 int history_length,
1562 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411563 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1564 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191565 if (render_manager_.pending_render_view_host()) {
1566 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141567 return;
[email protected]9e1ad4b2011-08-14 16:49:191568 }
[email protected]9f76c1e2012-03-05 15:15:581569 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191570 if (!rvh) {
1571 NOTREACHED();
1572 return;
1573 }
[email protected]9f76c1e2012-03-05 15:15:581574 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191575 NOTREACHED();
1576 return;
1577 }
[email protected]6b618e62012-08-16 12:59:181578 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1579 history_length,
1580 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271584 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541585 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1586 return;
1587 }
[email protected]9f76c1e2012-03-05 15:15:581588 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541589}
1590
[email protected]b172aee2012-04-10 17:05:261591bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271592 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541593}
1594
[email protected]b172aee2012-04-10 17:05:261595InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271596 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221597}
1598
[email protected]b172aee2012-04-10 17:05:261599bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161600 // WebKit creates Document object when MIME type is application/xhtml+xml,
1601 // so we also support this MIME type.
1602 return contents_mime_type_ == "text/html" ||
1603 contents_mime_type_ == "text/xml" ||
1604 contents_mime_type_ == "application/xhtml+xml" ||
1605 contents_mime_type_ == "text/plain" ||
1606 contents_mime_type_ == "text/css" ||
1607 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1608}
1609
[email protected]b172aee2012-04-10 17:05:261610void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591611 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161612 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481613 download_stats::RecordDownloadSource(
1614 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461615 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141616 return;
[email protected]c7dd2f62011-07-18 15:57:591617 }
1618
1619 Stop();
1620
1621 // Create the save package and possibly prompt the user for the name to save
1622 // the page as. The user prompt is an asynchronous operation that runs on
1623 // another thread.
1624 save_package_ = new SavePackage(this);
1625 save_package_->GetSaveInfo();
1626}
1627
1628// Used in automated testing to bypass prompting the user for file names.
1629// Instead, the names and paths are hard coded rather than running them through
1630// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261631bool WebContentsImpl::SavePage(const FilePath& main_file,
1632 const FilePath& dir_path,
1633 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591634 // Stop the page from navigating.
1635 Stop();
1636
1637 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271638 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591639}
1640
[email protected]b172aee2012-04-10 17:05:261641void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121642 const FilePath& file,
1643 const base::Callback<void(const FilePath&, int64)>& callback) {
1644 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1645}
1646
[email protected]b172aee2012-04-10 17:05:261647bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231648 NavigationEntryImpl* active_entry =
1649 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321650 return (active_entry != NULL &&
1651 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511652 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321653}
1654
[email protected]b172aee2012-04-10 17:05:261655const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271656 return contents_mime_type_;
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271660 return notify_disconnection_;
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311664 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181665 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161666}
1667
[email protected]b172aee2012-04-10 17:05:261668void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311669 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181670 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161671}
1672
[email protected]b172aee2012-04-10 17:05:261673content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271674 return &renderer_preferences_;
1675}
1676
[email protected]b172aee2012-04-10 17:05:261677void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271678 new_tab_start_time_ = time;
1679}
1680
[email protected]b172aee2012-04-10 17:05:261681base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271682 return new_tab_start_time_;
1683}
1684
[email protected]e35ccd52012-05-23 16:22:471685void WebContentsImpl::Close() {
1686 Close(GetRenderViewHost());
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151690 if (close_start_time_.is_null())
1691 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011692}
1693
[email protected]b172aee2012-04-10 17:05:261694bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191695#if defined(OS_CHROMEOS)
1696 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1697 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511698 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201699 return false;
1700 return true;
[email protected]46624bf2010-06-09 16:04:191701#else
1702 return true;
1703#endif
1704}
1705
[email protected]b172aee2012-04-10 17:05:261706void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521707 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581708 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511709 if (delegate_)
1710 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341711}
1712
[email protected]e35ccd52012-05-23 16:22:471713void WebContentsImpl::UserGestureDone() {
1714 OnUserGesture();
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271718 closed_by_user_gesture_ = value;
1719}
1720
[email protected]b172aee2012-04-10 17:05:261721bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271722 return closed_by_user_gesture_;
1723}
1724
[email protected]b172aee2012-04-10 17:05:261725double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051726 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561727 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251728 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171729 return 0;
[email protected]b75b8292010-10-01 07:28:251730
1731 double zoom_level;
1732 if (temporary_zoom_settings_) {
1733 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581734 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251735 } else {
[email protected]2ae88d12011-10-14 09:11:191736 GURL url;
[email protected]10f417c52011-12-28 21:04:231737 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191738 // Since zoom map is updated using rewritten URL, use rewritten URL
1739 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511740 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191741 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251742 }
[email protected]d0b8d092010-10-25 04:05:171743 return zoom_level;
1744}
[email protected]b75b8292010-10-01 07:28:251745
[email protected]b172aee2012-04-10 17:05:261746int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1747 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171748 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011749 // Calculate the zoom percent from the factor. Round up to the nearest whole
1750 // number.
[email protected]b75b8292010-10-01 07:28:251751 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011752 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251753 *enable_decrement = percent > minimum_zoom_percent_;
1754 *enable_increment = percent < maximum_zoom_percent_;
1755 return percent;
1756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501759 if (!delegate_)
1760 return;
1761
[email protected]10f417c52011-12-28 21:04:231762 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501763 if (!active_entry)
1764 return;
1765
[email protected]36fc0392011-12-25 03:59:511766 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121767}
1768
[email protected]b172aee2012-04-10 17:05:261769void WebContentsImpl::ViewFrameSource(const GURL& url,
1770 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271771 if (!delegate_)
1772 return;
1773
1774 delegate_->ViewSourceForFrame(this, url, content_state);
1775}
1776
[email protected]b172aee2012-04-10 17:05:261777int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271778 return minimum_zoom_percent_;
1779}
1780
[email protected]b172aee2012-04-10 17:05:261781int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271782 return maximum_zoom_percent_;
1783}
1784
[email protected]b172aee2012-04-10 17:05:261785gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231786 return preferred_size_;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271790 return content_restrictions_;
1791}
1792
[email protected]b172aee2012-04-10 17:05:261793WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501794 WebUIControllerFactory* factory =
1795 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1796 if (!factory)
1797 return WebUI::kNoWebUI;
1798 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271799}
1800
[email protected]b172aee2012-04-10 17:05:261801content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271802 // When there is a pending navigation entry, we want to use the pending WebUI
1803 // that goes along with it to control the basic flags. For example, we want to
1804 // show the pending URL in the URL bar, so we want the display_url flag to
1805 // be from the pending entry.
1806 //
1807 // The confusion comes because there are multiple possibilities for the
1808 // initial load in a tab as a side effect of the way the RenderViewHostManager
1809 // works.
1810 //
1811 // - For the very first tab the load looks "normal". The new tab Web UI is
1812 // the pending one, and we want it to apply here.
1813 //
1814 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1815 // get switched to the one previously associated with the new tab pages.
1816 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1817 // have a committed Web UI in this case.
1818 //
1819 // This condition handles all of these cases:
1820 //
1821 // - First load in first tab: no committed nav entry + pending nav entry +
1822 // pending dom ui:
1823 // -> Use pending Web UI if any.
1824 //
1825 // - First load in second tab: no committed nav entry + pending nav entry +
1826 // no pending Web UI:
1827 // -> Use the committed Web UI if any.
1828 //
1829 // - Second navigation in any tab: committed nav entry + pending nav entry:
1830 // -> Use pending Web UI if any.
1831 //
1832 // - Normal state with no load: committed nav entry + no pending nav entry:
1833 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251834 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271835 (controller_.GetLastCommittedEntry() ||
1836 render_manager_.pending_web_ui()))
1837 return render_manager_.pending_web_ui();
1838 return render_manager_.web_ui();
1839}
1840
[email protected]b172aee2012-04-10 17:05:261841bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271842 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581843 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271844}
1845
[email protected]b172aee2012-04-10 17:05:261846bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441847 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501848}
1849
[email protected]b172aee2012-04-10 17:05:261850void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321851 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181852 Send(new ViewMsg_DidChooseColorResponse(
1853 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201854}
1855
[email protected]b172aee2012-04-10 17:05:261856void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181857 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201858 if (delegate_)
1859 delegate_->DidEndColorChooser();
1860 color_chooser_ = NULL;
1861}
1862
[email protected]b172aee2012-04-10 17:05:261863bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471864 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271865 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221866 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231867 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411868 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271869}
1870
[email protected]b172aee2012-04-10 17:05:261871void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271872 if (delegate_)
1873 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211874}
1875
[email protected]3a3b75a2012-06-01 08:38:361876void WebContentsImpl::OnRegisterIntentService(
1877 const webkit_glue::WebIntentServiceData& data,
1878 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431879 if (delegate_)
1880 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301881}
1882
[email protected]b172aee2012-04-10 17:05:261883void WebContentsImpl::OnWebIntentDispatch(
1884 const webkit_glue::WebIntentData& intent,
1885 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431886 if (!delegate_)
1887 return;
1888
[email protected]0d9989d2011-12-21 20:26:001889 WebIntentsDispatcherImpl* intents_dispatcher =
1890 new WebIntentsDispatcherImpl(this, intent, intent_id);
1891 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301892}
1893
[email protected]54047eb52012-05-08 21:45:571894void WebContentsImpl::DidStartProvisionalLoadForFrame(
1895 content::RenderViewHost* render_view_host,
1896 int64 frame_id,
1897 bool is_main_frame,
1898 const GURL& opener_url,
1899 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281900 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181901 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451902 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571903 content::RenderProcessHost* render_process_host =
1904 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541905 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571906 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451907 false,
[email protected]9f76c1e2012-03-05 15:15:581908 &validated_url);
[email protected]ef108e72012-06-20 14:03:541909 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571910 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451911 true,
1912 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181913
[email protected]0d60f0192011-04-14 12:40:101914 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101916 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571917 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541918
1919 if (is_main_frame) {
1920 // Notify observers about the provisional change in the main frame URL.
1921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1922 ProvisionalChangeToMainFrameUrl(validated_url,
1923 validated_opener_url,
1924 render_view_host));
1925 }
1926}
1927
1928void WebContentsImpl::DidRedirectProvisionalLoad(
1929 content::RenderViewHost* render_view_host,
1930 int32 page_id,
1931 const GURL& opener_url,
1932 const GURL& source_url,
1933 const GURL& target_url) {
1934 // TODO(creis): Remove this method and have the pre-rendering code listen to
1935 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1936 // instead. See http://crbug.com/78512.
1937 GURL validated_source_url(source_url);
1938 GURL validated_target_url(target_url);
1939 GURL validated_opener_url(opener_url);
1940 content::RenderProcessHost* render_process_host =
1941 render_view_host->GetProcess();
1942 RenderViewHostImpl::FilterURL(
1943 ChildProcessSecurityPolicyImpl::GetInstance(),
1944 render_process_host->GetID(),
1945 false,
1946 &validated_source_url);
1947 RenderViewHostImpl::FilterURL(
1948 ChildProcessSecurityPolicyImpl::GetInstance(),
1949 render_process_host->GetID(),
1950 false,
1951 &validated_target_url);
1952 RenderViewHostImpl::FilterURL(
1953 ChildProcessSecurityPolicyImpl::GetInstance(),
1954 render_process_host->GetID(),
1955 true,
1956 &validated_opener_url);
1957 NavigationEntry* entry;
1958 if (page_id == -1) {
1959 entry = controller_.GetPendingEntry();
1960 } else {
1961 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1962 page_id);
1963 }
1964 if (!entry || entry->GetURL() != validated_source_url)
1965 return;
1966
1967 // Notify observers about the provisional change in the main frame URL.
1968 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1969 ProvisionalChangeToMainFrameUrl(validated_target_url,
1970 validated_opener_url,
1971 render_view_host));
[email protected]724159a2010-12-30 01:11:181972}
1973
[email protected]54047eb52012-05-08 21:45:571974void WebContentsImpl::DidFailProvisionalLoadWithError(
1975 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581976 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1977 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1978 << ", error_code: " << params.error_code
1979 << ", error_description: " << params.error_description
1980 << ", is_main_frame: " << params.is_main_frame
1981 << ", showing_repost_interstitial: " <<
1982 params.showing_repost_interstitial
1983 << ", frame_id: " << params.frame_id;
1984 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571985 content::RenderProcessHost* render_process_host =
1986 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541987 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571988 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451989 false,
[email protected]9f76c1e2012-03-05 15:15:581990 &validated_url);
[email protected]724159a2010-12-30 01:11:181991
[email protected]d7b175e2011-10-11 15:31:581992 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181993 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1994 // This means that the interstitial won't be torn down properly, which is
1995 // bad. But if we have an interstitial, go back to another tab type, and
1996 // then load the same interstitial again, we could end up getting the first
1997 // interstitial's "failed" message (as a result of the cancel) when we're on
1998 // the second one.
1999 //
2000 // We can't tell this apart, so we think we're tearing down the current page
2001 // which will cause a crash later one. There is also some code in
2002 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2003 // out because of this problem.
2004 //
2005 // http://code.google.com/p/chromium/issues/detail?id=2855
2006 // Because this will not tear down the interstitial properly, if "back" is
2007 // back to another tab type, the interstitial will still be somewhat alive
2008 // in the previous tab type. If you navigate somewhere that activates the
2009 // tab with the interstitial again, you'll see a flash before the new load
2010 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272011 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182012 LOG(WARNING) << "Discarding message during interstitial.";
2013 return;
2014 }
2015
[email protected]a16690732012-07-13 19:22:172016 // Do not clear the pending entry if one exists, so that the user's typed
2017 // URL is not lost when a navigation fails or is aborted. We'll allow
2018 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182019
[email protected]54047eb52012-05-08 21:45:572020 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182021 }
2022
[email protected]d8c660432011-12-22 20:51:252023 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582024 observers_,
2025 DidFailProvisionalLoad(params.frame_id,
2026 params.is_main_frame,
2027 validated_url,
2028 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462029 params.error_description,
2030 render_view_host));
[email protected]724159a2010-12-30 01:11:182031}
2032
[email protected]b172aee2012-04-10 17:05:262033void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182034 const GURL& url,
[email protected]70435962011-08-02 20:13:282035 const std::string& security_info,
2036 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182037 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282038 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192039 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182040 cache.Increment();
2041
2042 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082043 int cert_id = 0;
2044 net::CertStatus cert_status = 0;
2045 int security_bits = -1;
2046 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512047 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2048 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002049 content::LoadFromMemoryCacheDetails details(
2050 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2051 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182052
[email protected]ad50def52011-10-19 23:17:072053 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272054 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502055 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002056 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182057}
2058
[email protected]b172aee2012-04-10 17:05:262059void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382060 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182061 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192062 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182063}
2064
[email protected]b172aee2012-04-10 17:05:262065void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022066 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232067 LOG(INFO) << security_origin << " ran insecure content from "
2068 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382069 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412070 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2071 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182072 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412073 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192074 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182075}
2076
[email protected]b172aee2012-04-10 17:05:262077void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182078 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472080 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312084 int64 frame_id,
2085 const GURL& validated_url,
2086 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472088 DidFinishLoad(frame_id, validated_url, is_main_frame,
2089 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312090}
2091
[email protected]b172aee2012-04-10 17:05:262092void WebContentsImpl::OnDidFailLoadWithError(
2093 int64 frame_id,
2094 const GURL& validated_url,
2095 bool is_main_frame,
2096 int error_code,
2097 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252098 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312099 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472100 error_code, error_description,
2101 message_source_));
[email protected]724159a2010-12-30 01:11:182102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272105 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432106 if (delegate_)
2107 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172108}
2109
[email protected]b172aee2012-04-10 17:05:262110void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262111 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232112 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252113 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262114 if (!entry)
2115 return;
2116 // Note that we don't call NavigationController::GotToOffset() as we don't
2117 // want to create a pending navigation entry (it might end up lingering
2118 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252119 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582120 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512121 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582122 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472123 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572124
2125 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2126 // it in now that we know. This allows us to find the entry when it commits.
2127 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232128 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332129 entry->set_site_instance(
2130 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572131 }
[email protected]216813952011-05-19 22:21:262132 }
2133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2136 int maximum_percent,
2137 bool remember) {
[email protected]216813952011-05-19 22:21:262138 minimum_zoom_percent_ = minimum_percent;
2139 maximum_zoom_percent_ = maximum_percent;
2140 temporary_zoom_settings_ = !remember;
2141}
2142
[email protected]20b433a2012-05-15 21:23:462143void WebContentsImpl::OnSaveURL(const GURL& url,
2144 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482145 download_stats::RecordDownloadSource(
2146 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262147 // Check if the URL to save matches the URL of the main frame. Since this
2148 // message originates from Pepper plugins, it may not be the case if the
2149 // plugin is an embedded element.
2150 GURL main_frame_url = GetURL();
2151 if (!main_frame_url.is_valid())
2152 return;
2153 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462154 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::OnEnumerateDirectory(int request_id,
2158 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432159 if (!delegate_)
2160 return;
2161
[email protected]b9535422012-02-09 01:47:592162 ChildProcessSecurityPolicyImpl* policy =
2163 ChildProcessSecurityPolicyImpl::GetInstance();
2164 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2165 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212166}
2167
[email protected]b172aee2012-04-10 17:05:262168void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432169 if (delegate_)
2170 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202171}
2172
[email protected]b172aee2012-04-10 17:05:262173void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2174 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362175 const string16& title,
2176 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432177 if (!delegate_)
2178 return;
2179
[email protected]b9535422012-02-09 01:47:592180 ChildProcessSecurityPolicyImpl* policy =
2181 ChildProcessSecurityPolicyImpl::GetInstance();
2182 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2183 return;
[email protected]3a3b75a2012-06-01 08:38:362184 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202185}
2186
[email protected]b172aee2012-04-10 17:05:262187void WebContentsImpl::OnFindReply(int request_id,
2188 int number_of_matches,
2189 const gfx::Rect& selection_rect,
2190 int active_match_ordinal,
2191 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432192 if (delegate_) {
2193 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2194 active_match_ordinal, final_update);
2195 }
[email protected]b888919c2011-09-02 00:32:162196}
2197
[email protected]b172aee2012-04-10 17:05:262198void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442199 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2200 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2204 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102205 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102207 AppCacheAccessed(manifest_url, blocked_by_policy));
2208}
2209
[email protected]b172aee2012-04-10 17:05:262210void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322211 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432212 color_chooser_ = delegate_ ?
2213 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202217 if (color_chooser_ &&
2218 color_chooser_id == color_chooser_->identifier())
2219 color_chooser_->End();
2220}
2221
[email protected]b172aee2012-04-10 17:05:262222void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322223 SkColor color) {
[email protected]da8543762012-03-20 08:52:202224 if (color_chooser_ &&
2225 color_chooser_id == color_chooser_->identifier())
2226 color_chooser_->SetSelectedColor(color);
2227}
2228
[email protected]9f2a9d72012-04-16 16:02:222229void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2230 const FilePath& path,
2231 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442232 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2233 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292234}
2235
[email protected]d0759f492012-04-19 22:50:502236// This exists for render views that don't have a WebUI, but do have WebUI
2237// bindings enabled.
2238void WebContentsImpl::OnWebUISend(const GURL& source_url,
2239 const std::string& name,
2240 const base::ListValue& args) {
2241 if (delegate_)
2242 delegate_->WebUISend(this, source_url, name, args);
2243}
2244
[email protected]96d185d2009-04-24 03:28:542245// Notifies the RenderWidgetHost instance about the fact that the page is
2246// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262247void WebContentsImpl::SetIsLoading(bool is_loading,
2248 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542249 if (is_loading == is_loading_)
2250 return;
2251
2252 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212253 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542254 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562255 upload_size_ = 0;
2256 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542257 }
2258
2259 render_manager_.SetIsLoading(is_loading);
2260
2261 is_loading_ = is_loading;
2262 waiting_for_response_ = is_loading;
2263
[email protected]6ebdc9b2010-09-27 16:55:572264 if (delegate_)
2265 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462266 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542267
[email protected]432115822011-07-10 15:52:272268 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2269 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072270 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542271 if (details)
[email protected]6c2381d2011-10-19 02:52:532272 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072273 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502274 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542275 det);
2276}
2277
[email protected]b172aee2012-04-10 17:05:262278void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132279 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322280 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562281 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382282 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442283 // that opened the window, as long as both renderers have the same
2284 // privileges.
[email protected]1fd1a502011-03-30 16:55:562285 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562286 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582287 // web_ui might be NULL if the URL refers to a non-existent extension.
2288 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402289 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522290 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442291 }
2292 }
[email protected]1fd1a502011-03-30 16:55:562293 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442294 }
2295
[email protected]4e697b042011-07-08 06:44:562296 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322297 // Clear the status bubble. This is a workaround for a bug where WebKit
2298 // doesn't let us know that the cursor left an element during a
2299 // transition (this is also why the mouse cursor remains as a hand after
2300 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2301 // clear the bubble when a user navigates to a named anchor in the same
2302 // page.
[email protected]36fc0392011-12-25 03:59:512303 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322304 }
2305
[email protected]a6e82fc2010-02-24 22:28:142306 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472307 // Once the main frame is navigated, we're no longer considered to have
2308 // displayed insecure content.
2309 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172310 }
[email protected]ce5c4502009-05-06 16:46:112311
[email protected]3c9e1872010-11-18 16:17:492312 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252313 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042314 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322315}
2316
[email protected]b172aee2012-04-10 17:05:262317void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322318 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132319 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322320 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062321 // If we navigate off the page, reset JavaScript state. This does nothing
2322 // to prevent a malicious script from spamming messages, since the script
2323 // could just reload the page to stop blocking.
2324 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552325 dialog_creator_->ResetJavaScriptState(this);
2326 dialog_creator_ = NULL;
2327 }
[email protected]420ae012009-04-24 05:16:322328
[email protected]3c9e1872010-11-18 16:17:492329 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252330 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042331 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322332}
2333
[email protected]b172aee2012-04-10 17:05:262334void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462335 // If we are creating a RVH for a restored controller, then we need to make
2336 // sure the RenderView starts with a next_page_id_ larger than the number
2337 // of restored entries. This must be called before the RenderView starts
2338 // navigating (to avoid a race between the browser updating max_page_id and
2339 // the renderer updating next_page_id_). Because of this, we only call this
2340 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562341 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582342 if (max_restored_page_id >
2343 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2344 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2345 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322346}
2347
[email protected]b172aee2012-04-10 17:05:262348bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2349 const string16& title) {
[email protected]420ae012009-04-24 05:16:322350 // For file URLs without a title, use the pathname instead. In the case of a
2351 // synthesized title, we don't want the update to count toward the "one set
2352 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512353 string16 final_title;
[email protected]420ae012009-04-24 05:16:322354 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512355 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2356 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322357 explicit_set = false; // Don't count synthetic titles toward the set limit.
2358 } else {
[email protected]acafd272011-07-26 17:35:572359 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322360 explicit_set = true;
2361 }
2362
[email protected]987fc3a2011-05-26 14:18:092363 // If a page is created via window.open and never navigated,
2364 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552365 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092366 if (entry) {
[email protected]36fc0392011-12-25 03:59:512367 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092368 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322369
[email protected]36fc0392011-12-25 03:59:512370 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092371 } else {
2372 if (page_title_when_no_navigation_entry_ == final_title)
2373 return false; // Nothing changed, don't bother.
2374
2375 page_title_when_no_navigation_entry_ = final_title;
2376 }
[email protected]420ae012009-04-24 05:16:322377
[email protected]420ae012009-04-24 05:16:322378 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232379 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322380
[email protected]2bb171882012-03-07 02:09:462381 std::pair<content::NavigationEntry*, bool> details =
2382 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142383
[email protected]ad50def52011-10-19 23:17:072384 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442385 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2386 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462387 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042388
[email protected]420ae012009-04-24 05:16:322389 return true;
2390}
2391
[email protected]b172aee2012-04-10 17:05:262392void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322393 // After sending out a swap notification, we need to send a disconnect
2394 // notification so that clients that pick up a pointer to |this| can NULL the
2395 // pointer. See Bug 1230284.
2396 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072397 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202398 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2399 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072400 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322401}
2402
[email protected]b172aee2012-04-10 17:05:262403void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322404 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072405 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122406 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2407 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072408 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322409}
2410
[email protected]b172aee2012-04-10 17:05:262411void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322412 if (!notify_disconnection_)
2413 return;
2414
2415 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072416 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322417 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2418 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072419 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322420}
2421
[email protected]5a3bdf52012-05-24 15:12:572422RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2423 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322424}
2425
[email protected]8d3347f2009-07-09 22:00:212426RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262427WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212428 return &render_manager_;
2429}
2430
[email protected]b172aee2012-04-10 17:05:262431content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372432 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462433 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512434}
2435
[email protected]b172aee2012-04-10 17:05:262436WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172437 return this;
2438}
2439
[email protected]b172aee2012-04-10 17:05:262440gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172441 if (delegate_)
2442 return delegate_->GetRootWindowResizerRect();
2443 return gfx::Rect();
2444}
2445
[email protected]b172aee2012-04-10 17:05:262446void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442447 // Don't send notifications if we are just creating a swapped-out RVH for
2448 // the opener chain. These won't be used for view-source or WebUI, so it's
2449 // ok to return early.
2450 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2451 return;
2452
[email protected]ad50def52011-10-19 23:17:072453 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302454 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322455 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532456 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232457 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322458 if (!entry)
2459 return;
2460
2461 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352462 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562463 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582464 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322465
2466 if (entry->IsViewSourceMode()) {
2467 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182468 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582469 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322470 }
[email protected]0666aef2009-05-13 19:48:082471
[email protected]d487beefe2011-12-21 05:41:212472 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262473
2474 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252475 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322476}
2477
[email protected]b172aee2012-04-10 17:05:262478void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522479 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322480 // Don't notify the world, since this came from a renderer in the
2481 // background.
2482 return;
2483 }
2484
2485 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312486 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232487 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302488
2489 // Restore the focus to the tab (otherwise the focus will be on the top
2490 // window).
[email protected]484ae5912010-09-29 19:16:142491 if (was_crashed && !FocusLocationBarByDefault() &&
2492 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302493 Focus();
[email protected]484ae5912010-09-29 19:16:142494 }
[email protected]32ded2212011-11-10 18:51:432495
[email protected]d8c660432011-12-22 20:51:252496 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322497}
2498
[email protected]b172aee2012-04-10 17:05:262499void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2500 base::TerminationStatus status,
2501 int error_code) {
[email protected]151a63d2011-12-20 22:32:522502 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322503 // The pending page's RenderViewHost is gone.
2504 return;
2505 }
2506
2507 SetIsLoading(false, NULL);
2508 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232509 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312510 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322511
[email protected]d8c660432011-12-22 20:51:252512 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272513 observers_,
[email protected]be1f56ab2011-12-22 06:55:312514 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322515}
2516
[email protected]b172aee2012-04-10 17:05:262517void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482518 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252519 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062520}
2521
[email protected]b172aee2012-04-10 17:05:262522void WebContentsImpl::DidNavigate(
2523 RenderViewHost* rvh,
2524 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582525 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322526 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372527
[email protected]434f69f2012-02-06 21:56:522528 // Update the site of the SiteInstance if it doesn't have one yet, unless
2529 // this is for about:blank. In that case, the SiteInstance can still be
2530 // considered unused until a navigation to a real page.
2531 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2532 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332533 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522534 }
[email protected]420ae012009-04-24 05:16:322535
2536 // Need to update MIME type here because it's referred to in
2537 // UpdateNavigationCommands() called by RendererDidNavigate() to
2538 // determine whether or not to enable the encoding menu.
2539 // It's updated only for the main frame. For a subframe,
2540 // RenderView::UpdateURL does not set params.contents_mime_type.
2541 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2542 // TODO(jungshik): Add a test for the encoding menu to avoid
2543 // regressing it again.
[email protected]2905f742011-10-13 03:51:582544 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322545 contents_mime_type_ = params.contents_mime_type;
2546
[email protected]8286f51a2011-05-31 17:39:132547 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002548 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392549
[email protected]a9c0bfe2010-09-17 08:35:222550 // Send notification about committed provisional loads. This notification is
2551 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2552 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082553 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072554 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2555 // that is not recorded in the navigation history. For the purpose of
2556 // tracking navigation events, we treat this event as a sub frame navigation
2557 // event.
2558 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582559 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222560 // Whether or not a page transition was triggered by going backward or
2561 // forward in the history is only stored in the navigation controller's
2562 // entry list.
2563 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512564 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582565 content::PAGE_TRANSITION_FORWARD_BACK)) {
2566 transition_type = content::PageTransitionFromInt(
2567 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222568 }
[email protected]0d60f0192011-04-14 12:40:102569 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102571 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462572 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222573 }
2574
[email protected]76543b92009-08-31 17:27:452575 if (!did_navigate)
2576 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322577
2578 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2579 // for the appropriate notification (best) or you can add it to
2580 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2581 // necessary, please).
2582
2583 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002584 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322585 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512586 if (delegate_)
2587 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002588 }
[email protected]420ae012009-04-24 05:16:322589 DidNavigateAnyFramePostCommit(rvh, details, params);
2590}
2591
[email protected]b172aee2012-04-10 17:05:262592void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2593 int32 page_id,
2594 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152595 // Ensure that this state update comes from either the active RVH or one of
2596 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522597 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322598
2599 // We must be prepared to handle state updates for any page, these occur
2600 // when the user is scrolling and entering form data, as well as when we're
2601 // leaving a page, in which case our state may have already been moved to
2602 // the next page. The navigation controller will look up the appropriate
2603 // NavigationEntry and update it when it is notified via the delegate.
2604
2605 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582606 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322607 if (entry_index < 0)
2608 return;
[email protected]10f417c52011-12-28 21:04:232609 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322610
[email protected]36fc0392011-12-25 03:59:512611 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322612 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512613 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322614 controller_.NotifyEntryChanged(entry, entry_index);
2615}
2616
[email protected]b172aee2012-04-10 17:05:262617void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2618 int32 page_id,
2619 const string16& title,
2620 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322621 // If we have a title, that's a pretty good indication that we've started
2622 // getting useful data.
2623 SetNotWaitingForResponse();
2624
[email protected]73eb2602012-02-09 19:50:552625 // Try to find the navigation entry, which might not be the current one.
2626 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232627 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582628 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092629
[email protected]73eb2602012-02-09 19:50:552630 // We can handle title updates when we don't have an entry in
2631 // UpdateTitleForEntry, but only if the update is from the current RVH.
2632 if (!entry && rvh != GetRenderViewHost())
2633 return;
2634
[email protected]a49e10b2011-08-01 23:57:462635 // TODO(evan): make use of title_direction.
2636 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092637 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322638 return;
2639
2640 // Broadcast notifications when the UI should be updated.
2641 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462642 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322643}
2644
[email protected]b172aee2012-04-10 17:05:262645void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2646 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312647 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322648}
2649
[email protected]b172aee2012-04-10 17:05:262650void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512651 if (delegate_)
2652 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322653}
2654
[email protected]b172aee2012-04-10 17:05:262655void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292656 // The UI may be in an event-tracking loop, such as between the
2657 // mouse-down and mouse-up in text selection or a button click.
2658 // Defer the close until after tracking is complete, so that we
2659 // don't free objects out from under the UI.
2660 // TODO(shess): This could probably be integrated with the
2661 // IsDoingDrag() test below. Punting for now because I need more
2662 // research to understand how this impacts platforms other than Mac.
2663 // TODO(shess): This could get more fine-grained. For instance,
2664 // closing a tab in another window while selecting text in the
2665 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212666 if (GetView()->IsEventTracking()) {
2667 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292668 return;
2669 }
2670
[email protected]24a4d1062009-07-10 23:10:422671 // If we close the tab while we're in the middle of a drag, we'll crash.
2672 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212673 if (GetView()->IsDoingDrag()) {
2674 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422675 return;
2676 }
2677
[email protected]420ae012009-04-24 05:16:322678 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522679 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512680 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322681}
2682
[email protected]b172aee2012-04-10 17:05:262683void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522684 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512685 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572686}
2687
[email protected]b172aee2012-04-10 17:05:262688void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512689 if (delegate_ && delegate_->IsPopupOrPanel(this))
2690 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322691}
2692
[email protected]89793072012-07-23 22:25:292693void WebContentsImpl::DidStartLoading(
2694 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322695 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492696
[email protected]82114f52012-03-20 22:53:412697 if (delegate_ && content_restrictions_)
2698 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492699
2700 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292701 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2702 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322703}
2704
[email protected]89793072012-07-23 22:25:292705void WebContentsImpl::DidStopLoading(
2706 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322707 scoped_ptr<LoadNotificationDetails> details;
2708
[email protected]10f417c52011-12-28 21:04:232709 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322710 // An entry may not exist for a stop when loading an initial blank page or
2711 // if an iframe injected by script into a blank page finishes loading.
2712 if (entry) {
[email protected]420ae012009-04-24 05:16:322713 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2714
2715 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512716 entry->GetVirtualURL(),
2717 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322718 elapsed,
2719 &controller_,
2720 controller_.GetCurrentEntryIndex()));
2721 }
2722
[email protected]420ae012009-04-24 05:16:322723 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492724
2725 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292726 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2727 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322728}
2729
[email protected]b172aee2012-04-10 17:05:262730void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162731 controller_.DiscardNonCommittedEntries();
2732
2733 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462734 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162735}
2736
[email protected]b172aee2012-04-10 17:05:262737void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512738 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132739 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402740}
2741
[email protected]87717d0e2012-04-26 02:58:432742void WebContentsImpl::DocumentAvailableInMainFrame(
2743 RenderViewHost* render_view_host) {
2744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2745 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102746}
2747
[email protected]b172aee2012-04-10 17:05:262748void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082749 RenderViewHost* render_view_host,
2750 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072751 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272752 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322753 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532754 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082755}
2756
[email protected]196159d2012-05-04 17:26:542757void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2758 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262759 const content::Referrer& referrer,
2760 WindowOpenDisposition disposition,
2761 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542762 // If this came from a swapped out RenderViewHost, we only allow the request
2763 // if we are still in the same BrowsingInstance.
2764 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2765 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2766 return;
2767 }
2768
[email protected]4ad5d77d2011-12-03 02:00:482769 // Delegate to RequestTransferURL because this is just the generic
2770 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582771 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482772 GlobalRequestID());
2773}
2774
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::RequestTransferURL(
2776 const GURL& url,
2777 const content::Referrer& referrer,
2778 WindowOpenDisposition disposition,
2779 int64 source_frame_id,
2780 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202781 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582782 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582783 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352784 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322785 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2786 // generated suggestions).
2787 //
[email protected]e0112912011-02-02 22:54:352788 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162789 // want web sites to see a referrer of "chrome://blah" (and some
2790 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322791 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432792 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222793 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482794 false /* is_renderer_initiated */);
2795 params.transferred_global_request_id = old_request_id;
2796 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222797 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322798 } else {
[email protected]6bf6a6b52012-02-03 15:41:432799 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482800 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2801 params.transferred_global_request_id = old_request_id;
2802 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582803 }
2804 if (new_contents) {
2805 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582807 DidOpenRequestedURL(new_contents,
2808 url,
2809 referrer,
2810 disposition,
2811 transition_type,
2812 source_frame_id));
[email protected]420ae012009-04-24 05:16:322813 }
2814}
2815
[email protected]e1c3a552012-05-04 20:51:322816void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2817 // Tell the active RenderViewHost to run unload handlers and close, as long
2818 // as the request came from a RenderViewHost in the same BrowsingInstance.
2819 // In most cases, we receive this from a swapped out RenderViewHost.
2820 // It is possible to receive it from one that has just been swapped in,
2821 // in which case we might as well deliver the message anyway.
2822 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2823 GetRenderViewHost()->ClosePage();
2824}
2825
[email protected]f546640b2012-05-15 00:03:492826void WebContentsImpl::RouteMessageEvent(
2827 RenderViewHost* rvh,
2828 const ViewMsg_PostMessage_Params& params) {
2829 // Only deliver the message to the active RenderViewHost if the request
2830 // came from a RenderViewHost in the same BrowsingInstance.
2831 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2832 return;
2833
2834 ViewMsg_PostMessage_Params new_params(params);
2835
2836 // If there is a source_routing_id, translate it to the routing ID for
2837 // the equivalent swapped out RVH in the target process. If we need
2838 // to create a swapped out RVH for the source tab, we create its opener
2839 // chain as well, since those will also be accessible to the target page.
2840 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2841 // Try to look up the WebContents for the source page.
2842 WebContentsImpl* source_contents = NULL;
2843 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2844 rvh->GetProcess()->GetID(), params.source_routing_id);
2845 if (source_rvh) {
2846 source_contents = static_cast<WebContentsImpl*>(
2847 source_rvh->GetDelegate()->GetAsWebContents());
2848 }
2849
2850 if (source_contents) {
2851 new_params.source_routing_id =
2852 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2853 } else {
2854 // We couldn't find it, so don't pass a source frame.
2855 new_params.source_routing_id = MSG_ROUTING_NONE;
2856 }
2857 }
2858
2859 // In most cases, we receive this from a swapped out RenderViewHost.
2860 // It is possible to receive it from one that has just been swapped in,
2861 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182862 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492863}
2864
[email protected]b172aee2012-04-10 17:05:262865void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342866 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412867 const string16& message,
2868 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322869 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142870 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322871 IPC::Message* reply_msg,
2872 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072873 // Suppress JavaScript dialogs when requested. Also suppress messages when
2874 // showing an interstitial as it's shown over the previous page and we don't
2875 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502876 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582877 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272878 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072879 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522880 delegate_->ShouldSuppressDialogs() ||
2881 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322882
2883 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432884 std::string accept_lang = content::GetContentClient()->browser()->
2885 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552886 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522887 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432888 this,
2889 frame_url.GetOrigin(),
2890 accept_lang,
2891 javascript_message_type,
2892 message,
[email protected]51da7e32012-01-30 19:24:522893 default_prompt,
[email protected]b172aee2012-04-10 17:05:262894 base::Bind(&WebContentsImpl::OnDialogClosed,
2895 base::Unretained(this),
2896 rvh,
2897 reply_msg),
[email protected]51da7e32012-01-30 19:24:522898 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322899 }
[email protected]3ab9cb82011-06-03 18:02:072900
2901 if (suppress_this_message) {
2902 // If we are suppressing messages, just reply as if the user immediately
2903 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342904 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072905 }
2906
2907 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322908}
2909
[email protected]b172aee2012-04-10 17:05:262910void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2911 const string16& message,
2912 bool is_reload,
2913 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582914 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512915 if (delegate_)
2916 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072917
2918 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582919 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072920 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522921 delegate_->ShouldSuppressDialogs() ||
2922 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152923 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342924 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582925 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502926 return;
2927 }
[email protected]3ab9cb82011-06-03 18:02:072928
[email protected]7ab1e7d62009-10-14 23:32:012929 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552930 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522931 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322932 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262933 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522934 reply_msg));
[email protected]420ae012009-04-24 05:16:322935}
2936
[email protected]a796f202012-05-30 14:14:252937bool WebContentsImpl::AddMessageToConsole(int32 level,
2938 const string16& message,
2939 int32 line_no,
2940 const string16& source_id) {
2941 if (!delegate_)
2942 return false;
2943 return delegate_->AddMessageToConsole(this, level, message, line_no,
2944 source_id);
2945}
2946
[email protected]b172aee2012-04-10 17:05:262947WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332948 // We want to base the page config off of the real URL, rather than the
2949 // display URL.
2950 GURL url = controller_.GetActiveEntry()
2951 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2952 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322953}
2954
[email protected]b172aee2012-04-10 17:05:262955void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272956 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252957 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222958
[email protected]ea114722012-03-12 01:11:252959 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172960 if (rdh) // NULL in unittests.
2961 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252962}
2963
[email protected]b172aee2012-04-10 17:05:262964void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442965 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252966 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442967}
2968
[email protected]b172aee2012-04-10 17:05:262969void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2970 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152971 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522972 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152973 return;
2974
[email protected]9f76c1e2012-03-05 15:15:582975 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2976
[email protected]e5fc1632011-08-08 07:51:532977 // Ignore renderer unresponsive event if debugger is attached to the tab
2978 // since the event may be a result of the renderer sitting on a breakpoint.
2979 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442980 DevToolsAgentHost* agent =
2981 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2982 if (agent &&
2983 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532984 return;
2985
[email protected]420ae012009-04-24 05:16:322986 if (is_during_unload) {
2987 // Hang occurred while firing the beforeunload/unload handler.
2988 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582989 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322990
2991 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2992 return;
2993
2994 // If the tab hangs in the beforeunload/unload handler there's really
2995 // nothing we can do to recover. Pretend the unload listeners have
2996 // all fired and close the tab. If the hang is in the beforeunload handler
2997 // then the user will not have the option of cancelling the close.
2998 Close(rvh);
2999 return;
3000 }
3001
[email protected]9f76c1e2012-03-05 15:15:583002 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473003 return;
3004
[email protected]6934a702011-12-20 00:04:513005 if (delegate_)
3006 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323007}
3008
[email protected]b172aee2012-04-10 17:05:263009void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513010 if (delegate_)
3011 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323012}
3013
[email protected]b172aee2012-04-10 17:05:263014void WebContentsImpl::LoadStateChanged(
3015 const GURL& url,
3016 const net::LoadStateWithParam& load_state,
3017 uint64 upload_position,
3018 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323019 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563020 upload_position_ = upload_position;
3021 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503022 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203023 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303024 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213025 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323026 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463027 if (IsLoading()) {
3028 NotifyNavigationStateChanged(
3029 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3030 }
[email protected]420ae012009-04-24 05:16:323031}
3032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513034 if (delegate_)
3035 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253036}
3037
[email protected]b172aee2012-04-10 17:05:263038void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323039 bool proceed,
3040 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513041 if (delegate_)
3042 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323043}
3044
[email protected]b172aee2012-04-10 17:05:263045void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543046 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233047 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3048 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543049}
3050
[email protected]b172aee2012-04-10 17:05:263051void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103052 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263053 gfx::Size size = view_->GetContainerSize();
3054 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3055 // here during container initialization and normal window size will be set
3056 // later. In case of tab duplication this resizing to 0x0 prevents setting
3057 // normal size later so just ignore it.
3058 if (!size.IsEmpty())
3059 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323060}
3061
[email protected]b172aee2012-04-10 17:05:263062void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543063 NotifySwapped();
3064}
3065
[email protected]14392a52012-05-02 20:28:443066int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3067 SiteInstance* instance) {
3068 if (!opener_)
3069 return MSG_ROUTING_NONE;
3070
3071 // Recursively create RenderViews for anything else in the opener chain.
3072 return opener_->CreateOpenerRenderViews(instance);
3073}
3074
3075int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3076 int opener_route_id = MSG_ROUTING_NONE;
3077
3078 // If this tab has an opener, ensure it has a RenderView in the given
3079 // SiteInstance as well.
3080 if (opener_)
3081 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3082
3083 // Create a swapped out RenderView in the given SiteInstance if none exists,
3084 // setting its opener to the given route_id. Return the new view's route_id.
3085 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3086}
3087
[email protected]b172aee2012-04-10 17:05:263088NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193089 return GetController();
[email protected]3a3d47472010-07-15 21:03:543090}
3091
[email protected]b172aee2012-04-10 17:05:263092WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563093 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323094}
3095
[email protected]10f417c52011-12-28 21:04:233096NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263097 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323098 return controller_.GetLastCommittedEntry();
3099}
3100
[email protected]b172aee2012-04-10 17:05:263101bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443102 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443103 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323104 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523105
[email protected]420ae012009-04-24 05:16:323106 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443107 if (rwh_view)
3108 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323109
[email protected]74ce1ad2011-12-16 21:51:463110 // Make sure we use the correct starting page_id in the new RenderView.
3111 UpdateMaxPageIDIfNecessary(render_view_host);
3112 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583113 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463114
[email protected]7900bfdb2012-05-24 19:31:243115 std::string embedder_channel_name;
3116 int embedder_container_id;
3117 GetBrowserPluginEmbedderInfo(render_view_host,
3118 &embedder_channel_name,
3119 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583120 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493121 render_view_host)->CreateRenderView(string16(),
3122 opener_route_id,
3123 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243124 embedder_channel_name,
3125 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523126 return false;
[email protected]14392a52012-05-02 20:28:443127 }
[email protected]a4127722011-04-27 23:13:523128
[email protected]e60c0232011-11-11 19:56:353129#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503130 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3131 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443132 if (rwh_view) {
3133 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3134 render_widget_host->WasResized();
3135 }
[email protected]f8233cc2011-05-31 20:24:503136#endif
3137
[email protected]420ae012009-04-24 05:16:323138 return true;
3139}
3140
[email protected]b172aee2012-04-10 17:05:263141void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3142 IPC::Message* reply_msg,
3143 bool success,
3144 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543145 if (is_showing_before_unload_dialog_ && !success) {
3146 // If a beforeunload dialog is canceled, we need to stop the throbber from
3147 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293148 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353149 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543150
[email protected]3bbacc5b2012-04-17 17:46:153151 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543152 }
3153 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583154 static_cast<RenderViewHostImpl*>(
3155 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543156}
3157
[email protected]b172aee2012-04-10 17:05:263158void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123159 encoding_ = content::GetContentClient()->browser()->
3160 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103161}
[email protected]f45d2a72010-03-08 23:28:353162
[email protected]b172aee2012-04-10 17:05:263163void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463164 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263165 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573166 DownloadManager* dlm =
3167 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143168 if (!dlm)
3169 return;
3170 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263171 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143172 const NavigationEntry* entry = controller_.GetActiveEntry();
3173 if (entry)
3174 post_id = entry->GetPostID();
3175 }
[email protected]29a5ffc82012-03-13 19:35:583176 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143177 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143178 scoped_ptr<DownloadUrlParameters> params(
3179 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493180 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143181 params->set_post_id(post_id);
3182 params->set_prefer_cache(true);
3183 if (post_id >= 0)
3184 params->set_method("POST");
3185 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143186}
3187
[email protected]b172aee2012-04-10 17:05:263188void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213189 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443190 // Can be NULL during tests.
3191 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213192 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363193}
[email protected]9f76c1e2012-03-05 15:15:583194
[email protected]b172aee2012-04-10 17:05:263195RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583196 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3197}
[email protected]7900bfdb2012-05-24 19:31:243198
3199void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3200 content::RenderViewHost* render_view_host,
3201 std::string* embedder_channel_name,
3202 int* embedder_container_id) {
3203 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283204 old_browser_plugin_host()->embedder_render_process_host();
3205 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243206 int embedder_process_id =
3207 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3208 if (embedder_process_id != -1) {
3209 *embedder_channel_name =
3210 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3211 embedder_process_id);
3212 }
3213}