blob: 32ff95d3a7c8740dbd9612da83c5626552c0b4ea [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]b172aee2012-04-10 17:05:26754RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31755 return render_manager_.GetRenderWidgetHostView();
756}
757
[email protected]b172aee2012-04-10 17:05:26758content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31759 return view_.get();
760}
761
[email protected]b172aee2012-04-10 17:05:26762content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50763 WebUIControllerFactory* factory =
764 content::GetContentClient()->browser()->GetWebUIControllerFactory();
765 if (!factory)
766 return NULL;
[email protected]d2353452012-01-19 19:53:56767 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22768 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50769 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22770 if (controller) {
771 web_ui->SetController(controller);
772 return web_ui;
773 }
774
775 delete web_ui;
776 return NULL;
777}
778
[email protected]b172aee2012-04-10 17:05:26779content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31780 return render_manager_.web_ui() ? render_manager_.web_ui()
781 : render_manager_.pending_web_ui();
782}
783
[email protected]b172aee2012-04-10 17:05:26784content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31785 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34786}
787
[email protected]86ef6a392012-05-11 22:03:11788void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22789 if (GetUserAgentOverride() == override)
790 return;
791
792 renderer_preferences_.user_agent_override = override;
793
794 // Send the new override string to the renderer.
795 RenderViewHost* host = GetRenderViewHost();
796 if (host)
797 host->SyncRendererPrefs();
798
799 // Reload the page if a load is currently in progress to avoid having
800 // different parts of the page loaded using different user agents.
801 NavigationEntry* entry = controller_.GetActiveEntry();
802 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
803 controller_.ReloadIgnoringCache(true);
[email protected]86ef6a392012-05-11 22:03:11804}
805
806const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22807 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11808}
809
[email protected]b172aee2012-04-10 17:05:26810const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55811 // Transient entries take precedence. They are used for interstitial pages
812 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23813 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08814 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20815 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30816 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23817 if (entry) {
[email protected]b5cca982011-05-26 04:42:08818 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23819 }
[email protected]7ade2732011-02-10 00:13:58820 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
821 render_manager_.pending_web_ui() : render_manager_.web_ui();
822 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54823 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55824 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54825 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35826 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22827 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54828 if (!title.empty())
829 return title;
830 }
831 }
832
833 // We use the title for the last committed entry rather than a pending
834 // navigation entry. For example, when the user types in a URL, we want to
835 // keep the old page's title until the new load has committed and we get a new
836 // title.
[email protected]96d185d2009-04-24 03:28:54837 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23838 if (entry) {
[email protected]b5cca982011-05-26 04:42:08839 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23840 }
[email protected]987fc3a2011-05-26 14:18:09841
842 // |page_title_when_no_navigation_entry_| is finally used
843 // if no title cannot be retrieved.
844 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54845}
846
[email protected]b172aee2012-04-10 17:05:26847int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46848 return GetMaxPageIDForSiteInstance(GetSiteInstance());
849}
850
[email protected]b172aee2012-04-10 17:05:26851int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
852 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33853 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
854 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46855
[email protected]b6583592012-01-25 19:52:33856 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34857}
858
[email protected]b172aee2012-04-10 17:05:26859void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46860 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
861}
862
[email protected]b172aee2012-04-10 17:05:26863void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33864 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46865 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33866 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34867}
868
[email protected]b172aee2012-04-10 17:05:26869void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
870 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57871}
872
[email protected]b172aee2012-04-10 17:05:26873SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58874 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54875}
876
[email protected]b172aee2012-04-10 17:05:26877SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38878 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
879 render_manager_.pending_render_view_host() :
880 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58881 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38882}
883
[email protected]b172aee2012-04-10 17:05:26884bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31885 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49886}
887
[email protected]b172aee2012-04-10 17:05:26888bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return waiting_for_response_;
890}
891
[email protected]b172aee2012-04-10 17:05:26892const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return load_state_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31897 return load_state_host_;
898}
899
[email protected]b172aee2012-04-10 17:05:26900uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31901 return upload_size_;
902}
903
[email protected]b172aee2012-04-10 17:05:26904uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31905 return upload_position_;
906}
907
[email protected]b172aee2012-04-10 17:05:26908const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31909 return encoding_;
910}
911
[email protected]b172aee2012-04-10 17:05:26912bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return displayed_insecure_content_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31917 capturing_contents_ = cap;
918}
919
[email protected]b172aee2012-04-10 17:05:26920bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31921 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
922 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
923 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49924}
925
[email protected]b172aee2012-04-10 17:05:26926void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
927 int error_code) {
[email protected]443b80e2010-12-14 00:42:23928 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34929 return;
930
[email protected]443b80e2010-12-14 00:42:23931 crashed_status_ = status;
932 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46933 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34934}
935
[email protected]b172aee2012-04-10 17:05:26936base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31937 return crashed_status_;
938}
939
[email protected]b172aee2012-04-10 17:05:26940bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31941 return is_being_destroyed_;
942}
943
[email protected]b172aee2012-04-10 17:05:26944void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34945 if (delegate_)
946 delegate_->NavigationStateChanged(this, changed_flags);
947}
948
[email protected]3e324142012-06-25 18:26:33949base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
950 return last_selected_time_;
951}
952
[email protected]9e2e4632012-07-27 16:38:41953void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54954 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04955 RenderWidgetHostViewPort* rwhv =
956 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16957 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41958 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43959#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16960 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43961#endif
962 }
[email protected]96d185d2009-04-24 03:28:54963
[email protected]5ac20162010-11-24 23:33:11964 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38965
[email protected]9e2e4632012-07-27 16:38:41966 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59967
968 // The resize rect might have changed while this was inactive -- send the new
969 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58970 RenderViewHostImpl* rvh =
971 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59972 if (rvh) {
973 rvh->ResizeRectChanged(GetRootWindowResizerRect());
974 }
[email protected]96d185d2009-04-24 03:28:54975
[email protected]3e324142012-06-25 18:26:33976 bool is_visible = true;
977 content::NotificationService::current()->Notify(
978 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
979 content::Source<WebContents>(this),
980 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31981}
982
[email protected]b172aee2012-04-10 17:05:26983void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31984 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52985 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
986 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26987 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52988 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33989 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52990 // calls us).
[email protected]c30585c2012-02-16 15:02:04991 RenderWidgetHostViewPort* rwhv =
992 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16993 if (rwhv)
994 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54995 }
996
[email protected]375fa1b2012-05-22 22:05:37997 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07998 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37999 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091000 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371001 content::Details<bool>(&is_visible));
1002}
1003
[email protected]b172aee2012-04-10 17:05:261004bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311005 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271006 return WillNotifyDisconnection() &&
1007 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581008 !static_cast<RenderViewHostImpl*>(
1009 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271013 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251014 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271015}
1016
[email protected]b172aee2012-04-10 17:05:261017WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441018 // We use our current SiteInstance since the cloned entry will use it anyway.
1019 // We pass |this| for the |base_web_contents| to size the view correctly, and
1020 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191021 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1022 GetSiteInstance(), MSG_ROUTING_NONE,
1023 this, opener_);
1024 tc->GetController().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271025 return tc;
1026}
1027
[email protected]b172aee2012-04-10 17:05:261028void WebContentsImpl::AddNewContents(WebContents* new_contents,
1029 WindowOpenDisposition disposition,
1030 const gfx::Rect& initial_pos,
1031 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271032 if (!delegate_)
1033 return;
1034
1035 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1036 user_gesture);
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271040 return view_->GetContentNativeView();
1041}
1042
[email protected]b172aee2012-04-10 17:05:261043gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271044 return view_->GetNativeView();
1045}
1046
[email protected]b172aee2012-04-10 17:05:261047void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271048 view_->GetContainerBounds(out);
1049}
1050
[email protected]b172aee2012-04-10 17:05:261051void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271052 view_->Focus();
1053}
1054
[email protected]14392a52012-05-02 20:28:441055void WebContentsImpl::Observe(int type,
1056 const content::NotificationSource& source,
1057 const content::NotificationDetails& details) {
1058 switch (type) {
1059 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1060 OnWebContentsDestroyed(
1061 content::Source<content::WebContents>(source).ptr());
1062 break;
[email protected]bafe6cd2012-05-23 23:09:501063 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1064 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1065 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1066 i != pending_widget_views_.end(); ++i) {
1067 if (host->GetView() == i->second) {
1068 pending_widget_views_.erase(i);
1069 break;
1070 }
1071 }
1072 break;
1073 }
[email protected]14392a52012-05-02 20:28:441074 default:
1075 NOTREACHED();
1076 }
1077}
1078
[email protected]d1198fd2012-08-13 22:50:191079void WebContentsImpl::Init(BrowserContext* browser_context,
1080 SiteInstance* site_instance,
1081 int routing_id,
1082 const WebContents* base_web_contents) {
1083 render_manager_.Init(browser_context, site_instance, routing_id);
1084
1085 view_.reset(content::GetContentClient()->browser()->
1086 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1087 if (view_.get()) {
1088 CHECK(render_view_host_delegate_view_);
1089 } else {
1090 content::WebContentsViewDelegate* delegate =
1091 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1092 this);
1093 view_.reset(CreateWebContentsView(
1094 this, delegate, &render_view_host_delegate_view_));
1095 CHECK(render_view_host_delegate_view_);
1096 }
1097 CHECK(view_.get());
1098
1099 // We have the initial size of the view be based on the size of the view of
1100 // the passed in WebContents.
1101 view_->CreateView(base_web_contents ?
1102 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1103
1104 // Listen for whether our opener gets destroyed.
1105 if (opener_) {
1106 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1107 content::Source<WebContents>(opener_));
1108 }
1109
1110 registrar_.Add(this,
1111 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1112 content::NotificationService::AllBrowserContextsAndSources());
1113#if defined(ENABLE_JAVA_BRIDGE)
1114 java_bridge_dispatcher_host_manager_.reset(
1115 new JavaBridgeDispatcherHostManager(this));
1116#endif
1117
1118 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1119}
1120
[email protected]14392a52012-05-02 20:28:441121void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1122 // Clear the opener if it has been closed.
1123 if (web_contents == opener_) {
1124 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1125 content::Source<WebContents>(opener_));
1126 opener_ = NULL;
1127 }
1128}
1129
[email protected]b172aee2012-04-10 17:05:261130void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311131 observers_.AddObserver(observer);
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311135 observers_.RemoveObserver(observer);
1136}
1137
[email protected]b172aee2012-04-10 17:05:261138void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341139 if (delegate_)
1140 delegate_->ActivateContents(this);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121144 if (delegate_)
1145 delegate_->DeactivateContents(this);
1146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481149 if (delegate_)
1150 delegate_->LostCapture();
1151}
1152
[email protected]b172aee2012-04-10 17:05:261153bool WebContentsImpl::PreHandleKeyboardEvent(
1154 const NativeWebKeyboardEvent& event,
1155 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481156 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131157 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481161 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131162 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481163}
1164
[email protected]b172aee2012-04-10 17:05:261165void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431166 if (delegate_)
1167 delegate_->HandleMouseDown();
1168}
1169
[email protected]b172aee2012-04-10 17:05:261170void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481171 if (delegate_)
1172 delegate_->HandleMouseUp();
1173}
1174
[email protected]590a634e2012-07-19 16:38:231175void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481176 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231177 delegate_->HandlePointerActivate();
1178}
1179
1180void WebContentsImpl::HandleGestureBegin() {
1181 if (delegate_)
1182 delegate_->HandleGestureBegin();
1183}
1184
1185void WebContentsImpl::HandleGestureEnd() {
1186 if (delegate_)
1187 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481188}
1189
[email protected]b172aee2012-04-10 17:05:261190void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471191 if (delegate_)
1192 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1193}
1194
[email protected]b172aee2012-04-10 17:05:261195bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381196 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121197}
1198
[email protected]a9c81f02012-06-01 00:15:441199void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1200 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371201 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441202 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371203 } else {
1204 GotResponseToLockMouseRequest(false);
1205 }
1206}
1207
[email protected]b172aee2012-04-10 17:05:261208void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371209 if (delegate_)
1210 delegate_->LostMouseLock();
1211}
1212
[email protected]bafe6cd2012-05-23 23:09:501213void WebContentsImpl::CreateNewWindow(
1214 int route_id,
[email protected]97714c82012-06-06 10:15:131215 const ViewHostMsg_CreateWindow_Params& params,
1216 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501217 if (delegate_ && !delegate_->ShouldCreateWebContents(
1218 this, route_id, params.window_container_type, params.frame_name,
1219 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091220 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501221 return;
1222 }
1223
1224 // We usually create the new window in the same BrowsingInstance (group of
1225 // script-related windows), by passing in the current SiteInstance. However,
1226 // if the opener is being suppressed, we create a new SiteInstance in its own
1227 // BrowsingInstance.
1228 scoped_refptr<SiteInstance> site_instance =
1229 params.opener_suppressed ?
1230 SiteInstance::Create(GetBrowserContext()) :
1231 GetSiteInstance();
1232
1233 // Create the new web contents. This will automatically create the new
1234 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191235 WebContentsImpl* new_contents =
1236 new WebContentsImpl(GetBrowserContext(),
1237 params.opener_suppressed ? NULL : this);
1238
1239 // We must assign the SessionStorageNamespace before calling Init().
1240 const std::string& partition_id =
1241 content::GetContentClient()->browser()->
1242 GetStoragePartitionIdForSiteInstance(GetBrowserContext(),
1243 site_instance);
1244 DOMStorageContextImpl* dom_storage_context =
1245 static_cast<DOMStorageContextImpl*>(
1246 BrowserContext::GetDOMStorageContextByPartitionId(
1247 GetBrowserContext(), partition_id));
1248 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1249 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1250 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1251 new_contents->GetController().SetSessionStorageNamespace(
1252 partition_id,
1253 session_storage_namespace);
1254 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1255
[email protected]bafe6cd2012-05-23 23:09:501256 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1257
1258 if (!params.opener_suppressed) {
1259 content::WebContentsView* new_view = new_contents->GetView();
1260
1261 // TODO(brettw): It seems bogus that we have to call this function on the
1262 // newly created object and give it one of its own member variables.
1263 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1264
1265 // Save the created window associated with the route so we can show it
1266 // later.
1267 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1268 pending_contents_[route_id] = new_contents;
1269 }
1270
1271 if (delegate_) {
1272 delegate_->WebContentsCreated(
1273 this, params.opener_frame_id, params.target_url, new_contents);
1274 }
1275
1276 if (params.opener_suppressed) {
1277 // When the opener is suppressed, the original renderer cannot access the
1278 // new window. As a result, we need to show and navigate the window here.
1279 gfx::Rect initial_pos;
1280 AddNewContents(
1281 new_contents, params.disposition, initial_pos, params.user_gesture);
1282
1283 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1284 CURRENT_TAB,
1285 content::PAGE_TRANSITION_LINK,
1286 true /* is_renderer_initiated */);
1287 new_contents->OpenURL(open_params);
1288 }
1289}
1290
1291void WebContentsImpl::CreateNewWidget(int route_id,
1292 WebKit::WebPopupType popup_type) {
1293 CreateNewWidget(route_id, false, popup_type);
1294}
1295
1296void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1297 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1298}
1299
1300void WebContentsImpl::CreateNewWidget(int route_id,
1301 bool is_fullscreen,
1302 WebKit::WebPopupType popup_type) {
1303 content::RenderProcessHost* process = GetRenderProcessHost();
1304 RenderWidgetHostImpl* widget_host =
1305 new RenderWidgetHostImpl(this, process, route_id);
1306 RenderWidgetHostViewPort* widget_view =
1307 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1308 if (!is_fullscreen) {
1309 // Popups should not get activated.
1310 widget_view->SetPopupType(popup_type);
1311 }
1312 // Save the created widget associated with the route so we can show it later.
1313 pending_widget_views_[route_id] = widget_view;
1314
1315#if defined(OS_MACOSX)
1316 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1317 // to allow it to survive the trip without being hosted.
1318 base::mac::NSObjectRetain(widget_view->GetNativeView());
1319#endif
1320}
1321
1322void WebContentsImpl::ShowCreatedWindow(int route_id,
1323 WindowOpenDisposition disposition,
1324 const gfx::Rect& initial_pos,
1325 bool user_gesture) {
1326 WebContentsImpl* contents = GetCreatedWindow(route_id);
1327 if (contents)
1328 AddNewContents(contents, disposition, initial_pos, user_gesture);
1329}
1330
1331void WebContentsImpl::ShowCreatedWidget(int route_id,
1332 const gfx::Rect& initial_pos) {
1333 ShowCreatedWidget(route_id, false, initial_pos);
1334}
1335
1336void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1337 ShowCreatedWidget(route_id, true, gfx::Rect());
1338}
1339
1340void WebContentsImpl::ShowCreatedWidget(int route_id,
1341 bool is_fullscreen,
1342 const gfx::Rect& initial_pos) {
1343 if (delegate_)
1344 delegate_->RenderWidgetShowing();
1345
1346 RenderWidgetHostViewPort* widget_host_view =
1347 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1348 if (!widget_host_view)
1349 return;
1350 if (is_fullscreen) {
1351 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1352 } else {
1353 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1354 }
[email protected]89054502012-06-03 10:29:241355
1356 RenderWidgetHostImpl* render_widget_host_impl =
1357 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1358 render_widget_host_impl->Init();
1359 // Only allow privileged mouse lock for fullscreen render widget, which is
1360 // used to implement Pepper Flash fullscreen.
1361 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501362
1363#if defined(OS_MACOSX)
1364 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1365 // properly embedded (or purposefully ignored) we can release the retain we
1366 // took in CreateNewWidget().
1367 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1368#endif
1369}
1370
1371WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1372 PendingContents::iterator iter = pending_contents_.find(route_id);
1373
1374 // Certain systems can block the creation of new windows. If we didn't succeed
1375 // in creating one, just return NULL.
1376 if (iter == pending_contents_.end()) {
1377 return NULL;
1378 }
1379
1380 WebContentsImpl* new_contents = iter->second;
1381 pending_contents_.erase(route_id);
1382
1383 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1384 !new_contents->GetRenderViewHost()->GetView())
1385 return NULL;
1386
1387 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1388 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1389 return new_contents;
1390}
1391
1392RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1393 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1394 if (iter == pending_widget_views_.end()) {
1395 DCHECK(false);
1396 return NULL;
1397 }
1398
1399 RenderWidgetHostView* widget_host_view = iter->second;
1400 pending_widget_views_.erase(route_id);
1401
1402 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1403 if (!widget_host->GetProcess()->HasConnection()) {
1404 // The view has gone away or the renderer crashed. Nothing to do.
1405 return NULL;
1406 }
1407
1408 return widget_host_view;
1409}
1410
1411void WebContentsImpl::ShowContextMenu(
1412 const content::ContextMenuParams& params) {
1413 // Allow WebContentsDelegates to handle the context menu operation first.
1414 if (delegate_ && delegate_->HandleContextMenu(params))
1415 return;
1416
[email protected]5a3bdf52012-05-24 15:12:571417 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501418}
1419
[email protected]f13b4202012-06-12 23:53:231420void WebContentsImpl::RequestMediaAccessPermission(
1421 const content::MediaStreamRequest* request,
1422 const content::MediaResponseCallback& callback) {
1423 if (delegate_)
1424 delegate_->RequestMediaAccessPermission(this, request, callback);
1425 else
1426 callback.Run(content::MediaStreamDevices());
1427}
1428
[email protected]b172aee2012-04-10 17:05:261429void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231430 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331431 if (delegate_)
1432 delegate_->UpdatePreferredSize(this, pref_size);
1433}
1434
[email protected]b172aee2012-04-10 17:05:261435void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341436 if (delegate_)
1437 delegate_->ResizeDueToAutoResize(this, new_size);
1438}
1439
[email protected]b172aee2012-04-10 17:05:261440WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201441 if (!delegate_)
1442 return NULL;
[email protected]00c37fc2011-08-02 00:22:501443
[email protected]e5d549d2011-12-28 01:29:201444 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1445 // Notify observers.
1446 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1447 DidOpenURL(params.url, params.referrer,
1448 params.disposition, params.transition));
1449 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341450}
1451
[email protected]b172aee2012-04-10 17:05:261452bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501453 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251454 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231455 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251456 reload_type);
[email protected]876bc832010-09-07 16:29:541457}
[email protected]96d185d2009-04-24 03:28:541458
[email protected]ba45bfd2012-05-22 21:51:441459void WebContentsImpl::RenderViewForInterstitialPageCreated(
1460 content::RenderViewHost* render_view_host) {
1461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1462 RenderViewForInterstitialPageCreated(render_view_host));
1463}
1464
[email protected]b172aee2012-04-10 17:05:261465bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231466 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501467 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401468 // The renderer will reject IPC messages with URLs longer than
1469 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511470 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401471 return false;
1472
[email protected]9f76c1e2012-03-05 15:15:581473 RenderViewHostImpl* dest_render_view_host =
1474 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401475 if (!dest_render_view_host)
1476 return false; // Unable to create the desired render view host.
1477
[email protected]80a8fad2011-01-29 04:02:381478 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071479 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581480 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501481 WebUIControllerFactory* factory =
1482 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271483 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501484 bool is_allowed_in_web_ui_renderer =
1485 factory &&
[email protected]24e18252012-04-16 21:26:271486 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1487 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231488 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1489 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271490 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231491 content::GetContentClient()->SetActiveURL(entry.GetURL());
1492 CHECK(0);
1493 }
[email protected]54ec6472010-04-09 19:39:581494
[email protected]96d185d2009-04-24 03:28:541495 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441496 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521497 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441498 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511499 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541500
[email protected]7bb761892012-07-20 09:32:471501 // Notify observers that we will navigate in this RV.
1502 FOR_EACH_OBSERVER(WebContentsObserver,
1503 observers_,
1504 AboutToNavigateRenderView(dest_render_view_host));
1505
[email protected]96d185d2009-04-24 03:28:541506 // Used for page load time metrics.
1507 current_load_start_ = base::TimeTicks::Now();
1508
1509 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241510 std::string embedder_channel_name;
1511 int embedder_container_id;
1512 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1513 &embedder_channel_name,
1514 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341515 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271516 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241517 embedder_channel_name,
1518 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471519 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341520 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541521
[email protected]36fc0392011-12-25 03:59:511522 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541523 // HACK!! This code suppresses javascript: URLs from being added to
1524 // session history, which is what we want to do for javascript: URLs that
1525 // do not generate content. What we really need is a message from the
1526 // renderer telling us that a new page was not created. The same message
1527 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511528 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541529 return false;
1530 }
1531
[email protected]3c9e1872010-11-18 16:17:491532 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251533 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041534 observers_,
[email protected]36fc0392011-12-25 03:59:511535 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541536
[email protected]09b29342011-06-24 19:18:481537 if (delegate_)
1538 delegate_->DidNavigateToPendingEntry(this);
1539
[email protected]d5f942ba2008-09-26 19:30:341540 return true;
1541}
1542
[email protected]b172aee2012-04-10 17:05:261543void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331544 const SiteInstance* site_instance,
1545 int history_length,
1546 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411547 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1548 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191549 if (render_manager_.pending_render_view_host()) {
1550 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141551 return;
[email protected]9e1ad4b2011-08-14 16:49:191552 }
[email protected]9f76c1e2012-03-05 15:15:581553 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191554 if (!rvh) {
1555 NOTREACHED();
1556 return;
1557 }
[email protected]9f76c1e2012-03-05 15:15:581558 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191559 NOTREACHED();
1560 return;
1561 }
[email protected]9f76c1e2012-03-05 15:15:581562 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191563 history_length,
1564 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141565}
1566
[email protected]b172aee2012-04-10 17:05:261567void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271568 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541569 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1570 return;
1571 }
[email protected]9f76c1e2012-03-05 15:15:581572 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541573}
1574
[email protected]b172aee2012-04-10 17:05:261575bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271576 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541577}
1578
[email protected]b172aee2012-04-10 17:05:261579InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271580 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221581}
1582
[email protected]b172aee2012-04-10 17:05:261583bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161584 // WebKit creates Document object when MIME type is application/xhtml+xml,
1585 // so we also support this MIME type.
1586 return contents_mime_type_ == "text/html" ||
1587 contents_mime_type_ == "text/xml" ||
1588 contents_mime_type_ == "application/xhtml+xml" ||
1589 contents_mime_type_ == "text/plain" ||
1590 contents_mime_type_ == "text/css" ||
1591 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1592}
1593
[email protected]b172aee2012-04-10 17:05:261594void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591595 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161596 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481597 download_stats::RecordDownloadSource(
1598 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461599 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141600 return;
[email protected]c7dd2f62011-07-18 15:57:591601 }
1602
1603 Stop();
1604
1605 // Create the save package and possibly prompt the user for the name to save
1606 // the page as. The user prompt is an asynchronous operation that runs on
1607 // another thread.
1608 save_package_ = new SavePackage(this);
1609 save_package_->GetSaveInfo();
1610}
1611
1612// Used in automated testing to bypass prompting the user for file names.
1613// Instead, the names and paths are hard coded rather than running them through
1614// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261615bool WebContentsImpl::SavePage(const FilePath& main_file,
1616 const FilePath& dir_path,
1617 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591618 // Stop the page from navigating.
1619 Stop();
1620
1621 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271622 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591623}
1624
[email protected]b172aee2012-04-10 17:05:261625void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121626 const FilePath& file,
1627 const base::Callback<void(const FilePath&, int64)>& callback) {
1628 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1629}
1630
[email protected]b172aee2012-04-10 17:05:261631bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231632 NavigationEntryImpl* active_entry =
1633 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321634 return (active_entry != NULL &&
1635 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511636 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321637}
1638
[email protected]b172aee2012-04-10 17:05:261639const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271640 return contents_mime_type_;
1641}
1642
[email protected]b172aee2012-04-10 17:05:261643bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271644 return notify_disconnection_;
1645}
1646
[email protected]b172aee2012-04-10 17:05:261647void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311648 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581649 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1650 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161651}
1652
[email protected]b172aee2012-04-10 17:05:261653void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311654 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581655 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1656 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161657}
1658
[email protected]b172aee2012-04-10 17:05:261659content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271660 return &renderer_preferences_;
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271664 new_tab_start_time_ = time;
1665}
1666
[email protected]b172aee2012-04-10 17:05:261667base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271668 return new_tab_start_time_;
1669}
1670
[email protected]e35ccd52012-05-23 16:22:471671void WebContentsImpl::Close() {
1672 Close(GetRenderViewHost());
1673}
1674
[email protected]b172aee2012-04-10 17:05:261675void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151676 if (close_start_time_.is_null())
1677 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011678}
1679
[email protected]b172aee2012-04-10 17:05:261680bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191681#if defined(OS_CHROMEOS)
1682 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1683 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511684 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201685 return false;
1686 return true;
[email protected]46624bf2010-06-09 16:04:191687#else
1688 return true;
1689#endif
1690}
1691
[email protected]b172aee2012-04-10 17:05:261692void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521693 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581694 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511695 if (delegate_)
1696 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341697}
1698
[email protected]e35ccd52012-05-23 16:22:471699void WebContentsImpl::UserGestureDone() {
1700 OnUserGesture();
1701}
1702
[email protected]b172aee2012-04-10 17:05:261703void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271704 closed_by_user_gesture_ = value;
1705}
1706
[email protected]b172aee2012-04-10 17:05:261707bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271708 return closed_by_user_gesture_;
1709}
1710
[email protected]b172aee2012-04-10 17:05:261711double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051712 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561713 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251714 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171715 return 0;
[email protected]b75b8292010-10-01 07:28:251716
1717 double zoom_level;
1718 if (temporary_zoom_settings_) {
1719 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581720 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251721 } else {
[email protected]2ae88d12011-10-14 09:11:191722 GURL url;
[email protected]10f417c52011-12-28 21:04:231723 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191724 // Since zoom map is updated using rewritten URL, use rewritten URL
1725 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511726 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191727 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251728 }
[email protected]d0b8d092010-10-25 04:05:171729 return zoom_level;
1730}
[email protected]b75b8292010-10-01 07:28:251731
[email protected]b172aee2012-04-10 17:05:261732int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1733 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171734 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011735 // Calculate the zoom percent from the factor. Round up to the nearest whole
1736 // number.
[email protected]b75b8292010-10-01 07:28:251737 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011738 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251739 *enable_decrement = percent > minimum_zoom_percent_;
1740 *enable_increment = percent < maximum_zoom_percent_;
1741 return percent;
1742}
1743
[email protected]b172aee2012-04-10 17:05:261744void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501745 if (!delegate_)
1746 return;
1747
[email protected]10f417c52011-12-28 21:04:231748 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501749 if (!active_entry)
1750 return;
1751
[email protected]36fc0392011-12-25 03:59:511752 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121753}
1754
[email protected]b172aee2012-04-10 17:05:261755void WebContentsImpl::ViewFrameSource(const GURL& url,
1756 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271757 if (!delegate_)
1758 return;
1759
1760 delegate_->ViewSourceForFrame(this, url, content_state);
1761}
1762
[email protected]b172aee2012-04-10 17:05:261763int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271764 return minimum_zoom_percent_;
1765}
1766
[email protected]b172aee2012-04-10 17:05:261767int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271768 return maximum_zoom_percent_;
1769}
1770
[email protected]b172aee2012-04-10 17:05:261771gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231772 return preferred_size_;
1773}
1774
[email protected]b172aee2012-04-10 17:05:261775int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271776 return content_restrictions_;
1777}
1778
[email protected]b172aee2012-04-10 17:05:261779WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501780 WebUIControllerFactory* factory =
1781 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1782 if (!factory)
1783 return WebUI::kNoWebUI;
1784 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271785}
1786
[email protected]b172aee2012-04-10 17:05:261787content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271788 // When there is a pending navigation entry, we want to use the pending WebUI
1789 // that goes along with it to control the basic flags. For example, we want to
1790 // show the pending URL in the URL bar, so we want the display_url flag to
1791 // be from the pending entry.
1792 //
1793 // The confusion comes because there are multiple possibilities for the
1794 // initial load in a tab as a side effect of the way the RenderViewHostManager
1795 // works.
1796 //
1797 // - For the very first tab the load looks "normal". The new tab Web UI is
1798 // the pending one, and we want it to apply here.
1799 //
1800 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1801 // get switched to the one previously associated with the new tab pages.
1802 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1803 // have a committed Web UI in this case.
1804 //
1805 // This condition handles all of these cases:
1806 //
1807 // - First load in first tab: no committed nav entry + pending nav entry +
1808 // pending dom ui:
1809 // -> Use pending Web UI if any.
1810 //
1811 // - First load in second tab: no committed nav entry + pending nav entry +
1812 // no pending Web UI:
1813 // -> Use the committed Web UI if any.
1814 //
1815 // - Second navigation in any tab: committed nav entry + pending nav entry:
1816 // -> Use pending Web UI if any.
1817 //
1818 // - Normal state with no load: committed nav entry + no pending nav entry:
1819 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251820 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271821 (controller_.GetLastCommittedEntry() ||
1822 render_manager_.pending_web_ui()))
1823 return render_manager_.pending_web_ui();
1824 return render_manager_.web_ui();
1825}
1826
[email protected]b172aee2012-04-10 17:05:261827bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271828 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581829 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271830}
1831
[email protected]b172aee2012-04-10 17:05:261832bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441833 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501834}
1835
[email protected]b172aee2012-04-10 17:05:261836void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321837 SkColor color) {
[email protected]da8543762012-03-20 08:52:201838 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1839 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1840}
1841
[email protected]b172aee2012-04-10 17:05:261842void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201843 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1844 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1845 if (delegate_)
1846 delegate_->DidEndColorChooser();
1847 color_chooser_ = NULL;
1848}
1849
[email protected]b172aee2012-04-10 17:05:261850bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471851 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271852 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221853 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231854 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411855 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271856}
1857
[email protected]b172aee2012-04-10 17:05:261858void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271859 if (delegate_)
1860 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211861}
1862
[email protected]3a3b75a2012-06-01 08:38:361863void WebContentsImpl::OnRegisterIntentService(
1864 const webkit_glue::WebIntentServiceData& data,
1865 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431866 if (delegate_)
1867 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301868}
1869
[email protected]b172aee2012-04-10 17:05:261870void WebContentsImpl::OnWebIntentDispatch(
1871 const webkit_glue::WebIntentData& intent,
1872 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431873 if (!delegate_)
1874 return;
1875
[email protected]0d9989d2011-12-21 20:26:001876 WebIntentsDispatcherImpl* intents_dispatcher =
1877 new WebIntentsDispatcherImpl(this, intent, intent_id);
1878 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301879}
1880
[email protected]54047eb52012-05-08 21:45:571881void WebContentsImpl::DidStartProvisionalLoadForFrame(
1882 content::RenderViewHost* render_view_host,
1883 int64 frame_id,
1884 bool is_main_frame,
1885 const GURL& opener_url,
1886 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281887 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181888 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451889 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571890 content::RenderProcessHost* render_process_host =
1891 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541892 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571893 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451894 false,
[email protected]9f76c1e2012-03-05 15:15:581895 &validated_url);
[email protected]ef108e72012-06-20 14:03:541896 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571897 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451898 true,
1899 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181900
[email protected]0d60f0192011-04-14 12:40:101901 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251902 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101903 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571904 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541905
1906 if (is_main_frame) {
1907 // Notify observers about the provisional change in the main frame URL.
1908 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1909 ProvisionalChangeToMainFrameUrl(validated_url,
1910 validated_opener_url,
1911 render_view_host));
1912 }
1913}
1914
1915void WebContentsImpl::DidRedirectProvisionalLoad(
1916 content::RenderViewHost* render_view_host,
1917 int32 page_id,
1918 const GURL& opener_url,
1919 const GURL& source_url,
1920 const GURL& target_url) {
1921 // TODO(creis): Remove this method and have the pre-rendering code listen to
1922 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1923 // instead. See http://crbug.com/78512.
1924 GURL validated_source_url(source_url);
1925 GURL validated_target_url(target_url);
1926 GURL validated_opener_url(opener_url);
1927 content::RenderProcessHost* render_process_host =
1928 render_view_host->GetProcess();
1929 RenderViewHostImpl::FilterURL(
1930 ChildProcessSecurityPolicyImpl::GetInstance(),
1931 render_process_host->GetID(),
1932 false,
1933 &validated_source_url);
1934 RenderViewHostImpl::FilterURL(
1935 ChildProcessSecurityPolicyImpl::GetInstance(),
1936 render_process_host->GetID(),
1937 false,
1938 &validated_target_url);
1939 RenderViewHostImpl::FilterURL(
1940 ChildProcessSecurityPolicyImpl::GetInstance(),
1941 render_process_host->GetID(),
1942 true,
1943 &validated_opener_url);
1944 NavigationEntry* entry;
1945 if (page_id == -1) {
1946 entry = controller_.GetPendingEntry();
1947 } else {
1948 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1949 page_id);
1950 }
1951 if (!entry || entry->GetURL() != validated_source_url)
1952 return;
1953
1954 // Notify observers about the provisional change in the main frame URL.
1955 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1956 ProvisionalChangeToMainFrameUrl(validated_target_url,
1957 validated_opener_url,
1958 render_view_host));
[email protected]724159a2010-12-30 01:11:181959}
1960
[email protected]54047eb52012-05-08 21:45:571961void WebContentsImpl::DidFailProvisionalLoadWithError(
1962 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581963 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1964 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1965 << ", error_code: " << params.error_code
1966 << ", error_description: " << params.error_description
1967 << ", is_main_frame: " << params.is_main_frame
1968 << ", showing_repost_interstitial: " <<
1969 params.showing_repost_interstitial
1970 << ", frame_id: " << params.frame_id;
1971 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571972 content::RenderProcessHost* render_process_host =
1973 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541974 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571975 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451976 false,
[email protected]9f76c1e2012-03-05 15:15:581977 &validated_url);
[email protected]724159a2010-12-30 01:11:181978
[email protected]d7b175e2011-10-11 15:31:581979 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181980 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1981 // This means that the interstitial won't be torn down properly, which is
1982 // bad. But if we have an interstitial, go back to another tab type, and
1983 // then load the same interstitial again, we could end up getting the first
1984 // interstitial's "failed" message (as a result of the cancel) when we're on
1985 // the second one.
1986 //
1987 // We can't tell this apart, so we think we're tearing down the current page
1988 // which will cause a crash later one. There is also some code in
1989 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1990 // out because of this problem.
1991 //
1992 // http://code.google.com/p/chromium/issues/detail?id=2855
1993 // Because this will not tear down the interstitial properly, if "back" is
1994 // back to another tab type, the interstitial will still be somewhat alive
1995 // in the previous tab type. If you navigate somewhere that activates the
1996 // tab with the interstitial again, you'll see a flash before the new load
1997 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271998 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181999 LOG(WARNING) << "Discarding message during interstitial.";
2000 return;
2001 }
2002
[email protected]a16690732012-07-13 19:22:172003 // Do not clear the pending entry if one exists, so that the user's typed
2004 // URL is not lost when a navigation fails or is aborted. We'll allow
2005 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182006
[email protected]54047eb52012-05-08 21:45:572007 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182008 }
2009
[email protected]d8c660432011-12-22 20:51:252010 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582011 observers_,
2012 DidFailProvisionalLoad(params.frame_id,
2013 params.is_main_frame,
2014 validated_url,
2015 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462016 params.error_description,
2017 render_view_host));
[email protected]724159a2010-12-30 01:11:182018}
2019
[email protected]b172aee2012-04-10 17:05:262020void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182021 const GURL& url,
[email protected]70435962011-08-02 20:13:282022 const std::string& security_info,
2023 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182024 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282025 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192026 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182027 cache.Increment();
2028
2029 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082030 int cert_id = 0;
2031 net::CertStatus cert_status = 0;
2032 int security_bits = -1;
2033 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512034 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2035 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002036 content::LoadFromMemoryCacheDetails details(
2037 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2038 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182039
[email protected]ad50def52011-10-19 23:17:072040 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272041 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502042 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002043 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182044}
2045
[email protected]b172aee2012-04-10 17:05:262046void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382047 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182048 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192049 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182050}
2051
[email protected]b172aee2012-04-10 17:05:262052void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022053 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232054 LOG(INFO) << security_origin << " ran insecure content from "
2055 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382056 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412057 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2058 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182059 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412060 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192061 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182062}
2063
[email protected]b172aee2012-04-10 17:05:262064void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182065 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252066 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472067 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182068}
2069
[email protected]b172aee2012-04-10 17:05:262070void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312071 int64 frame_id,
2072 const GURL& validated_url,
2073 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252074 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472075 DidFinishLoad(frame_id, validated_url, is_main_frame,
2076 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312077}
2078
[email protected]b172aee2012-04-10 17:05:262079void WebContentsImpl::OnDidFailLoadWithError(
2080 int64 frame_id,
2081 const GURL& validated_url,
2082 bool is_main_frame,
2083 int error_code,
2084 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252085 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312086 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472087 error_code, error_description,
2088 message_source_));
[email protected]724159a2010-12-30 01:11:182089}
2090
[email protected]b172aee2012-04-10 17:05:262091void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272092 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432093 if (delegate_)
2094 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172095}
2096
[email protected]b172aee2012-04-10 17:05:262097void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262098 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232099 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252100 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262101 if (!entry)
2102 return;
2103 // Note that we don't call NavigationController::GotToOffset() as we don't
2104 // want to create a pending navigation entry (it might end up lingering
2105 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252106 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582107 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512108 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582109 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472110 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572111
2112 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2113 // it in now that we know. This allows us to find the entry when it commits.
2114 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232115 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332116 entry->set_site_instance(
2117 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572118 }
[email protected]216813952011-05-19 22:21:262119 }
2120}
2121
[email protected]b172aee2012-04-10 17:05:262122void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2123 int maximum_percent,
2124 bool remember) {
[email protected]216813952011-05-19 22:21:262125 minimum_zoom_percent_ = minimum_percent;
2126 maximum_zoom_percent_ = maximum_percent;
2127 temporary_zoom_settings_ = !remember;
2128}
2129
[email protected]20b433a2012-05-15 21:23:462130void WebContentsImpl::OnSaveURL(const GURL& url,
2131 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482132 download_stats::RecordDownloadSource(
2133 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262134 // Check if the URL to save matches the URL of the main frame. Since this
2135 // message originates from Pepper plugins, it may not be the case if the
2136 // plugin is an embedded element.
2137 GURL main_frame_url = GetURL();
2138 if (!main_frame_url.is_valid())
2139 return;
2140 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462141 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272142}
2143
[email protected]b172aee2012-04-10 17:05:262144void WebContentsImpl::OnEnumerateDirectory(int request_id,
2145 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432146 if (!delegate_)
2147 return;
2148
[email protected]b9535422012-02-09 01:47:592149 ChildProcessSecurityPolicyImpl* policy =
2150 ChildProcessSecurityPolicyImpl::GetInstance();
2151 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2152 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212153}
2154
[email protected]b172aee2012-04-10 17:05:262155void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432156 if (delegate_)
2157 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202158}
2159
[email protected]b172aee2012-04-10 17:05:262160void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2161 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362162 const string16& title,
2163 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432164 if (!delegate_)
2165 return;
2166
[email protected]b9535422012-02-09 01:47:592167 ChildProcessSecurityPolicyImpl* policy =
2168 ChildProcessSecurityPolicyImpl::GetInstance();
2169 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2170 return;
[email protected]3a3b75a2012-06-01 08:38:362171 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202172}
2173
[email protected]b172aee2012-04-10 17:05:262174void WebContentsImpl::OnFindReply(int request_id,
2175 int number_of_matches,
2176 const gfx::Rect& selection_rect,
2177 int active_match_ordinal,
2178 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432179 if (delegate_) {
2180 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2181 active_match_ordinal, final_update);
2182 }
[email protected]b888919c2011-09-02 00:32:162183}
2184
[email protected]b172aee2012-04-10 17:05:262185void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442186 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2187 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2191 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102192 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252193 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102194 AppCacheAccessed(manifest_url, blocked_by_policy));
2195}
2196
[email protected]b172aee2012-04-10 17:05:262197void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322198 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432199 color_chooser_ = delegate_ ?
2200 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202204 if (color_chooser_ &&
2205 color_chooser_id == color_chooser_->identifier())
2206 color_chooser_->End();
2207}
2208
[email protected]b172aee2012-04-10 17:05:262209void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322210 SkColor color) {
[email protected]da8543762012-03-20 08:52:202211 if (color_chooser_ &&
2212 color_chooser_id == color_chooser_->identifier())
2213 color_chooser_->SetSelectedColor(color);
2214}
2215
[email protected]9f2a9d72012-04-16 16:02:222216void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2217 const FilePath& path,
2218 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442219 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2220 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292221}
2222
[email protected]d0759f492012-04-19 22:50:502223// This exists for render views that don't have a WebUI, but do have WebUI
2224// bindings enabled.
2225void WebContentsImpl::OnWebUISend(const GURL& source_url,
2226 const std::string& name,
2227 const base::ListValue& args) {
2228 if (delegate_)
2229 delegate_->WebUISend(this, source_url, name, args);
2230}
2231
[email protected]96d185d2009-04-24 03:28:542232// Notifies the RenderWidgetHost instance about the fact that the page is
2233// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262234void WebContentsImpl::SetIsLoading(bool is_loading,
2235 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542236 if (is_loading == is_loading_)
2237 return;
2238
2239 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212240 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542241 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562242 upload_size_ = 0;
2243 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542244 }
2245
2246 render_manager_.SetIsLoading(is_loading);
2247
2248 is_loading_ = is_loading;
2249 waiting_for_response_ = is_loading;
2250
[email protected]6ebdc9b2010-09-27 16:55:572251 if (delegate_)
2252 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462253 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542254
[email protected]432115822011-07-10 15:52:272255 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2256 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072257 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542258 if (details)
[email protected]6c2381d2011-10-19 02:52:532259 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072260 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502261 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542262 det);
2263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132266 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322267 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562268 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382269 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442270 // that opened the window, as long as both renderers have the same
2271 // privileges.
[email protected]1fd1a502011-03-30 16:55:562272 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562273 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582274 // web_ui might be NULL if the URL refers to a non-existent extension.
2275 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402276 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522277 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442278 }
2279 }
[email protected]1fd1a502011-03-30 16:55:562280 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442281 }
2282
[email protected]4e697b042011-07-08 06:44:562283 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322284 // Clear the status bubble. This is a workaround for a bug where WebKit
2285 // doesn't let us know that the cursor left an element during a
2286 // transition (this is also why the mouse cursor remains as a hand after
2287 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2288 // clear the bubble when a user navigates to a named anchor in the same
2289 // page.
[email protected]36fc0392011-12-25 03:59:512290 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322291 }
2292
[email protected]a6e82fc2010-02-24 22:28:142293 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472294 // Once the main frame is navigated, we're no longer considered to have
2295 // displayed insecure content.
2296 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172297 }
[email protected]ce5c4502009-05-06 16:46:112298
[email protected]3c9e1872010-11-18 16:17:492299 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252300 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042301 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322302}
2303
[email protected]b172aee2012-04-10 17:05:262304void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322305 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132306 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322307 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062308 // If we navigate off the page, reset JavaScript state. This does nothing
2309 // to prevent a malicious script from spamming messages, since the script
2310 // could just reload the page to stop blocking.
2311 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552312 dialog_creator_->ResetJavaScriptState(this);
2313 dialog_creator_ = NULL;
2314 }
[email protected]420ae012009-04-24 05:16:322315
[email protected]3c9e1872010-11-18 16:17:492316 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252317 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042318 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322319}
2320
[email protected]b172aee2012-04-10 17:05:262321void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462322 // If we are creating a RVH for a restored controller, then we need to make
2323 // sure the RenderView starts with a next_page_id_ larger than the number
2324 // of restored entries. This must be called before the RenderView starts
2325 // navigating (to avoid a race between the browser updating max_page_id and
2326 // the renderer updating next_page_id_). Because of this, we only call this
2327 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562328 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582329 if (max_restored_page_id >
2330 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2331 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2332 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322333}
2334
[email protected]b172aee2012-04-10 17:05:262335bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2336 const string16& title) {
[email protected]420ae012009-04-24 05:16:322337 // For file URLs without a title, use the pathname instead. In the case of a
2338 // synthesized title, we don't want the update to count toward the "one set
2339 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512340 string16 final_title;
[email protected]420ae012009-04-24 05:16:322341 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512342 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2343 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322344 explicit_set = false; // Don't count synthetic titles toward the set limit.
2345 } else {
[email protected]acafd272011-07-26 17:35:572346 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322347 explicit_set = true;
2348 }
2349
[email protected]987fc3a2011-05-26 14:18:092350 // If a page is created via window.open and never navigated,
2351 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552352 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092353 if (entry) {
[email protected]36fc0392011-12-25 03:59:512354 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092355 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322356
[email protected]36fc0392011-12-25 03:59:512357 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092358 } else {
2359 if (page_title_when_no_navigation_entry_ == final_title)
2360 return false; // Nothing changed, don't bother.
2361
2362 page_title_when_no_navigation_entry_ = final_title;
2363 }
[email protected]420ae012009-04-24 05:16:322364
[email protected]420ae012009-04-24 05:16:322365 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232366 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322367
[email protected]2bb171882012-03-07 02:09:462368 std::pair<content::NavigationEntry*, bool> details =
2369 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142370
[email protected]ad50def52011-10-19 23:17:072371 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442372 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2373 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462374 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042375
[email protected]420ae012009-04-24 05:16:322376 return true;
2377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322380 // After sending out a swap notification, we need to send a disconnect
2381 // notification so that clients that pick up a pointer to |this| can NULL the
2382 // pointer. See Bug 1230284.
2383 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072384 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202385 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2386 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072387 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322391 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072392 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122393 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2394 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072395 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322396}
2397
[email protected]b172aee2012-04-10 17:05:262398void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322399 if (!notify_disconnection_)
2400 return;
2401
2402 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072403 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322404 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2405 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072406 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322407}
2408
[email protected]5a3bdf52012-05-24 15:12:572409RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2410 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322411}
2412
[email protected]8d3347f2009-07-09 22:00:212413RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262414WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212415 return &render_manager_;
2416}
2417
[email protected]b172aee2012-04-10 17:05:262418content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372419 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462420 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512421}
2422
[email protected]b172aee2012-04-10 17:05:262423WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172424 return this;
2425}
2426
[email protected]b172aee2012-04-10 17:05:262427gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172428 if (delegate_)
2429 return delegate_->GetRootWindowResizerRect();
2430 return gfx::Rect();
2431}
2432
[email protected]b172aee2012-04-10 17:05:262433void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442434 // Don't send notifications if we are just creating a swapped-out RVH for
2435 // the opener chain. These won't be used for view-source or WebUI, so it's
2436 // ok to return early.
2437 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2438 return;
2439
[email protected]ad50def52011-10-19 23:17:072440 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302441 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322442 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532443 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232444 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322445 if (!entry)
2446 return;
2447
2448 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352449 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562450 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582451 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322452
2453 if (entry->IsViewSourceMode()) {
2454 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582455 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2456 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322457 }
[email protected]0666aef2009-05-13 19:48:082458
[email protected]d487beefe2011-12-21 05:41:212459 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262460
2461 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252462 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322463}
2464
[email protected]b172aee2012-04-10 17:05:262465void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522466 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322467 // Don't notify the world, since this came from a renderer in the
2468 // background.
2469 return;
2470 }
2471
2472 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312473 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232474 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302475
2476 // Restore the focus to the tab (otherwise the focus will be on the top
2477 // window).
[email protected]484ae5912010-09-29 19:16:142478 if (was_crashed && !FocusLocationBarByDefault() &&
2479 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302480 Focus();
[email protected]484ae5912010-09-29 19:16:142481 }
[email protected]32ded2212011-11-10 18:51:432482
[email protected]d8c660432011-12-22 20:51:252483 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322484}
2485
[email protected]b172aee2012-04-10 17:05:262486void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2487 base::TerminationStatus status,
2488 int error_code) {
[email protected]151a63d2011-12-20 22:32:522489 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322490 // The pending page's RenderViewHost is gone.
2491 return;
2492 }
2493
2494 SetIsLoading(false, NULL);
2495 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232496 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312497 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322498
[email protected]d8c660432011-12-22 20:51:252499 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272500 observers_,
[email protected]be1f56ab2011-12-22 06:55:312501 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322502}
2503
[email protected]b172aee2012-04-10 17:05:262504void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482505 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252506 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062507}
2508
[email protected]b172aee2012-04-10 17:05:262509void WebContentsImpl::DidNavigate(
2510 RenderViewHost* rvh,
2511 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582512 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322513 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372514
[email protected]434f69f2012-02-06 21:56:522515 // Update the site of the SiteInstance if it doesn't have one yet, unless
2516 // this is for about:blank. In that case, the SiteInstance can still be
2517 // considered unused until a navigation to a real page.
2518 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2519 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332520 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522521 }
[email protected]420ae012009-04-24 05:16:322522
2523 // Need to update MIME type here because it's referred to in
2524 // UpdateNavigationCommands() called by RendererDidNavigate() to
2525 // determine whether or not to enable the encoding menu.
2526 // It's updated only for the main frame. For a subframe,
2527 // RenderView::UpdateURL does not set params.contents_mime_type.
2528 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2529 // TODO(jungshik): Add a test for the encoding menu to avoid
2530 // regressing it again.
[email protected]2905f742011-10-13 03:51:582531 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322532 contents_mime_type_ = params.contents_mime_type;
2533
[email protected]8286f51a2011-05-31 17:39:132534 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002535 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392536
[email protected]a9c0bfe2010-09-17 08:35:222537 // Send notification about committed provisional loads. This notification is
2538 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2539 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082540 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072541 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2542 // that is not recorded in the navigation history. For the purpose of
2543 // tracking navigation events, we treat this event as a sub frame navigation
2544 // event.
2545 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582546 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222547 // Whether or not a page transition was triggered by going backward or
2548 // forward in the history is only stored in the navigation controller's
2549 // entry list.
2550 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512551 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582552 content::PAGE_TRANSITION_FORWARD_BACK)) {
2553 transition_type = content::PageTransitionFromInt(
2554 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222555 }
[email protected]0d60f0192011-04-14 12:40:102556 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252557 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102558 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462559 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222560 }
2561
[email protected]76543b92009-08-31 17:27:452562 if (!did_navigate)
2563 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322564
2565 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2566 // for the appropriate notification (best) or you can add it to
2567 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2568 // necessary, please).
2569
2570 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002571 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322572 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512573 if (delegate_)
2574 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002575 }
[email protected]420ae012009-04-24 05:16:322576 DidNavigateAnyFramePostCommit(rvh, details, params);
2577}
2578
[email protected]b172aee2012-04-10 17:05:262579void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2580 int32 page_id,
2581 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152582 // Ensure that this state update comes from either the active RVH or one of
2583 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522584 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322585
2586 // We must be prepared to handle state updates for any page, these occur
2587 // when the user is scrolling and entering form data, as well as when we're
2588 // leaving a page, in which case our state may have already been moved to
2589 // the next page. The navigation controller will look up the appropriate
2590 // NavigationEntry and update it when it is notified via the delegate.
2591
2592 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582593 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322594 if (entry_index < 0)
2595 return;
[email protected]10f417c52011-12-28 21:04:232596 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322597
[email protected]36fc0392011-12-25 03:59:512598 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322599 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512600 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322601 controller_.NotifyEntryChanged(entry, entry_index);
2602}
2603
[email protected]b172aee2012-04-10 17:05:262604void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2605 int32 page_id,
2606 const string16& title,
2607 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322608 // If we have a title, that's a pretty good indication that we've started
2609 // getting useful data.
2610 SetNotWaitingForResponse();
2611
[email protected]73eb2602012-02-09 19:50:552612 // Try to find the navigation entry, which might not be the current one.
2613 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232614 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582615 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092616
[email protected]73eb2602012-02-09 19:50:552617 // We can handle title updates when we don't have an entry in
2618 // UpdateTitleForEntry, but only if the update is from the current RVH.
2619 if (!entry && rvh != GetRenderViewHost())
2620 return;
2621
[email protected]a49e10b2011-08-01 23:57:462622 // TODO(evan): make use of title_direction.
2623 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092624 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322625 return;
2626
2627 // Broadcast notifications when the UI should be updated.
2628 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462629 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]b172aee2012-04-10 17:05:262632void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2633 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312634 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322635}
2636
[email protected]b172aee2012-04-10 17:05:262637void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512638 if (delegate_)
2639 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322640}
2641
[email protected]b172aee2012-04-10 17:05:262642void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292643 // The UI may be in an event-tracking loop, such as between the
2644 // mouse-down and mouse-up in text selection or a button click.
2645 // Defer the close until after tracking is complete, so that we
2646 // don't free objects out from under the UI.
2647 // TODO(shess): This could probably be integrated with the
2648 // IsDoingDrag() test below. Punting for now because I need more
2649 // research to understand how this impacts platforms other than Mac.
2650 // TODO(shess): This could get more fine-grained. For instance,
2651 // closing a tab in another window while selecting text in the
2652 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212653 if (GetView()->IsEventTracking()) {
2654 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292655 return;
2656 }
2657
[email protected]24a4d1062009-07-10 23:10:422658 // If we close the tab while we're in the middle of a drag, we'll crash.
2659 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212660 if (GetView()->IsDoingDrag()) {
2661 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422662 return;
2663 }
2664
[email protected]420ae012009-04-24 05:16:322665 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522666 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512667 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322668}
2669
[email protected]b172aee2012-04-10 17:05:262670void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522671 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512672 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572673}
2674
[email protected]b172aee2012-04-10 17:05:262675void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512676 if (delegate_ && delegate_->IsPopupOrPanel(this))
2677 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322678}
2679
[email protected]89793072012-07-23 22:25:292680void WebContentsImpl::DidStartLoading(
2681 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322682 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492683
[email protected]82114f52012-03-20 22:53:412684 if (delegate_ && content_restrictions_)
2685 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492686
2687 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292688 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2689 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322690}
2691
[email protected]89793072012-07-23 22:25:292692void WebContentsImpl::DidStopLoading(
2693 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322694 scoped_ptr<LoadNotificationDetails> details;
2695
[email protected]10f417c52011-12-28 21:04:232696 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322697 // An entry may not exist for a stop when loading an initial blank page or
2698 // if an iframe injected by script into a blank page finishes loading.
2699 if (entry) {
[email protected]420ae012009-04-24 05:16:322700 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2701
2702 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512703 entry->GetVirtualURL(),
2704 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322705 elapsed,
2706 &controller_,
2707 controller_.GetCurrentEntryIndex()));
2708 }
2709
[email protected]420ae012009-04-24 05:16:322710 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492711
2712 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292713 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2714 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322715}
2716
[email protected]b172aee2012-04-10 17:05:262717void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162718 controller_.DiscardNonCommittedEntries();
2719
2720 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462721 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162722}
2723
[email protected]b172aee2012-04-10 17:05:262724void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512725 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132726 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402727}
2728
[email protected]87717d0e2012-04-26 02:58:432729void WebContentsImpl::DocumentAvailableInMainFrame(
2730 RenderViewHost* render_view_host) {
2731 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2732 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102733}
2734
[email protected]b172aee2012-04-10 17:05:262735void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082736 RenderViewHost* render_view_host,
2737 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072738 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272739 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322740 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532741 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082742}
2743
[email protected]196159d2012-05-04 17:26:542744void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2745 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262746 const content::Referrer& referrer,
2747 WindowOpenDisposition disposition,
2748 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542749 // If this came from a swapped out RenderViewHost, we only allow the request
2750 // if we are still in the same BrowsingInstance.
2751 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2752 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2753 return;
2754 }
2755
[email protected]4ad5d77d2011-12-03 02:00:482756 // Delegate to RequestTransferURL because this is just the generic
2757 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582758 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482759 GlobalRequestID());
2760}
2761
[email protected]b172aee2012-04-10 17:05:262762void WebContentsImpl::RequestTransferURL(
2763 const GURL& url,
2764 const content::Referrer& referrer,
2765 WindowOpenDisposition disposition,
2766 int64 source_frame_id,
2767 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202768 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582769 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582770 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352771 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322772 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2773 // generated suggestions).
2774 //
[email protected]e0112912011-02-02 22:54:352775 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162776 // want web sites to see a referrer of "chrome://blah" (and some
2777 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322778 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432779 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222780 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482781 false /* is_renderer_initiated */);
2782 params.transferred_global_request_id = old_request_id;
2783 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222784 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322785 } else {
[email protected]6bf6a6b52012-02-03 15:41:432786 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482787 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2788 params.transferred_global_request_id = old_request_id;
2789 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582790 }
2791 if (new_contents) {
2792 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252793 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582794 DidOpenRequestedURL(new_contents,
2795 url,
2796 referrer,
2797 disposition,
2798 transition_type,
2799 source_frame_id));
[email protected]420ae012009-04-24 05:16:322800 }
2801}
2802
[email protected]e1c3a552012-05-04 20:51:322803void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2804 // Tell the active RenderViewHost to run unload handlers and close, as long
2805 // as the request came from a RenderViewHost in the same BrowsingInstance.
2806 // In most cases, we receive this from a swapped out RenderViewHost.
2807 // It is possible to receive it from one that has just been swapped in,
2808 // in which case we might as well deliver the message anyway.
2809 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2810 GetRenderViewHost()->ClosePage();
2811}
2812
[email protected]f546640b2012-05-15 00:03:492813void WebContentsImpl::RouteMessageEvent(
2814 RenderViewHost* rvh,
2815 const ViewMsg_PostMessage_Params& params) {
2816 // Only deliver the message to the active RenderViewHost if the request
2817 // came from a RenderViewHost in the same BrowsingInstance.
2818 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2819 return;
2820
2821 ViewMsg_PostMessage_Params new_params(params);
2822
2823 // If there is a source_routing_id, translate it to the routing ID for
2824 // the equivalent swapped out RVH in the target process. If we need
2825 // to create a swapped out RVH for the source tab, we create its opener
2826 // chain as well, since those will also be accessible to the target page.
2827 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2828 // Try to look up the WebContents for the source page.
2829 WebContentsImpl* source_contents = NULL;
2830 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2831 rvh->GetProcess()->GetID(), params.source_routing_id);
2832 if (source_rvh) {
2833 source_contents = static_cast<WebContentsImpl*>(
2834 source_rvh->GetDelegate()->GetAsWebContents());
2835 }
2836
2837 if (source_contents) {
2838 new_params.source_routing_id =
2839 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2840 } else {
2841 // We couldn't find it, so don't pass a source frame.
2842 new_params.source_routing_id = MSG_ROUTING_NONE;
2843 }
2844 }
2845
2846 // In most cases, we receive this from a swapped out RenderViewHost.
2847 // It is possible to receive it from one that has just been swapped in,
2848 // in which case we might as well deliver the message anyway.
2849 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2850 GetRenderViewHost()->GetRoutingID(), new_params));
2851}
2852
[email protected]b172aee2012-04-10 17:05:262853void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342854 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412855 const string16& message,
2856 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322857 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142858 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322859 IPC::Message* reply_msg,
2860 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072861 // Suppress JavaScript dialogs when requested. Also suppress messages when
2862 // showing an interstitial as it's shown over the previous page and we don't
2863 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502864 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582865 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272866 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072867 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522868 delegate_->ShouldSuppressDialogs() ||
2869 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322870
2871 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432872 std::string accept_lang = content::GetContentClient()->browser()->
2873 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552874 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522875 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432876 this,
2877 frame_url.GetOrigin(),
2878 accept_lang,
2879 javascript_message_type,
2880 message,
[email protected]51da7e32012-01-30 19:24:522881 default_prompt,
[email protected]b172aee2012-04-10 17:05:262882 base::Bind(&WebContentsImpl::OnDialogClosed,
2883 base::Unretained(this),
2884 rvh,
2885 reply_msg),
[email protected]51da7e32012-01-30 19:24:522886 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322887 }
[email protected]3ab9cb82011-06-03 18:02:072888
2889 if (suppress_this_message) {
2890 // If we are suppressing messages, just reply as if the user immediately
2891 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342892 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072893 }
2894
2895 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322896}
2897
[email protected]b172aee2012-04-10 17:05:262898void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2899 const string16& message,
2900 bool is_reload,
2901 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582902 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512903 if (delegate_)
2904 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072905
2906 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582907 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072908 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522909 delegate_->ShouldSuppressDialogs() ||
2910 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152911 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342912 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582913 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502914 return;
2915 }
[email protected]3ab9cb82011-06-03 18:02:072916
[email protected]7ab1e7d62009-10-14 23:32:012917 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552918 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522919 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322920 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262921 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522922 reply_msg));
[email protected]420ae012009-04-24 05:16:322923}
2924
[email protected]a796f202012-05-30 14:14:252925bool WebContentsImpl::AddMessageToConsole(int32 level,
2926 const string16& message,
2927 int32 line_no,
2928 const string16& source_id) {
2929 if (!delegate_)
2930 return false;
2931 return delegate_->AddMessageToConsole(this, level, message, line_no,
2932 source_id);
2933}
2934
[email protected]b172aee2012-04-10 17:05:262935WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332936 // We want to base the page config off of the real URL, rather than the
2937 // display URL.
2938 GURL url = controller_.GetActiveEntry()
2939 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2940 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322941}
2942
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272944 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252945 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222946
[email protected]ea114722012-03-12 01:11:252947 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172948 if (rdh) // NULL in unittests.
2949 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252950}
2951
[email protected]b172aee2012-04-10 17:05:262952void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442953 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252954 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442955}
2956
[email protected]b172aee2012-04-10 17:05:262957void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2958 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152959 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522960 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152961 return;
2962
[email protected]9f76c1e2012-03-05 15:15:582963 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2964
[email protected]e5fc1632011-08-08 07:51:532965 // Ignore renderer unresponsive event if debugger is attached to the tab
2966 // since the event may be a result of the renderer sitting on a breakpoint.
2967 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442968 DevToolsAgentHost* agent =
2969 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2970 if (agent &&
2971 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532972 return;
2973
[email protected]420ae012009-04-24 05:16:322974 if (is_during_unload) {
2975 // Hang occurred while firing the beforeunload/unload handler.
2976 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582977 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322978
2979 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2980 return;
2981
2982 // If the tab hangs in the beforeunload/unload handler there's really
2983 // nothing we can do to recover. Pretend the unload listeners have
2984 // all fired and close the tab. If the hang is in the beforeunload handler
2985 // then the user will not have the option of cancelling the close.
2986 Close(rvh);
2987 return;
2988 }
2989
[email protected]9f76c1e2012-03-05 15:15:582990 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472991 return;
2992
[email protected]6934a702011-12-20 00:04:512993 if (delegate_)
2994 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322995}
2996
[email protected]b172aee2012-04-10 17:05:262997void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512998 if (delegate_)
2999 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323000}
3001
[email protected]b172aee2012-04-10 17:05:263002void WebContentsImpl::LoadStateChanged(
3003 const GURL& url,
3004 const net::LoadStateWithParam& load_state,
3005 uint64 upload_position,
3006 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323007 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563008 upload_position_ = upload_position;
3009 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503010 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203011 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303012 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213013 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323014 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463015 if (IsLoading()) {
3016 NotifyNavigationStateChanged(
3017 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3018 }
[email protected]420ae012009-04-24 05:16:323019}
3020
[email protected]b172aee2012-04-10 17:05:263021void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513022 if (delegate_)
3023 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253024}
3025
[email protected]b172aee2012-04-10 17:05:263026void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323027 bool proceed,
3028 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513029 if (delegate_)
3030 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323031}
3032
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543034 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233035 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3036 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543037}
3038
[email protected]b172aee2012-04-10 17:05:263039void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103040 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263041 gfx::Size size = view_->GetContainerSize();
3042 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3043 // here during container initialization and normal window size will be set
3044 // later. In case of tab duplication this resizing to 0x0 prevents setting
3045 // normal size later so just ignore it.
3046 if (!size.IsEmpty())
3047 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323048}
3049
[email protected]b172aee2012-04-10 17:05:263050void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543051 NotifySwapped();
3052}
3053
[email protected]14392a52012-05-02 20:28:443054int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3055 SiteInstance* instance) {
3056 if (!opener_)
3057 return MSG_ROUTING_NONE;
3058
3059 // Recursively create RenderViews for anything else in the opener chain.
3060 return opener_->CreateOpenerRenderViews(instance);
3061}
3062
3063int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3064 int opener_route_id = MSG_ROUTING_NONE;
3065
3066 // If this tab has an opener, ensure it has a RenderView in the given
3067 // SiteInstance as well.
3068 if (opener_)
3069 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3070
3071 // Create a swapped out RenderView in the given SiteInstance if none exists,
3072 // setting its opener to the given route_id. Return the new view's route_id.
3073 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3074}
3075
[email protected]b172aee2012-04-10 17:05:263076NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193077 return GetController();
[email protected]3a3d47472010-07-15 21:03:543078}
3079
[email protected]b172aee2012-04-10 17:05:263080WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563081 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323082}
3083
[email protected]10f417c52011-12-28 21:04:233084NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263085 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323086 return controller_.GetLastCommittedEntry();
3087}
3088
[email protected]b172aee2012-04-10 17:05:263089bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443090 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443091 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323092 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523093
[email protected]420ae012009-04-24 05:16:323094 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443095 if (rwh_view)
3096 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323097
[email protected]74ce1ad2011-12-16 21:51:463098 // Make sure we use the correct starting page_id in the new RenderView.
3099 UpdateMaxPageIDIfNecessary(render_view_host);
3100 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583101 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463102
[email protected]7900bfdb2012-05-24 19:31:243103 std::string embedder_channel_name;
3104 int embedder_container_id;
3105 GetBrowserPluginEmbedderInfo(render_view_host,
3106 &embedder_channel_name,
3107 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583108 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493109 render_view_host)->CreateRenderView(string16(),
3110 opener_route_id,
3111 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243112 embedder_channel_name,
3113 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523114 return false;
[email protected]14392a52012-05-02 20:28:443115 }
[email protected]a4127722011-04-27 23:13:523116
[email protected]e60c0232011-11-11 19:56:353117#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503118 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3119 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443120 if (rwh_view) {
3121 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3122 render_widget_host->WasResized();
3123 }
[email protected]f8233cc2011-05-31 20:24:503124#endif
3125
[email protected]420ae012009-04-24 05:16:323126 return true;
3127}
3128
[email protected]b172aee2012-04-10 17:05:263129void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3130 IPC::Message* reply_msg,
3131 bool success,
3132 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543133 if (is_showing_before_unload_dialog_ && !success) {
3134 // If a beforeunload dialog is canceled, we need to stop the throbber from
3135 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293136 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353137 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543138
[email protected]3bbacc5b2012-04-17 17:46:153139 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543140 }
3141 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583142 static_cast<RenderViewHostImpl*>(
3143 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543144}
3145
[email protected]b172aee2012-04-10 17:05:263146void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123147 encoding_ = content::GetContentClient()->browser()->
3148 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103149}
[email protected]f45d2a72010-03-08 23:28:353150
[email protected]b172aee2012-04-10 17:05:263151void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463152 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263153 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573154 DownloadManager* dlm =
3155 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143156 if (!dlm)
3157 return;
3158 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263159 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143160 const NavigationEntry* entry = controller_.GetActiveEntry();
3161 if (entry)
3162 post_id = entry->GetPostID();
3163 }
[email protected]29a5ffc82012-03-13 19:35:583164 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143165 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143166 scoped_ptr<DownloadUrlParameters> params(
3167 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493168 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143169 params->set_post_id(post_id);
3170 params->set_prefer_cache(true);
3171 if (post_id >= 0)
3172 params->set_method("POST");
3173 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143174}
3175
[email protected]b172aee2012-04-10 17:05:263176void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213177 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443178 // Can be NULL during tests.
3179 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213180 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363181}
[email protected]9f76c1e2012-03-05 15:15:583182
[email protected]b172aee2012-04-10 17:05:263183RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583184 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3185}
[email protected]7900bfdb2012-05-24 19:31:243186
3187void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3188 content::RenderViewHost* render_view_host,
3189 std::string* embedder_channel_name,
3190 int* embedder_container_id) {
3191 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283192 old_browser_plugin_host()->embedder_render_process_host();
3193 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243194 int embedder_process_id =
3195 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3196 if (embedder_process_id != -1) {
3197 *embedder_channel_name =
3198 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3199 embedder_process_id);
3200 }
3201}