blob: e6c8b6cdde374cd5ce922769f0341bed2bebc697 [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]7a846df2012-09-20 19:17:3918#include "content/browser/browser_plugin/browser_plugin_embedder.h"
19#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]cc510d7e2012-08-08 04:40:1020#include "content/browser/browser_plugin/old/old_browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5921#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4422#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1923#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0424#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4625#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1226#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1627#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3228#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5429#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0530#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0031#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3032#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3233#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5034#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2535#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3336#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3737#include "content/browser/web_contents/interstitial_page_impl.h"
38#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5639#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3940#include "content/common/browser_plugin_messages.h"
[email protected]ce9751942011-09-21 01:57:2441#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5142#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0243#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5744#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5845#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1146#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2047#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4448#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4449#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1750#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1451#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4652#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1553#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0054#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2755#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0056#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3757#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1458#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3259#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3460#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3861#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4262#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2563#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1064#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5065#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2166#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4867#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1868#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5469#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0370#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1671#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2972#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5473#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3474#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3775#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5676#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1677#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4178#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0179#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5281#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2482#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3683#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3184#include "webkit/glue/webpreferences.h"
85
[email protected]f66df822012-05-18 16:52:1786#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5087#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4188#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5789#endif
[email protected]3e45ba92009-02-20 21:09:0090
[email protected]c71fe6402012-08-15 15:22:5591#if defined(USE_AURA) && defined(USE_X11)
92#include "ui/base/touch/touch_factory.h"
93#endif // defined (USE_AURA) && defined(USE_X11)
94
[email protected]420ae012009-04-24 05:16:3295// Cross-Site Navigations
96//
[email protected]b172aee2012-04-10 17:05:2697// If a WebContentsImpl is told to navigate to a different web site (as
98// determined by SiteInstance), it will replace its current RenderViewHost with
99// a new RenderViewHost dedicated to the new SiteInstance. This works as
100// follows:
[email protected]420ae012009-04-24 05:16:32101//
102// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46103// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32104// - The pending RVH is "suspended," so that no navigation messages are sent to
105// its renderer until the onbeforeunload JavaScript handler has a chance to
106// run in the current RVH.
107// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
108// that it has a pending cross-site request. ResourceDispatcherHost will
109// check for this when the response arrives.
110// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46111// cancel all the pending logic. Otherwise we allow the pending RVH to send
112// the navigation request to its renderer.
113// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
114// main resource load on the pending RVH. It checks CrossSiteRequestManager
115// to see that it is a cross-site request, and installs a
116// CrossSiteResourceHandler.
117// - When RDH receives a response, the BufferedResourceHandler determines
118// whether it is a download. If so, it sends a message to the new renderer
119// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26120// pending RVH remains until the next DidNavigate event for this
121// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32122// - After RDH receives a response and determines that it is safe and not a
123// download, it pauses the response to first run the old page's onunload
124// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26125// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32126// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15127// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32128// the ResourceDispatcherHost, who unpauses the response. Data is then sent
129// to the pending RVH.
130// - The pending renderer sends a FrameNavigate message that invokes the
131// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46132// pending RVH.
[email protected]992db4c2011-05-12 15:37:15133// - The previous renderer is kept swapped out in RenderViewHostManager in case
134// the user goes back. The process only stays live if another tab is using
135// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32136
[email protected]b441a8492012-06-06 14:55:57137using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44138using content::DevToolsAgentHost;
139using content::DevToolsAgentHostRegistry;
140using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17141using content::DownloadItem;
142using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14143using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20144using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56145using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13146using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27147using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54148using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50149using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23150using content::NavigationEntry;
151using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20152using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11153using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57154using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57155using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27156using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11157using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50158using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58159using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04160using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25161using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14162using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43163using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33164using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38165using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09166using content::WebContents;
[email protected]eda238a12012-09-07 23:44:00167using content::WebContentsDelegate;
[email protected]d8c660432011-12-22 20:51:25168using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56169using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22170using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50171using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25172using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44173
[email protected]420ae012009-04-24 05:16:32174namespace {
175
176// Amount of time we wait between when a key event is received and the renderer
177// is queried for its state and pushed to the NavigationEntry.
178const int kQueryStateDelay = 5000;
179
[email protected]6ebdc9b2010-09-27 16:55:57180const int kSyncWaitDelay = 40;
181
[email protected]82114f52012-03-20 22:53:41182const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05183
[email protected]420ae012009-04-24 05:16:32184#if defined(OS_WIN)
185
186BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
187 // Note: erase is required to properly paint some widgets borders. This can
188 // be seen with textfields.
189 InvalidateRect(hwnd, NULL, TRUE);
190 return TRUE;
191}
192#endif
193
[email protected]2c5569662011-03-22 20:45:02194ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23195 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50196 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16197 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47198 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02199 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47200 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23202 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
203 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47204 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16205 break; // Fall through to rest of function.
206 }
[email protected]5e369672009-11-03 23:48:30207
[email protected]59246c572012-02-10 13:32:13208 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
209 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23210 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13211 browser_context->DidLastSessionExitCleanly()) {
212 if (entry.GetHasPostData())
213 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02214 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13215 }
[email protected]5e369672009-11-03 23:48:30216
[email protected]2c5569662011-03-22 20:45:02217 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30218}
219
[email protected]10f417c52011-12-28 21:04:23220void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47221 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42222 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50223 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24224 const std::string& embedder_channel_name,
225 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16226 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51227 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54228 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55229 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
230 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36231 if (!entry.GetBaseURLForDataURL().is_empty()) {
232 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
233 params->history_url_for_data_url = entry.GetVirtualURL();
234 }
[email protected]36fc0392011-12-25 03:59:51235 params->referrer = entry.GetReferrer();
236 params->transition = entry.GetTransitionType();
237 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00238 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55239 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34240 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47241 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48242 params->transferred_request_child_id =
243 entry.transferred_global_request_id().child_id;
244 params->transferred_request_request_id =
245 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22246 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00247 // Avoid downloading when in view-source mode.
248 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24249 params->embedder_channel_name = embedder_channel_name;
250 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44251 params->is_post = entry.GetHasPostData();
252 if(entry.GetBrowserInitiatedPostData()) {
253 params->browser_initiated_post_data.assign(
254 entry.GetBrowserInitiatedPostData()->front(),
255 entry.GetBrowserInitiatedPostData()->front() +
256 entry.GetBrowserInitiatedPostData()->size());
257
258 }
[email protected]6c6b02d2011-09-02 03:36:47259
[email protected]7c16976c2012-08-04 02:38:23260 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
261 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
262 // We may have been redirected when navigating to the current URL.
263 // Use the URL the user originally intended to visit, if it's valid and if a
264 // POST wasn't involved; the latter case avoids issues with sending data to
265 // the wrong page.
266 params->url = entry.GetOriginalRequestURL();
267 } else {
268 params->url = entry.GetURL();
269 }
270
[email protected]6c6b02d2011-09-02 03:36:47271 if (delegate)
272 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34273}
274
[email protected]f98f5092012-05-19 00:08:14275int GetSwitchValueAsInt(
276 const CommandLine& command_line,
277 const std::string& switch_string,
278 int min_value) {
279 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
280 int int_value;
281 if (base::StringToInt(string_value, &int_value))
282 return std::max(min_value, int_value);
283 else
284 return min_value;
285}
286
[email protected]420ae012009-04-24 05:16:32287} // namespace
288
[email protected]a81343d232011-12-27 07:39:20289namespace content {
290
291WebContents* WebContents::Create(
292 BrowserContext* browser_context,
293 SiteInstance* site_instance,
294 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19295 const WebContents* base_web_contents) {
296 return WebContentsImpl::Create(
297 browser_context, site_instance, routing_id,
298 static_cast<const WebContentsImpl*>(base_web_contents));
299}
300
301WebContents* WebContents::CreateWithSessionStorage(
302 BrowserContext* browser_context,
303 SiteInstance* site_instance,
304 int routing_id,
[email protected]b172aee2012-04-10 17:05:26305 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19306 const SessionStorageNamespaceMap& session_storage_namespace_map) {
307 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
308
309 for (SessionStorageNamespaceMap::const_iterator it =
310 session_storage_namespace_map.begin();
311 it != session_storage_namespace_map.end();
312 ++it) {
313 new_contents->GetController().SetSessionStorageNamespace(it->first,
314 it->second);
315 }
316
317 new_contents->Init(browser_context, site_instance, routing_id,
318 static_cast<const WebContentsImpl*>(base_web_contents));
319 return new_contents;
[email protected]a81343d232011-12-27 07:39:20320}
[email protected]746d3052012-05-22 15:15:47321
[email protected]299d7f12012-05-23 05:31:15322WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47323 return rvh->GetDelegate()->GetAsWebContents();
324}
325
[email protected]a81343d232011-12-27 07:39:20326}
[email protected]f4f50ef2011-01-21 19:01:19327
[email protected]b172aee2012-04-10 17:05:26328// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32329
[email protected]b172aee2012-04-10 17:05:26330WebContentsImpl::WebContentsImpl(
331 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19332 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42333 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19334 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57335 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44336 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05337 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34338 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23339 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
340 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34341 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21342 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56343 upload_size_(0),
344 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47345 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57346 capturing_contents_(false),
347 is_being_destroyed_(false),
348 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55349 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57350#if defined(OS_WIN)
351 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
352#endif
[email protected]7ab1e7d62009-10-14 23:32:01353 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56354 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38355 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25356 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01357 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25358 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01359 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00360 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43361 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20362 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35363}
initial.commit09911bf2008-07-26 23:55:29364
[email protected]b172aee2012-04-10 17:05:26365WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32366 is_being_destroyed_ = true;
367
[email protected]b24b68a2012-09-24 21:57:26368 for (std::set<RenderWidgetHostImpl*>::iterator iter =
369 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
370 (*iter)->DetachDelegate();
371 }
372 created_widgets_.clear();
373
[email protected]3ab9cb82011-06-03 18:02:07374 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55375 if (dialog_creator_)
376 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07377
[email protected]da8543762012-03-20 08:52:20378 if (color_chooser_)
379 color_chooser_->End();
380
[email protected]420ae012009-04-24 05:16:32381 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32382
[email protected]ca13a442012-04-17 14:00:12383 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07384 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09385 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
386 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07387 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32388
389 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07390#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32391 // If we still have a window handle, destroy it. GetNativeView can return
392 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42393 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52394 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58395 if (host && host->GetView())
396 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42397 }
[email protected]420ae012009-04-24 05:16:32398#endif
[email protected]7ab1e7d62009-10-14 23:32:01399
400 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15401 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55402 base::TimeTicks now = base::TimeTicks::Now();
403 base::TimeTicks unload_start_time = close_start_time_;
404 if (!before_unload_end_time_.is_null())
405 unload_start_time = before_unload_end_time_;
406 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
407 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01408 }
[email protected]b5a1d11c2011-02-17 03:09:42409
[email protected]2db9bd72012-04-13 20:20:56410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
412 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08413
[email protected]6934a702011-12-20 00:04:51414 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42415}
416
[email protected]d1198fd2012-08-13 22:50:19417WebContentsImpl* WebContentsImpl::Create(
418 BrowserContext* browser_context,
419 SiteInstance* site_instance,
420 int routing_id,
421 const WebContentsImpl* base_web_contents) {
422 return CreateWithOpener(browser_context, site_instance, routing_id,
423 base_web_contents, NULL);
424}
425
426WebContentsImpl* WebContentsImpl::CreateWithOpener(
427 BrowserContext* browser_context,
428 SiteInstance* site_instance,
429 int routing_id,
430 const WebContentsImpl* base_web_contents,
431 WebContentsImpl* opener) {
432 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
433
434 new_contents->Init(browser_context, site_instance, routing_id,
435 static_cast<const WebContentsImpl*>(base_web_contents));
436 return new_contents;
437}
438
[email protected]7a846df2012-09-20 19:17:39439WebContentsImpl* WebContentsImpl::CreateGuest(BrowserContext* browser_context,
440 const std::string& host_url,
441 int guest_instance_id) {
442 // The SiteInstance of a given guest is based on the fact that it's a guest
443 // in addition to which platform application the guest belongs to, rather
444 // than the URL that the guest is being navigated to.
445 GURL guest_site(
446 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str()));
447 SiteInstance* guest_site_instance =
448 SiteInstance::CreateForURL(browser_context, guest_site);
449 WebContentsImpl* new_contents = WebContentsImpl::Create(
450 browser_context,
451 guest_site_instance,
452 MSG_ROUTING_NONE,
453 NULL); // base WebContents
454 WebContentsImpl* new_contents_impl =
455 static_cast<WebContentsImpl*>(new_contents);
456
457 // This makes |new_contents| act as a guest.
458 // For more info, see comment above class BrowserPluginGuest.
459 new_contents_impl->browser_plugin_guest_.reset(
460 content::BrowserPluginGuest::Create(
461 guest_instance_id,
462 new_contents_impl,
463 new_contents_impl->GetRenderViewHost()));
464 return new_contents;
465}
466
[email protected]b172aee2012-04-10 17:05:26467WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
468 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54469 WebPreferences prefs;
470
471 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
472
473 prefs.developer_extras_enabled = true;
474 prefs.javascript_enabled =
475 !command_line.HasSwitch(switches::kDisableJavaScript);
476 prefs.web_security_enabled =
477 !command_line.HasSwitch(switches::kDisableWebSecurity);
478 prefs.plugins_enabled =
479 !command_line.HasSwitch(switches::kDisablePlugins);
480 prefs.java_enabled =
481 !command_line.HasSwitch(switches::kDisableJava);
482
483 prefs.uses_page_cache =
484 command_line.HasSwitch(switches::kEnableFastback);
485 prefs.remote_fonts_enabled =
486 !command_line.HasSwitch(switches::kDisableRemoteFonts);
487 prefs.xss_auditor_enabled =
488 !command_line.HasSwitch(switches::kDisableXSSAuditor);
489 prefs.application_cache_enabled =
490 !command_line.HasSwitch(switches::kDisableApplicationCache);
491
492 prefs.local_storage_enabled =
493 !command_line.HasSwitch(switches::kDisableLocalStorage);
494 prefs.databases_enabled =
495 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01496#if defined(OS_ANDROID)
497 prefs.webaudio_enabled =
498 command_line.HasSwitch(switches::kEnableWebAudio);
499#else
[email protected]64d69de42012-02-06 00:19:54500 prefs.webaudio_enabled =
501 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01502#endif
[email protected]64d69de42012-02-06 00:19:54503
504 prefs.experimental_webgl_enabled =
505 GpuProcessHost::gpu_enabled() &&
506 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07507#if defined(OS_ANDROID)
508 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
509#else
[email protected]64d69de42012-02-06 00:19:54510 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07511#endif
[email protected]64d69de42012-02-06 00:19:54512
[email protected]5a073092012-06-08 00:42:51513 prefs.flash_3d_enabled =
514 GpuProcessHost::gpu_enabled() &&
515 !command_line.HasSwitch(switches::kDisableFlash3d);
516 prefs.flash_stage3d_enabled =
517 GpuProcessHost::gpu_enabled() &&
518 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19519
[email protected]64d69de42012-02-06 00:19:54520 prefs.gl_multisampling_enabled =
521 !command_line.HasSwitch(switches::kDisableGLMultisampling);
522 prefs.privileged_webgl_extensions_enabled =
523 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
524 prefs.site_specific_quirks_enabled =
525 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
526 prefs.allow_file_access_from_file_urls =
527 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
528 prefs.show_composited_layer_borders =
529 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
530 prefs.show_composited_layer_tree =
531 command_line.HasSwitch(switches::kShowCompositedLayerTree);
532 prefs.show_fps_counter =
533 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08534 prefs.accelerated_compositing_for_overflow_scroll_enabled =
535 command_line.HasSwitch(
536 switches::kEnableAcceleratedCompositingForOverflowScroll);
[email protected]8611a852012-05-23 22:11:19537 prefs.show_paint_rects =
538 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52539 prefs.render_vsync_enabled =
540 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54541 prefs.accelerated_compositing_enabled =
542 GpuProcessHost::gpu_enabled() &&
543 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54544 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23545 command_line.HasSwitch(switches::kForceCompositingMode) &&
546 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54547 prefs.fixed_position_compositing_enabled =
548 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
549 prefs.accelerated_2d_canvas_enabled =
550 GpuProcessHost::gpu_enabled() &&
551 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58552 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27553 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54554 prefs.accelerated_painting_enabled =
555 GpuProcessHost::gpu_enabled() &&
556 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
557 prefs.accelerated_filters_enabled =
558 GpuProcessHost::gpu_enabled() &&
559 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
560 prefs.accelerated_layers_enabled =
561 prefs.accelerated_animation_enabled =
562 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54563 prefs.accelerated_plugins_enabled =
564 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
565 prefs.accelerated_video_enabled =
566 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54567 prefs.fullscreen_enabled =
568 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43569 prefs.css_sticky_position_enabled =
570 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]37ac2a82012-03-01 05:30:16571 prefs.css_regions_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03572 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29573 prefs.css_shaders_enabled =
574 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01575 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03576 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]c71fe6402012-08-15 15:22:55577#if defined(USE_AURA) && defined(USE_X11)
578 prefs.device_supports_touch |=
579 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
580#endif
[email protected]25ee94f2012-09-11 19:16:16581#if defined(OS_WIN)
582 prefs.device_supports_touch = ui::IsTouchDevicePresent();
583#endif
[email protected]d849b122012-07-18 07:35:26584#if defined(OS_ANDROID)
585 prefs.device_supports_mouse = false;
586#endif
[email protected]64d69de42012-02-06 00:19:54587
588#if defined(OS_MACOSX)
589 bool default_enable_scroll_animator = true;
590#else
591 // On CrOS, the launcher always passes in the --enable flag.
592 bool default_enable_scroll_animator = false;
593#endif
594 prefs.enable_scroll_animator = default_enable_scroll_animator;
595 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
596 prefs.enable_scroll_animator = true;
597 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
598 prefs.enable_scroll_animator = false;
599
600 prefs.visual_word_movement_enabled =
601 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54602
603 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32604 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54605 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39606 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]d56ecf922012-02-15 16:03:11607 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54608 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11609 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54610 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19611 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
612 prefs.flash_3d_enabled = false;
613 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
614 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11615 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54616 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11617 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54618 prefs.gl_multisampling_enabled = false;
619
620 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45621 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32622 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54623 prefs.accelerated_video_enabled = false;
624 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45625 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09626 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54627 }
628 }
629
[email protected]b9535422012-02-09 01:47:59630 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58631 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54632 prefs.loads_images_automatically = true;
633 prefs.javascript_enabled = true;
634 }
635
636 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
637
638 // Force accelerated compositing and 2d canvas off for chrome:, about: and
639 // chrome-devtools: pages (unless it's specifically allowed).
640 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54641 url.SchemeIs(chrome::kChromeUIScheme) ||
642 (url.SchemeIs(chrome::kAboutScheme) &&
643 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25644 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54645 prefs.accelerated_compositing_enabled = false;
646 prefs.accelerated_2d_canvas_enabled = false;
647 }
[email protected]43d9d782012-03-01 15:40:09648
[email protected]f98f5092012-05-19 00:08:14649 if (command_line.HasSwitch(switches::kDefaultTileWidth))
650 prefs.default_tile_width =
651 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
652 if (command_line.HasSwitch(switches::kDefaultTileHeight))
653 prefs.default_tile_height =
654 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
655 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
656 prefs.max_untiled_layer_width =
657 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
658 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
659 prefs.max_untiled_layer_height =
660 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
661
[email protected]2486dce2012-05-23 17:18:19662 if (gfx::Screen::IsDIPEnabled()) {
663 // Only apply when using DIP coordinate system as this setting interferes
664 // with fixed layout mode.
665 prefs.apply_default_device_scale_factor_in_compositor = true;
666 }
667
[email protected]de023762012-07-26 17:10:17668 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
669 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10670
[email protected]e755a382012-09-13 17:16:35671 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
672 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12673
[email protected]6b4dcb072012-06-18 22:26:51674 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
675
[email protected]2e21fe292012-03-02 22:52:32676 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54677
678 return prefs;
679}
680
[email protected]b172aee2012-04-10 17:05:26681RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28682 return &render_manager_;
683}
684
[email protected]7bb761892012-07-20 09:32:47685bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
686 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56687 if (GetWebUI() &&
688 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17689 return true;
[email protected]d2353452012-01-19 19:53:56690 }
[email protected]f82d57b52011-04-27 19:13:17691
[email protected]d8c660432011-12-22 20:51:25692 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
693 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10694 while ((observer = it.GetNext()) != NULL)
695 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53696 return true;
[email protected]403415a2011-01-10 18:57:53697
[email protected]7bb761892012-07-20 09:32:47698 // Message handlers should be aware of which RenderViewHost sent the
699 // message, which is temporarily stored in message_source_.
700 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18701 bool handled = true;
702 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26703 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58704 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
705 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24706 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
707 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18708 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
709 OnDidLoadResourceFromMemoryCache)
710 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
711 OnDidDisplayInsecureContent)
712 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
713 OnDidRunInsecureContent)
714 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
715 OnDocumentLoadedInFrame)
716 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26717 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
718 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17719 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
720 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25721 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26722 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59723 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21724 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20725 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
726 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
727 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16728 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]59363fc92012-09-05 03:46:31729#if defined(OS_ANDROID)
730 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
731 OnFindMatchRectsReply)
732#endif
[email protected]d952a052011-09-06 18:42:45733 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10734 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20735 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
736 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
737 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
738 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29739 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50740 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50741 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
742 OnRequestPpapiBrokerPermission)
[email protected]7a846df2012-09-20 19:17:39743 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
744 OnBrowserPluginNavigateGuest)
[email protected]724159a2010-12-30 01:11:18745 IPC_MESSAGE_UNHANDLED(handled = false)
746 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47747 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18748
749 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38750 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18751 GetRenderProcessHost()->ReceivedBadMessage();
752 }
753
754 return handled;
755}
756
[email protected]b172aee2012-04-10 17:05:26757void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18758 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23759 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43760 if (delegate_)
761 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18762}
763
[email protected]d1198fd2012-08-13 22:50:19764NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56765 return controller_;
766}
767
[email protected]d1198fd2012-08-13 22:50:19768const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56769 return controller_;
770}
771
[email protected]b172aee2012-04-10 17:05:26772content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55773 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30774}
775
[email protected]b172aee2012-04-10 17:05:26776const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31777 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23778 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51779 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31780}
781
[email protected]b172aee2012-04-10 17:05:26782content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31783 return delegate_;
784}
785
[email protected]b172aee2012-04-10 17:05:26786void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31787 // TODO(cbentzel): remove this debugging code?
788 if (delegate == delegate_)
789 return;
790 if (delegate_)
791 delegate_->Detach(this);
792 delegate_ = delegate;
793 if (delegate_)
794 delegate_->Attach(this);
795}
796
[email protected]b172aee2012-04-10 17:05:26797content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41798 RenderViewHostImpl* host = render_manager_.current_host();
799 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16800}
801
[email protected]b172aee2012-04-10 17:05:26802RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return render_manager_.current_host();
804}
805
[email protected]6b618e62012-08-16 12:59:18806int WebContentsImpl::GetRoutingID() const {
807 if (!GetRenderViewHost())
808 return MSG_ROUTING_NONE;
809
810 return GetRenderViewHost()->GetRoutingID();
811}
812
[email protected]b172aee2012-04-10 17:05:26813RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31814 return render_manager_.GetRenderWidgetHostView();
815}
816
[email protected]b172aee2012-04-10 17:05:26817content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31818 return view_.get();
819}
820
[email protected]b172aee2012-04-10 17:05:26821content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50822 WebUIControllerFactory* factory =
823 content::GetContentClient()->browser()->GetWebUIControllerFactory();
824 if (!factory)
825 return NULL;
[email protected]d2353452012-01-19 19:53:56826 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22827 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50828 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22829 if (controller) {
830 web_ui->SetController(controller);
831 return web_ui;
832 }
833
834 delete web_ui;
835 return NULL;
836}
837
[email protected]b172aee2012-04-10 17:05:26838content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return render_manager_.web_ui() ? render_manager_.web_ui()
840 : render_manager_.pending_web_ui();
841}
842
[email protected]b172aee2012-04-10 17:05:26843content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31844 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34845}
846
[email protected]86ef6a392012-05-11 22:03:11847void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22848 if (GetUserAgentOverride() == override)
849 return;
850
851 renderer_preferences_.user_agent_override = override;
852
853 // Send the new override string to the renderer.
854 RenderViewHost* host = GetRenderViewHost();
855 if (host)
856 host->SyncRendererPrefs();
857
858 // Reload the page if a load is currently in progress to avoid having
859 // different parts of the page loaded using different user agents.
860 NavigationEntry* entry = controller_.GetActiveEntry();
861 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
862 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53863
864 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
865 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11866}
867
868const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22869 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11870}
871
[email protected]b172aee2012-04-10 17:05:26872const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55873 // Transient entries take precedence. They are used for interstitial pages
874 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23875 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08876 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20877 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30878 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23879 if (entry) {
[email protected]b5cca982011-05-26 04:42:08880 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23881 }
[email protected]7ade2732011-02-10 00:13:58882 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
883 render_manager_.pending_web_ui() : render_manager_.web_ui();
884 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54885 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55886 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54887 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35888 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22889 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54890 if (!title.empty())
891 return title;
892 }
893 }
894
895 // We use the title for the last committed entry rather than a pending
896 // navigation entry. For example, when the user types in a URL, we want to
897 // keep the old page's title until the new load has committed and we get a new
898 // title.
[email protected]96d185d2009-04-24 03:28:54899 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23900 if (entry) {
[email protected]b5cca982011-05-26 04:42:08901 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23902 }
[email protected]987fc3a2011-05-26 14:18:09903
904 // |page_title_when_no_navigation_entry_| is finally used
905 // if no title cannot be retrieved.
906 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54907}
908
[email protected]b172aee2012-04-10 17:05:26909int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46910 return GetMaxPageIDForSiteInstance(GetSiteInstance());
911}
912
[email protected]b172aee2012-04-10 17:05:26913int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
914 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33915 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
916 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46917
[email protected]b6583592012-01-25 19:52:33918 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34919}
920
[email protected]b172aee2012-04-10 17:05:26921void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46922 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
923}
924
[email protected]b172aee2012-04-10 17:05:26925void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33926 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46927 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33928 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34929}
930
[email protected]b172aee2012-04-10 17:05:26931void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
932 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57933}
934
[email protected]b172aee2012-04-10 17:05:26935SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58936 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54937}
938
[email protected]b172aee2012-04-10 17:05:26939SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38940 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
941 render_manager_.pending_render_view_host() :
942 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58943 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38944}
945
[email protected]b172aee2012-04-10 17:05:26946bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31947 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49948}
949
[email protected]b172aee2012-04-10 17:05:26950bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31951 return waiting_for_response_;
952}
953
[email protected]b172aee2012-04-10 17:05:26954const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31955 return load_state_;
956}
957
[email protected]b172aee2012-04-10 17:05:26958const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31959 return load_state_host_;
960}
961
[email protected]b172aee2012-04-10 17:05:26962uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31963 return upload_size_;
964}
965
[email protected]b172aee2012-04-10 17:05:26966uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31967 return upload_position_;
968}
969
[email protected]b172aee2012-04-10 17:05:26970const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31971 return encoding_;
972}
973
[email protected]b172aee2012-04-10 17:05:26974bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31975 return displayed_insecure_content_;
976}
977
[email protected]b172aee2012-04-10 17:05:26978void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31979 capturing_contents_ = cap;
980}
981
[email protected]b172aee2012-04-10 17:05:26982bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31983 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
984 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
985 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49986}
987
[email protected]b172aee2012-04-10 17:05:26988void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
989 int error_code) {
[email protected]443b80e2010-12-14 00:42:23990 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34991 return;
992
[email protected]443b80e2010-12-14 00:42:23993 crashed_status_ = status;
994 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46995 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34996}
997
[email protected]b172aee2012-04-10 17:05:26998base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31999 return crashed_status_;
1000}
1001
[email protected]b172aee2012-04-10 17:05:261002bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311003 return is_being_destroyed_;
1004}
1005
[email protected]b172aee2012-04-10 17:05:261006void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341007 if (delegate_)
1008 delegate_->NavigationStateChanged(this, changed_flags);
1009}
1010
[email protected]3e324142012-06-25 18:26:331011base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1012 return last_selected_time_;
1013}
1014
[email protected]9e2e4632012-07-27 16:38:411015void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541016 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041017 RenderWidgetHostViewPort* rwhv =
1018 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161019 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411020 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431021#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161022 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431023#endif
1024 }
[email protected]96d185d2009-04-24 03:28:541025
[email protected]5ac20162010-11-24 23:33:111026 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381027
[email protected]9e2e4632012-07-27 16:38:411028 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591029
1030 // The resize rect might have changed while this was inactive -- send the new
1031 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581032 RenderViewHostImpl* rvh =
1033 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591034 if (rvh) {
1035 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1036 }
[email protected]96d185d2009-04-24 03:28:541037
[email protected]3e324142012-06-25 18:26:331038 bool is_visible = true;
1039 content::NotificationService::current()->Notify(
1040 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1041 content::Source<WebContents>(this),
1042 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311043}
1044
[email protected]b172aee2012-04-10 17:05:261045void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311046 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521047 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1048 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261049 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521050 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331051 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521052 // calls us).
[email protected]c30585c2012-02-16 15:02:041053 RenderWidgetHostViewPort* rwhv =
1054 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161055 if (rwhv)
1056 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541057 }
1058
[email protected]375fa1b2012-05-22 22:05:371059 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071060 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371061 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091062 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371063 content::Details<bool>(&is_visible));
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311067 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271068 return WillNotifyDisconnection() &&
1069 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581070 !static_cast<RenderViewHostImpl*>(
1071 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311072}
1073
[email protected]b172aee2012-04-10 17:05:261074void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271075 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251076 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271077}
1078
[email protected]b172aee2012-04-10 17:05:261079WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441080 // We use our current SiteInstance since the cloned entry will use it anyway.
1081 // We pass |this| for the |base_web_contents| to size the view correctly, and
1082 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191083 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1084 GetSiteInstance(), MSG_ROUTING_NONE,
1085 this, opener_);
1086 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221087 FOR_EACH_OBSERVER(WebContentsObserver,
1088 observers_,
1089 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271090 return tc;
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271094 return view_->GetContentNativeView();
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271098 return view_->GetNativeView();
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271102 view_->GetContainerBounds(out);
1103}
1104
[email protected]b172aee2012-04-10 17:05:261105void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271106 view_->Focus();
1107}
1108
[email protected]14392a52012-05-02 20:28:441109void WebContentsImpl::Observe(int type,
1110 const content::NotificationSource& source,
1111 const content::NotificationDetails& details) {
1112 switch (type) {
1113 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1114 OnWebContentsDestroyed(
1115 content::Source<content::WebContents>(source).ptr());
1116 break;
[email protected]bafe6cd2012-05-23 23:09:501117 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1118 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1119 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1120 i != pending_widget_views_.end(); ++i) {
1121 if (host->GetView() == i->second) {
1122 pending_widget_views_.erase(i);
1123 break;
1124 }
1125 }
1126 break;
1127 }
[email protected]14392a52012-05-02 20:28:441128 default:
1129 NOTREACHED();
1130 }
1131}
1132
[email protected]d1198fd2012-08-13 22:50:191133void WebContentsImpl::Init(BrowserContext* browser_context,
1134 SiteInstance* site_instance,
1135 int routing_id,
1136 const WebContents* base_web_contents) {
1137 render_manager_.Init(browser_context, site_instance, routing_id);
1138
1139 view_.reset(content::GetContentClient()->browser()->
1140 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1141 if (view_.get()) {
1142 CHECK(render_view_host_delegate_view_);
1143 } else {
1144 content::WebContentsViewDelegate* delegate =
1145 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1146 this);
1147 view_.reset(CreateWebContentsView(
1148 this, delegate, &render_view_host_delegate_view_));
1149 CHECK(render_view_host_delegate_view_);
1150 }
1151 CHECK(view_.get());
1152
1153 // We have the initial size of the view be based on the size of the view of
1154 // the passed in WebContents.
1155 view_->CreateView(base_web_contents ?
1156 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1157
1158 // Listen for whether our opener gets destroyed.
1159 if (opener_) {
1160 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1161 content::Source<WebContents>(opener_));
1162 }
1163
1164 registrar_.Add(this,
1165 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1166 content::NotificationService::AllBrowserContextsAndSources());
1167#if defined(ENABLE_JAVA_BRIDGE)
1168 java_bridge_dispatcher_host_manager_.reset(
1169 new JavaBridgeDispatcherHostManager(this));
1170#endif
1171
1172 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1173}
1174
[email protected]14392a52012-05-02 20:28:441175void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1176 // Clear the opener if it has been closed.
1177 if (web_contents == opener_) {
1178 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1179 content::Source<WebContents>(opener_));
1180 opener_ = NULL;
1181 }
1182}
1183
[email protected]b172aee2012-04-10 17:05:261184void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311185 observers_.AddObserver(observer);
1186}
1187
[email protected]b172aee2012-04-10 17:05:261188void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311189 observers_.RemoveObserver(observer);
1190}
1191
[email protected]b172aee2012-04-10 17:05:261192void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341193 if (delegate_)
1194 delegate_->ActivateContents(this);
1195}
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121198 if (delegate_)
1199 delegate_->DeactivateContents(this);
1200}
1201
[email protected]b172aee2012-04-10 17:05:261202void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481203 if (delegate_)
1204 delegate_->LostCapture();
1205}
1206
[email protected]b24b68a2012-09-24 21:57:261207void WebContentsImpl::RenderWidgetDeleted(
1208 RenderWidgetHostImpl* render_widget_host) {
1209 if (is_being_destroyed_) {
1210 // |created_widgets_| might have been destroyed.
1211 return;
1212 }
1213
1214 std::set<RenderWidgetHostImpl*>::iterator iter =
1215 created_widgets_.find(render_widget_host);
1216 if (iter != created_widgets_.end())
1217 created_widgets_.erase(iter);
1218}
1219
[email protected]b172aee2012-04-10 17:05:261220bool WebContentsImpl::PreHandleKeyboardEvent(
1221 const NativeWebKeyboardEvent& event,
1222 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481223 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131224 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481225}
1226
[email protected]b172aee2012-04-10 17:05:261227void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481228 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131229 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481230}
1231
[email protected]b172aee2012-04-10 17:05:261232void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431233 if (delegate_)
1234 delegate_->HandleMouseDown();
1235}
1236
[email protected]b172aee2012-04-10 17:05:261237void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481238 if (delegate_)
1239 delegate_->HandleMouseUp();
1240}
1241
[email protected]590a634e2012-07-19 16:38:231242void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481243 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231244 delegate_->HandlePointerActivate();
1245}
1246
1247void WebContentsImpl::HandleGestureBegin() {
1248 if (delegate_)
1249 delegate_->HandleGestureBegin();
1250}
1251
1252void WebContentsImpl::HandleGestureEnd() {
1253 if (delegate_)
1254 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481255}
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471258 if (delegate_)
1259 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381263 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121264}
1265
[email protected]a9c81f02012-06-01 00:15:441266void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1267 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371268 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441269 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371270 } else {
1271 GotResponseToLockMouseRequest(false);
1272 }
1273}
1274
[email protected]b172aee2012-04-10 17:05:261275void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371276 if (delegate_)
1277 delegate_->LostMouseLock();
1278}
1279
[email protected]bafe6cd2012-05-23 23:09:501280void WebContentsImpl::CreateNewWindow(
1281 int route_id,
[email protected]97714c82012-06-06 10:15:131282 const ViewHostMsg_CreateWindow_Params& params,
1283 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501284 if (delegate_ && !delegate_->ShouldCreateWebContents(
1285 this, route_id, params.window_container_type, params.frame_name,
1286 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091287 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501288 return;
1289 }
1290
1291 // We usually create the new window in the same BrowsingInstance (group of
1292 // script-related windows), by passing in the current SiteInstance. However,
1293 // if the opener is being suppressed, we create a new SiteInstance in its own
1294 // BrowsingInstance.
1295 scoped_refptr<SiteInstance> site_instance =
1296 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571297 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501298 GetSiteInstance();
1299
1300 // Create the new web contents. This will automatically create the new
1301 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191302 WebContentsImpl* new_contents =
1303 new WebContentsImpl(GetBrowserContext(),
1304 params.opener_suppressed ? NULL : this);
1305
1306 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341307 //
1308 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191309 const std::string& partition_id =
1310 content::GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571311 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591312 site_instance->GetSiteURL());
[email protected]4c3a23582012-08-18 08:54:341313 content::StoragePartition* partition =
1314 BrowserContext::GetStoragePartition(GetBrowserContext(),
1315 site_instance);
[email protected]d1198fd2012-08-13 22:50:191316 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341317 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191318 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1319 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1320 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1321 new_contents->GetController().SetSessionStorageNamespace(
1322 partition_id,
1323 session_storage_namespace);
1324 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1325
[email protected]bafe6cd2012-05-23 23:09:501326 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1327
1328 if (!params.opener_suppressed) {
1329 content::WebContentsView* new_view = new_contents->GetView();
1330
1331 // TODO(brettw): It seems bogus that we have to call this function on the
1332 // newly created object and give it one of its own member variables.
1333 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1334
1335 // Save the created window associated with the route so we can show it
1336 // later.
1337 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1338 pending_contents_[route_id] = new_contents;
1339 }
1340
1341 if (delegate_) {
1342 delegate_->WebContentsCreated(
1343 this, params.opener_frame_id, params.target_url, new_contents);
1344 }
1345
1346 if (params.opener_suppressed) {
1347 // When the opener is suppressed, the original renderer cannot access the
1348 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001349 bool was_blocked = false;
1350 if (delegate_) {
1351 gfx::Rect initial_pos;
1352 delegate_->AddNewContents(
1353 this, new_contents, params.disposition, initial_pos,
1354 params.user_gesture, &was_blocked);
1355 }
1356 if (!was_blocked) {
1357 content::OpenURLParams open_params(params.target_url,
1358 content::Referrer(),
1359 CURRENT_TAB,
1360 content::PAGE_TRANSITION_LINK,
1361 true /* is_renderer_initiated */);
1362 new_contents->OpenURL(open_params);
1363 }
[email protected]bafe6cd2012-05-23 23:09:501364 }
1365}
1366
1367void WebContentsImpl::CreateNewWidget(int route_id,
1368 WebKit::WebPopupType popup_type) {
1369 CreateNewWidget(route_id, false, popup_type);
1370}
1371
1372void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1373 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1374}
1375
1376void WebContentsImpl::CreateNewWidget(int route_id,
1377 bool is_fullscreen,
1378 WebKit::WebPopupType popup_type) {
1379 content::RenderProcessHost* process = GetRenderProcessHost();
1380 RenderWidgetHostImpl* widget_host =
1381 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261382 created_widgets_.insert(widget_host);
1383
[email protected]bafe6cd2012-05-23 23:09:501384 RenderWidgetHostViewPort* widget_view =
1385 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1386 if (!is_fullscreen) {
1387 // Popups should not get activated.
1388 widget_view->SetPopupType(popup_type);
1389 }
1390 // Save the created widget associated with the route so we can show it later.
1391 pending_widget_views_[route_id] = widget_view;
1392
1393#if defined(OS_MACOSX)
1394 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1395 // to allow it to survive the trip without being hosted.
1396 base::mac::NSObjectRetain(widget_view->GetNativeView());
1397#endif
1398}
1399
1400void WebContentsImpl::ShowCreatedWindow(int route_id,
1401 WindowOpenDisposition disposition,
1402 const gfx::Rect& initial_pos,
1403 bool user_gesture) {
1404 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001405 if (contents) {
1406 WebContentsDelegate* delegate = GetDelegate();
1407 if (delegate) {
1408 delegate->AddNewContents(
1409 this, contents, disposition, initial_pos, user_gesture, NULL);
1410 }
1411 }
[email protected]bafe6cd2012-05-23 23:09:501412}
1413
1414void WebContentsImpl::ShowCreatedWidget(int route_id,
1415 const gfx::Rect& initial_pos) {
1416 ShowCreatedWidget(route_id, false, initial_pos);
1417}
1418
1419void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1420 ShowCreatedWidget(route_id, true, gfx::Rect());
1421}
1422
1423void WebContentsImpl::ShowCreatedWidget(int route_id,
1424 bool is_fullscreen,
1425 const gfx::Rect& initial_pos) {
1426 if (delegate_)
1427 delegate_->RenderWidgetShowing();
1428
1429 RenderWidgetHostViewPort* widget_host_view =
1430 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1431 if (!widget_host_view)
1432 return;
1433 if (is_fullscreen) {
1434 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1435 } else {
1436 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1437 }
[email protected]89054502012-06-03 10:29:241438
1439 RenderWidgetHostImpl* render_widget_host_impl =
1440 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1441 render_widget_host_impl->Init();
1442 // Only allow privileged mouse lock for fullscreen render widget, which is
1443 // used to implement Pepper Flash fullscreen.
1444 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501445
1446#if defined(OS_MACOSX)
1447 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1448 // properly embedded (or purposefully ignored) we can release the retain we
1449 // took in CreateNewWidget().
1450 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1451#endif
1452}
1453
1454WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1455 PendingContents::iterator iter = pending_contents_.find(route_id);
1456
1457 // Certain systems can block the creation of new windows. If we didn't succeed
1458 // in creating one, just return NULL.
1459 if (iter == pending_contents_.end()) {
1460 return NULL;
1461 }
1462
1463 WebContentsImpl* new_contents = iter->second;
1464 pending_contents_.erase(route_id);
1465
1466 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1467 !new_contents->GetRenderViewHost()->GetView())
1468 return NULL;
1469
1470 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1471 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1472 return new_contents;
1473}
1474
1475RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1476 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1477 if (iter == pending_widget_views_.end()) {
1478 DCHECK(false);
1479 return NULL;
1480 }
1481
1482 RenderWidgetHostView* widget_host_view = iter->second;
1483 pending_widget_views_.erase(route_id);
1484
1485 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1486 if (!widget_host->GetProcess()->HasConnection()) {
1487 // The view has gone away or the renderer crashed. Nothing to do.
1488 return NULL;
1489 }
1490
1491 return widget_host_view;
1492}
1493
1494void WebContentsImpl::ShowContextMenu(
[email protected]ba16e3a2012-09-07 04:14:521495 const content::ContextMenuParams& params,
[email protected]1de0fc02012-09-17 21:37:271496 content::ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501497 // Allow WebContentsDelegates to handle the context menu operation first.
1498 if (delegate_ && delegate_->HandleContextMenu(params))
1499 return;
1500
[email protected]ba16e3a2012-09-07 04:14:521501 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501502}
1503
[email protected]f13b4202012-06-12 23:53:231504void WebContentsImpl::RequestMediaAccessPermission(
1505 const content::MediaStreamRequest* request,
1506 const content::MediaResponseCallback& callback) {
1507 if (delegate_)
1508 delegate_->RequestMediaAccessPermission(this, request, callback);
1509 else
1510 callback.Run(content::MediaStreamDevices());
1511}
1512
[email protected]16383382012-09-05 23:57:261513#if defined(OS_ANDROID)
1514void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1515 if (delegate_)
1516 delegate_->AttachLayer(this, layer);
1517}
1518
1519void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1520 if (delegate_)
1521 delegate_->RemoveLayer(this, layer);
1522}
1523#endif
1524
[email protected]b172aee2012-04-10 17:05:261525void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231526 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331527 if (delegate_)
1528 delegate_->UpdatePreferredSize(this, pref_size);
1529}
1530
[email protected]b172aee2012-04-10 17:05:261531void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341532 if (delegate_)
1533 delegate_->ResizeDueToAutoResize(this, new_size);
1534}
1535
[email protected]b172aee2012-04-10 17:05:261536WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201537 if (!delegate_)
1538 return NULL;
[email protected]00c37fc2011-08-02 00:22:501539
[email protected]e5d549d2011-12-28 01:29:201540 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1541 // Notify observers.
1542 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1543 DidOpenURL(params.url, params.referrer,
1544 params.disposition, params.transition));
1545 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341546}
1547
[email protected]6b618e62012-08-16 12:59:181548bool WebContentsImpl::Send(IPC::Message* message) {
1549 if (!GetRenderViewHost()) {
1550 delete message;
1551 return false;
1552 }
1553
1554 return GetRenderViewHost()->Send(message);
1555}
1556
[email protected]b172aee2012-04-10 17:05:261557bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501558 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251559 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231560 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251561 reload_type);
[email protected]876bc832010-09-07 16:29:541562}
[email protected]96d185d2009-04-24 03:28:541563
[email protected]ba45bfd2012-05-22 21:51:441564void WebContentsImpl::RenderViewForInterstitialPageCreated(
1565 content::RenderViewHost* render_view_host) {
1566 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1567 RenderViewForInterstitialPageCreated(render_view_host));
1568}
1569
[email protected]b172aee2012-04-10 17:05:261570bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231571 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501572 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401573 // The renderer will reject IPC messages with URLs longer than
1574 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511575 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401576 return false;
1577
[email protected]9f76c1e2012-03-05 15:15:581578 RenderViewHostImpl* dest_render_view_host =
1579 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401580 if (!dest_render_view_host)
1581 return false; // Unable to create the desired render view host.
1582
[email protected]80a8fad2011-01-29 04:02:381583 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071584 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581585 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501586 WebUIControllerFactory* factory =
1587 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271588 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501589 bool is_allowed_in_web_ui_renderer =
1590 factory &&
[email protected]24e18252012-04-16 21:26:271591 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1592 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231593 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1594 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271595 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231596 content::GetContentClient()->SetActiveURL(entry.GetURL());
1597 CHECK(0);
1598 }
[email protected]54ec6472010-04-09 19:39:581599
[email protected]96d185d2009-04-24 03:28:541600 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441601 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521602 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441603 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511604 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541605
[email protected]7bb761892012-07-20 09:32:471606 // Notify observers that we will navigate in this RV.
1607 FOR_EACH_OBSERVER(WebContentsObserver,
1608 observers_,
1609 AboutToNavigateRenderView(dest_render_view_host));
1610
[email protected]96d185d2009-04-24 03:28:541611 // Used for page load time metrics.
1612 current_load_start_ = base::TimeTicks::Now();
1613
1614 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241615 std::string embedder_channel_name;
1616 int embedder_container_id;
1617 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1618 &embedder_channel_name,
1619 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341620 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271621 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241622 embedder_channel_name,
1623 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471624 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341625 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541626
[email protected]36fc0392011-12-25 03:59:511627 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541628 // HACK!! This code suppresses javascript: URLs from being added to
1629 // session history, which is what we want to do for javascript: URLs that
1630 // do not generate content. What we really need is a message from the
1631 // renderer telling us that a new page was not created. The same message
1632 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511633 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541634 return false;
1635 }
1636
[email protected]3c9e1872010-11-18 16:17:491637 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251638 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041639 observers_,
[email protected]36fc0392011-12-25 03:59:511640 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541641
[email protected]09b29342011-06-24 19:18:481642 if (delegate_)
1643 delegate_->DidNavigateToPendingEntry(this);
1644
[email protected]d5f942ba2008-09-26 19:30:341645 return true;
1646}
1647
[email protected]b172aee2012-04-10 17:05:261648void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331649 const SiteInstance* site_instance,
1650 int history_length,
1651 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411652 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1653 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191654 if (render_manager_.pending_render_view_host()) {
1655 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141656 return;
[email protected]9e1ad4b2011-08-14 16:49:191657 }
[email protected]9f76c1e2012-03-05 15:15:581658 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191659 if (!rvh) {
1660 NOTREACHED();
1661 return;
1662 }
[email protected]9f76c1e2012-03-05 15:15:581663 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191664 NOTREACHED();
1665 return;
1666 }
[email protected]6b618e62012-08-16 12:59:181667 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1668 history_length,
1669 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141670}
1671
[email protected]b172aee2012-04-10 17:05:261672void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271673 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541674 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1675 return;
1676 }
[email protected]9f76c1e2012-03-05 15:15:581677 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541678}
1679
[email protected]b172aee2012-04-10 17:05:261680bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271681 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541682}
1683
[email protected]b172aee2012-04-10 17:05:261684InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271685 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221686}
1687
[email protected]b172aee2012-04-10 17:05:261688bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161689 // WebKit creates Document object when MIME type is application/xhtml+xml,
1690 // so we also support this MIME type.
1691 return contents_mime_type_ == "text/html" ||
1692 contents_mime_type_ == "text/xml" ||
1693 contents_mime_type_ == "application/xhtml+xml" ||
1694 contents_mime_type_ == "text/plain" ||
1695 contents_mime_type_ == "text/css" ||
1696 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591700 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161701 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481702 download_stats::RecordDownloadSource(
1703 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461704 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141705 return;
[email protected]c7dd2f62011-07-18 15:57:591706 }
1707
1708 Stop();
1709
1710 // Create the save package and possibly prompt the user for the name to save
1711 // the page as. The user prompt is an asynchronous operation that runs on
1712 // another thread.
1713 save_package_ = new SavePackage(this);
1714 save_package_->GetSaveInfo();
1715}
1716
1717// Used in automated testing to bypass prompting the user for file names.
1718// Instead, the names and paths are hard coded rather than running them through
1719// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261720bool WebContentsImpl::SavePage(const FilePath& main_file,
1721 const FilePath& dir_path,
1722 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591723 // Stop the page from navigating.
1724 Stop();
1725
1726 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271727 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591728}
1729
[email protected]b172aee2012-04-10 17:05:261730void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121731 const FilePath& file,
1732 const base::Callback<void(const FilePath&, int64)>& callback) {
1733 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1734}
1735
[email protected]b172aee2012-04-10 17:05:261736bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231737 NavigationEntryImpl* active_entry =
1738 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321739 return (active_entry != NULL &&
1740 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511741 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321742}
1743
[email protected]b172aee2012-04-10 17:05:261744const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271745 return contents_mime_type_;
1746}
1747
[email protected]b172aee2012-04-10 17:05:261748bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271749 return notify_disconnection_;
1750}
1751
[email protected]b172aee2012-04-10 17:05:261752void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311753 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181754 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161755}
1756
[email protected]b172aee2012-04-10 17:05:261757void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311758 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181759 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161760}
1761
[email protected]b172aee2012-04-10 17:05:261762content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271763 return &renderer_preferences_;
1764}
1765
[email protected]b172aee2012-04-10 17:05:261766void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271767 new_tab_start_time_ = time;
1768}
1769
[email protected]b172aee2012-04-10 17:05:261770base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271771 return new_tab_start_time_;
1772}
1773
[email protected]e35ccd52012-05-23 16:22:471774void WebContentsImpl::Close() {
1775 Close(GetRenderViewHost());
1776}
1777
[email protected]b172aee2012-04-10 17:05:261778void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151779 if (close_start_time_.is_null())
1780 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011781}
1782
[email protected]b172aee2012-04-10 17:05:261783bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191784#if defined(OS_CHROMEOS)
1785 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1786 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511787 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201788 return false;
1789 return true;
[email protected]46624bf2010-06-09 16:04:191790#else
1791 return true;
1792#endif
1793}
1794
[email protected]b172aee2012-04-10 17:05:261795void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521796 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581797 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511798 if (delegate_)
1799 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341800}
1801
[email protected]e35ccd52012-05-23 16:22:471802void WebContentsImpl::UserGestureDone() {
1803 OnUserGesture();
1804}
1805
[email protected]b172aee2012-04-10 17:05:261806void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271807 closed_by_user_gesture_ = value;
1808}
1809
[email protected]b172aee2012-04-10 17:05:261810bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271811 return closed_by_user_gesture_;
1812}
1813
[email protected]b172aee2012-04-10 17:05:261814double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051815 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561816 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251817 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171818 return 0;
[email protected]b75b8292010-10-01 07:28:251819
1820 double zoom_level;
1821 if (temporary_zoom_settings_) {
1822 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581823 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251824 } else {
[email protected]2ae88d12011-10-14 09:11:191825 GURL url;
[email protected]10f417c52011-12-28 21:04:231826 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191827 // Since zoom map is updated using rewritten URL, use rewritten URL
1828 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511829 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191830 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251831 }
[email protected]d0b8d092010-10-25 04:05:171832 return zoom_level;
1833}
[email protected]b75b8292010-10-01 07:28:251834
[email protected]b172aee2012-04-10 17:05:261835int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591836 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171837 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011838 // Calculate the zoom percent from the factor. Round up to the nearest whole
1839 // number.
[email protected]b75b8292010-10-01 07:28:251840 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011841 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251842 *enable_decrement = percent > minimum_zoom_percent_;
1843 *enable_increment = percent < maximum_zoom_percent_;
1844 return percent;
1845}
1846
[email protected]b172aee2012-04-10 17:05:261847void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501848 if (!delegate_)
1849 return;
1850
[email protected]10f417c52011-12-28 21:04:231851 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501852 if (!active_entry)
1853 return;
1854
[email protected]36fc0392011-12-25 03:59:511855 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121856}
1857
[email protected]b172aee2012-04-10 17:05:261858void WebContentsImpl::ViewFrameSource(const GURL& url,
1859 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271860 if (!delegate_)
1861 return;
1862
1863 delegate_->ViewSourceForFrame(this, url, content_state);
1864}
1865
[email protected]b172aee2012-04-10 17:05:261866int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271867 return minimum_zoom_percent_;
1868}
1869
[email protected]b172aee2012-04-10 17:05:261870int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271871 return maximum_zoom_percent_;
1872}
1873
[email protected]b172aee2012-04-10 17:05:261874gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231875 return preferred_size_;
1876}
1877
[email protected]b172aee2012-04-10 17:05:261878int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271879 return content_restrictions_;
1880}
1881
[email protected]b172aee2012-04-10 17:05:261882WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501883 WebUIControllerFactory* factory =
1884 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1885 if (!factory)
1886 return WebUI::kNoWebUI;
1887 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271888}
1889
[email protected]b172aee2012-04-10 17:05:261890content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271891 // When there is a pending navigation entry, we want to use the pending WebUI
1892 // that goes along with it to control the basic flags. For example, we want to
1893 // show the pending URL in the URL bar, so we want the display_url flag to
1894 // be from the pending entry.
1895 //
1896 // The confusion comes because there are multiple possibilities for the
1897 // initial load in a tab as a side effect of the way the RenderViewHostManager
1898 // works.
1899 //
1900 // - For the very first tab the load looks "normal". The new tab Web UI is
1901 // the pending one, and we want it to apply here.
1902 //
1903 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1904 // get switched to the one previously associated with the new tab pages.
1905 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1906 // have a committed Web UI in this case.
1907 //
1908 // This condition handles all of these cases:
1909 //
1910 // - First load in first tab: no committed nav entry + pending nav entry +
1911 // pending dom ui:
1912 // -> Use pending Web UI if any.
1913 //
1914 // - First load in second tab: no committed nav entry + pending nav entry +
1915 // no pending Web UI:
1916 // -> Use the committed Web UI if any.
1917 //
1918 // - Second navigation in any tab: committed nav entry + pending nav entry:
1919 // -> Use pending Web UI if any.
1920 //
1921 // - Normal state with no load: committed nav entry + no pending nav entry:
1922 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251923 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271924 (controller_.GetLastCommittedEntry() ||
1925 render_manager_.pending_web_ui()))
1926 return render_manager_.pending_web_ui();
1927 return render_manager_.web_ui();
1928}
1929
[email protected]b172aee2012-04-10 17:05:261930bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271931 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581932 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271933}
1934
[email protected]b172aee2012-04-10 17:05:261935bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441936 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501937}
1938
[email protected]b172aee2012-04-10 17:05:261939void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321940 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181941 Send(new ViewMsg_DidChooseColorResponse(
1942 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201943}
1944
[email protected]b172aee2012-04-10 17:05:261945void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181946 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201947 if (delegate_)
1948 delegate_->DidEndColorChooser();
1949 color_chooser_ = NULL;
1950}
1951
[email protected]b172aee2012-04-10 17:05:261952bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471953 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271954 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221955 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231956 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411957 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271958}
1959
[email protected]b172aee2012-04-10 17:05:261960void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271961 if (delegate_)
1962 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211963}
1964
[email protected]3a3b75a2012-06-01 08:38:361965void WebContentsImpl::OnRegisterIntentService(
1966 const webkit_glue::WebIntentServiceData& data,
1967 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431968 if (delegate_)
1969 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301970}
1971
[email protected]b172aee2012-04-10 17:05:261972void WebContentsImpl::OnWebIntentDispatch(
1973 const webkit_glue::WebIntentData& intent,
1974 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431975 if (!delegate_)
1976 return;
1977
[email protected]0d9989d2011-12-21 20:26:001978 WebIntentsDispatcherImpl* intents_dispatcher =
1979 new WebIntentsDispatcherImpl(this, intent, intent_id);
1980 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301981}
1982
[email protected]54047eb52012-05-08 21:45:571983void WebContentsImpl::DidStartProvisionalLoadForFrame(
1984 content::RenderViewHost* render_view_host,
1985 int64 frame_id,
1986 bool is_main_frame,
1987 const GURL& opener_url,
1988 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281989 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181990 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451991 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571992 content::RenderProcessHost* render_process_host =
1993 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541994 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571995 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451996 false,
[email protected]9f76c1e2012-03-05 15:15:581997 &validated_url);
[email protected]ef108e72012-06-20 14:03:541998 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571999 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452000 true,
2001 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:182002
[email protected]0d60f0192011-04-14 12:40:102003 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252004 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102005 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:572006 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:542007
2008 if (is_main_frame) {
2009 // Notify observers about the provisional change in the main frame URL.
2010 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2011 ProvisionalChangeToMainFrameUrl(validated_url,
2012 validated_opener_url,
2013 render_view_host));
2014 }
2015}
2016
2017void WebContentsImpl::DidRedirectProvisionalLoad(
2018 content::RenderViewHost* render_view_host,
2019 int32 page_id,
2020 const GURL& opener_url,
2021 const GURL& source_url,
2022 const GURL& target_url) {
2023 // TODO(creis): Remove this method and have the pre-rendering code listen to
2024 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2025 // instead. See http://crbug.com/78512.
2026 GURL validated_source_url(source_url);
2027 GURL validated_target_url(target_url);
2028 GURL validated_opener_url(opener_url);
2029 content::RenderProcessHost* render_process_host =
2030 render_view_host->GetProcess();
2031 RenderViewHostImpl::FilterURL(
2032 ChildProcessSecurityPolicyImpl::GetInstance(),
2033 render_process_host->GetID(),
2034 false,
2035 &validated_source_url);
2036 RenderViewHostImpl::FilterURL(
2037 ChildProcessSecurityPolicyImpl::GetInstance(),
2038 render_process_host->GetID(),
2039 false,
2040 &validated_target_url);
2041 RenderViewHostImpl::FilterURL(
2042 ChildProcessSecurityPolicyImpl::GetInstance(),
2043 render_process_host->GetID(),
2044 true,
2045 &validated_opener_url);
2046 NavigationEntry* entry;
2047 if (page_id == -1) {
2048 entry = controller_.GetPendingEntry();
2049 } else {
2050 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2051 page_id);
2052 }
2053 if (!entry || entry->GetURL() != validated_source_url)
2054 return;
2055
2056 // Notify observers about the provisional change in the main frame URL.
2057 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2058 ProvisionalChangeToMainFrameUrl(validated_target_url,
2059 validated_opener_url,
2060 render_view_host));
[email protected]724159a2010-12-30 01:11:182061}
2062
[email protected]54047eb52012-05-08 21:45:572063void WebContentsImpl::DidFailProvisionalLoadWithError(
2064 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582065 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2066 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2067 << ", error_code: " << params.error_code
2068 << ", error_description: " << params.error_description
2069 << ", is_main_frame: " << params.is_main_frame
2070 << ", showing_repost_interstitial: " <<
2071 params.showing_repost_interstitial
2072 << ", frame_id: " << params.frame_id;
2073 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:572074 content::RenderProcessHost* render_process_host =
2075 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542076 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572077 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452078 false,
[email protected]9f76c1e2012-03-05 15:15:582079 &validated_url);
[email protected]724159a2010-12-30 01:11:182080
[email protected]d7b175e2011-10-11 15:31:582081 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182082 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2083 // This means that the interstitial won't be torn down properly, which is
2084 // bad. But if we have an interstitial, go back to another tab type, and
2085 // then load the same interstitial again, we could end up getting the first
2086 // interstitial's "failed" message (as a result of the cancel) when we're on
2087 // the second one.
2088 //
2089 // We can't tell this apart, so we think we're tearing down the current page
2090 // which will cause a crash later one. There is also some code in
2091 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2092 // out because of this problem.
2093 //
2094 // http://code.google.com/p/chromium/issues/detail?id=2855
2095 // Because this will not tear down the interstitial properly, if "back" is
2096 // back to another tab type, the interstitial will still be somewhat alive
2097 // in the previous tab type. If you navigate somewhere that activates the
2098 // tab with the interstitial again, you'll see a flash before the new load
2099 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272100 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182101 LOG(WARNING) << "Discarding message during interstitial.";
2102 return;
2103 }
2104
[email protected]a16690732012-07-13 19:22:172105 // Do not clear the pending entry if one exists, so that the user's typed
2106 // URL is not lost when a navigation fails or is aborted. We'll allow
2107 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182108
[email protected]54047eb52012-05-08 21:45:572109 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182110 }
2111
[email protected]d8c660432011-12-22 20:51:252112 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582113 observers_,
2114 DidFailProvisionalLoad(params.frame_id,
2115 params.is_main_frame,
2116 validated_url,
2117 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462118 params.error_description,
2119 render_view_host));
[email protected]724159a2010-12-30 01:11:182120}
2121
[email protected]b172aee2012-04-10 17:05:262122void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182123 const GURL& url,
[email protected]70435962011-08-02 20:13:282124 const std::string& security_info,
2125 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182126 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282127 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192128 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182129 cache.Increment();
2130
2131 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082132 int cert_id = 0;
2133 net::CertStatus cert_status = 0;
2134 int security_bits = -1;
2135 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512136 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2137 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002138 content::LoadFromMemoryCacheDetails details(
2139 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2140 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182141
[email protected]ad50def52011-10-19 23:17:072142 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272143 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502144 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002145 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382149 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182150 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192151 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182152}
2153
[email protected]b172aee2012-04-10 17:05:262154void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022155 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232156 LOG(INFO) << security_origin << " ran insecure content from "
2157 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382158 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412159 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2160 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182161 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412162 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192163 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182164}
2165
[email protected]b172aee2012-04-10 17:05:262166void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182167 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252168 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472169 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182170}
2171
[email protected]b172aee2012-04-10 17:05:262172void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312173 int64 frame_id,
2174 const GURL& validated_url,
2175 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472177 DidFinishLoad(frame_id, validated_url, is_main_frame,
2178 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnDidFailLoadWithError(
2182 int64 frame_id,
2183 const GURL& validated_url,
2184 bool is_main_frame,
2185 int error_code,
2186 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252187 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312188 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472189 error_code, error_description,
2190 message_source_));
[email protected]724159a2010-12-30 01:11:182191}
2192
[email protected]b172aee2012-04-10 17:05:262193void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272194 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432195 if (delegate_)
2196 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172197}
2198
[email protected]b172aee2012-04-10 17:05:262199void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262200 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232201 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252202 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262203 if (!entry)
2204 return;
2205 // Note that we don't call NavigationController::GotToOffset() as we don't
2206 // want to create a pending navigation entry (it might end up lingering
2207 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252208 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582209 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512210 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582211 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472212 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572213
2214 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2215 // it in now that we know. This allows us to find the entry when it commits.
2216 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232217 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332218 entry->set_site_instance(
2219 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572220 }
[email protected]216813952011-05-19 22:21:262221 }
2222}
2223
[email protected]b172aee2012-04-10 17:05:262224void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2225 int maximum_percent,
2226 bool remember) {
[email protected]216813952011-05-19 22:21:262227 minimum_zoom_percent_ = minimum_percent;
2228 maximum_zoom_percent_ = maximum_percent;
2229 temporary_zoom_settings_ = !remember;
2230}
2231
[email protected]20b433a2012-05-15 21:23:462232void WebContentsImpl::OnSaveURL(const GURL& url,
2233 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482234 download_stats::RecordDownloadSource(
2235 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262236 // Check if the URL to save matches the URL of the main frame. Since this
2237 // message originates from Pepper plugins, it may not be the case if the
2238 // plugin is an embedded element.
2239 GURL main_frame_url = GetURL();
2240 if (!main_frame_url.is_valid())
2241 return;
2242 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462243 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnEnumerateDirectory(int request_id,
2247 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432248 if (!delegate_)
2249 return;
2250
[email protected]b9535422012-02-09 01:47:592251 ChildProcessSecurityPolicyImpl* policy =
2252 ChildProcessSecurityPolicyImpl::GetInstance();
2253 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2254 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432258 if (delegate_)
2259 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202260}
2261
[email protected]b172aee2012-04-10 17:05:262262void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2263 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362264 const string16& title,
2265 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432266 if (!delegate_)
2267 return;
2268
[email protected]b9535422012-02-09 01:47:592269 ChildProcessSecurityPolicyImpl* policy =
2270 ChildProcessSecurityPolicyImpl::GetInstance();
2271 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2272 return;
[email protected]3a3b75a2012-06-01 08:38:362273 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202274}
2275
[email protected]b172aee2012-04-10 17:05:262276void WebContentsImpl::OnFindReply(int request_id,
2277 int number_of_matches,
2278 const gfx::Rect& selection_rect,
2279 int active_match_ordinal,
2280 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432281 if (delegate_) {
2282 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2283 active_match_ordinal, final_update);
2284 }
[email protected]b888919c2011-09-02 00:32:162285}
2286
[email protected]59363fc92012-09-05 03:46:312287#if defined(OS_ANDROID)
2288void WebContentsImpl::OnFindMatchRectsReply(
2289 int version,
2290 const std::vector<gfx::RectF>& rects,
2291 const gfx::RectF& active_rect) {
2292 if (delegate_)
2293 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2294}
2295#endif
2296
[email protected]b172aee2012-04-10 17:05:262297void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2299 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452300}
2301
[email protected]b172aee2012-04-10 17:05:262302void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2303 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102304 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252305 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102306 AppCacheAccessed(manifest_url, blocked_by_policy));
2307}
2308
[email protected]b172aee2012-04-10 17:05:262309void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322310 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432311 color_chooser_ = delegate_ ?
2312 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202313}
2314
[email protected]b172aee2012-04-10 17:05:262315void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202316 if (color_chooser_ &&
2317 color_chooser_id == color_chooser_->identifier())
2318 color_chooser_->End();
2319}
2320
[email protected]b172aee2012-04-10 17:05:262321void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322322 SkColor color) {
[email protected]da8543762012-03-20 08:52:202323 if (color_chooser_ &&
2324 color_chooser_id == color_chooser_->identifier())
2325 color_chooser_->SetSelectedColor(color);
2326}
2327
[email protected]9f2a9d72012-04-16 16:02:222328void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2329 const FilePath& path,
2330 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442331 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2332 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292333}
2334
[email protected]d0759f492012-04-19 22:50:502335// This exists for render views that don't have a WebUI, but do have WebUI
2336// bindings enabled.
2337void WebContentsImpl::OnWebUISend(const GURL& source_url,
2338 const std::string& name,
2339 const base::ListValue& args) {
2340 if (delegate_)
2341 delegate_->WebUISend(this, source_url, name, args);
2342}
2343
[email protected]d8415ad92012-08-23 14:40:502344void WebContentsImpl::OnRequestPpapiBrokerPermission(
2345 int request_id,
2346 const GURL& url,
2347 const FilePath& plugin_path) {
2348 base::Callback<void(bool)> callback =
2349 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2350 base::Unretained(this), request_id);
2351 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2352 WebContentsObserver* observer;
2353 while ((observer = it.GetNext()) != NULL) {
2354 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2355 callback))
2356 return;
2357 }
2358
2359 // Fall back to allowing the request if no observer handled it.
2360 OnPpapiBrokerPermissionResult(request_id, true);
2361}
2362
2363void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2364 bool result) {
2365 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2366 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2367 request_id,
2368 result));
2369}
2370
[email protected]92a01cc2012-09-29 14:13:592371void WebContentsImpl::OnBrowserPluginNavigateGuest(
2372 int instance_id,
2373 const std::string& src,
2374 const BrowserPluginHostMsg_ResizeGuest_Params& resize_params) {
[email protected]7a846df2012-09-20 19:17:392375 // This is the first 'navigate' to a browser plugin, before WebContents has/is
2376 // an 'Embedder'; subsequent navigate messages for this WebContents will
2377 // be handled by the BrowserPluginEmbedderHelper of the embedder itself (this
2378 // also means any message from browser plugin renderer prior to NavigateGuest
2379 // which is not NavigateGuest will be ignored). Therefore
2380 // |browser_plugin_embedder_| should not be set.
2381 // For more info, see comment above classes BrowserPluginEmbedder and
2382 // BrowserPluginGuest.
2383 CHECK(!browser_plugin_embedder_.get());
2384
2385 browser_plugin_embedder_.reset(
2386 content::BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
2387 browser_plugin_embedder_->NavigateGuest(GetRenderViewHost(),
2388 instance_id,
[email protected]7a846df2012-09-20 19:17:392389 src,
[email protected]92a01cc2012-09-29 14:13:592390 resize_params);
[email protected]7a846df2012-09-20 19:17:392391}
2392
[email protected]96d185d2009-04-24 03:28:542393// Notifies the RenderWidgetHost instance about the fact that the page is
2394// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262395void WebContentsImpl::SetIsLoading(bool is_loading,
2396 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542397 if (is_loading == is_loading_)
2398 return;
2399
2400 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212401 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542402 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562403 upload_size_ = 0;
2404 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542405 }
2406
2407 render_manager_.SetIsLoading(is_loading);
2408
2409 is_loading_ = is_loading;
2410 waiting_for_response_ = is_loading;
2411
[email protected]6ebdc9b2010-09-27 16:55:572412 if (delegate_)
2413 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462414 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542415
[email protected]432115822011-07-10 15:52:272416 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2417 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072418 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542419 if (details)
[email protected]6c2381d2011-10-19 02:52:532420 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072421 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502422 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542423 det);
2424}
2425
[email protected]b172aee2012-04-10 17:05:262426void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132427 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322428 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562429 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382430 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442431 // that opened the window, as long as both renderers have the same
2432 // privileges.
[email protected]1fd1a502011-03-30 16:55:562433 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562434 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582435 // web_ui might be NULL if the URL refers to a non-existent extension.
2436 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402437 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522438 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442439 }
2440 }
[email protected]1fd1a502011-03-30 16:55:562441 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442442 }
2443
[email protected]4e697b042011-07-08 06:44:562444 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322445 // Clear the status bubble. This is a workaround for a bug where WebKit
2446 // doesn't let us know that the cursor left an element during a
2447 // transition (this is also why the mouse cursor remains as a hand after
2448 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2449 // clear the bubble when a user navigates to a named anchor in the same
2450 // page.
[email protected]36fc0392011-12-25 03:59:512451 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322452 }
2453
[email protected]a6e82fc2010-02-24 22:28:142454 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472455 // Once the main frame is navigated, we're no longer considered to have
2456 // displayed insecure content.
2457 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172458 }
[email protected]ce5c4502009-05-06 16:46:112459
[email protected]3c9e1872010-11-18 16:17:492460 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042462 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322463}
2464
[email protected]b172aee2012-04-10 17:05:262465void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322466 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132467 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322468 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062469 // If we navigate off the page, reset JavaScript state. This does nothing
2470 // to prevent a malicious script from spamming messages, since the script
2471 // could just reload the page to stop blocking.
2472 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552473 dialog_creator_->ResetJavaScriptState(this);
2474 dialog_creator_ = NULL;
2475 }
[email protected]420ae012009-04-24 05:16:322476
[email protected]3c9e1872010-11-18 16:17:492477 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252478 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042479 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322480}
2481
[email protected]b172aee2012-04-10 17:05:262482void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462483 // If we are creating a RVH for a restored controller, then we need to make
2484 // sure the RenderView starts with a next_page_id_ larger than the number
2485 // of restored entries. This must be called before the RenderView starts
2486 // navigating (to avoid a race between the browser updating max_page_id and
2487 // the renderer updating next_page_id_). Because of this, we only call this
2488 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562489 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582490 if (max_restored_page_id >
2491 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2492 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2493 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322494}
2495
[email protected]b172aee2012-04-10 17:05:262496bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2497 const string16& title) {
[email protected]420ae012009-04-24 05:16:322498 // For file URLs without a title, use the pathname instead. In the case of a
2499 // synthesized title, we don't want the update to count toward the "one set
2500 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512501 string16 final_title;
[email protected]420ae012009-04-24 05:16:322502 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512503 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2504 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322505 explicit_set = false; // Don't count synthetic titles toward the set limit.
2506 } else {
[email protected]acafd272011-07-26 17:35:572507 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322508 explicit_set = true;
2509 }
2510
[email protected]987fc3a2011-05-26 14:18:092511 // If a page is created via window.open and never navigated,
2512 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552513 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092514 if (entry) {
[email protected]36fc0392011-12-25 03:59:512515 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092516 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322517
[email protected]36fc0392011-12-25 03:59:512518 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092519 } else {
2520 if (page_title_when_no_navigation_entry_ == final_title)
2521 return false; // Nothing changed, don't bother.
2522
2523 page_title_when_no_navigation_entry_ = final_title;
2524 }
[email protected]420ae012009-04-24 05:16:322525
[email protected]420ae012009-04-24 05:16:322526 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232527 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322528
[email protected]2bb171882012-03-07 02:09:462529 std::pair<content::NavigationEntry*, bool> details =
2530 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142531
[email protected]ad50def52011-10-19 23:17:072532 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442533 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2534 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462535 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042536
[email protected]420ae012009-04-24 05:16:322537 return true;
2538}
2539
[email protected]b172aee2012-04-10 17:05:262540void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322541 // After sending out a swap notification, we need to send a disconnect
2542 // notification so that clients that pick up a pointer to |this| can NULL the
2543 // pointer. See Bug 1230284.
2544 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072545 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202546 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2547 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072548 content::NotificationService::NoDetails());
[email protected]7a846df2012-09-20 19:17:392549
2550 // Ensure that the associated embedder gets cleared after a RenderViewHost
2551 // gets swapped, so we don't reuse the same embedder next time a
2552 // RenderViewHost is attached to this WebContents.
2553 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322554}
2555
[email protected]b172aee2012-04-10 17:05:262556void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322557 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072558 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122559 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2560 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072561 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322562}
2563
[email protected]b172aee2012-04-10 17:05:262564void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322565 if (!notify_disconnection_)
2566 return;
2567
2568 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072569 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322570 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2571 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072572 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322573}
2574
[email protected]5a3bdf52012-05-24 15:12:572575RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2576 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322577}
2578
[email protected]8d3347f2009-07-09 22:00:212579RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262580WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212581 return &render_manager_;
2582}
2583
[email protected]b172aee2012-04-10 17:05:262584content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372585 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462586 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512587}
2588
[email protected]b172aee2012-04-10 17:05:262589WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172590 return this;
2591}
2592
[email protected]b172aee2012-04-10 17:05:262593gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172594 if (delegate_)
2595 return delegate_->GetRootWindowResizerRect();
2596 return gfx::Rect();
2597}
2598
[email protected]7a846df2012-09-20 19:17:392599void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2600 if (browser_plugin_embedder_.get())
2601 browser_plugin_embedder_.reset();
2602}
2603
[email protected]b172aee2012-04-10 17:05:262604void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442605 // Don't send notifications if we are just creating a swapped-out RVH for
2606 // the opener chain. These won't be used for view-source or WebUI, so it's
2607 // ok to return early.
2608 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2609 return;
2610
[email protected]ad50def52011-10-19 23:17:072611 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302612 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322613 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532614 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232615 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322616 if (!entry)
2617 return;
2618
2619 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352620 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562621 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582622 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322623
2624 if (entry->IsViewSourceMode()) {
2625 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182626 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582627 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322628 }
[email protected]0666aef2009-05-13 19:48:082629
[email protected]d487beefe2011-12-21 05:41:212630 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262631
2632 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252633 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322634}
2635
[email protected]b172aee2012-04-10 17:05:262636void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522637 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322638 // Don't notify the world, since this came from a renderer in the
2639 // background.
2640 return;
2641 }
2642
2643 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312644 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232645 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302646
2647 // Restore the focus to the tab (otherwise the focus will be on the top
2648 // window).
[email protected]484ae5912010-09-29 19:16:142649 if (was_crashed && !FocusLocationBarByDefault() &&
2650 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302651 Focus();
[email protected]484ae5912010-09-29 19:16:142652 }
[email protected]32ded2212011-11-10 18:51:432653
[email protected]d8c660432011-12-22 20:51:252654 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322655}
2656
[email protected]b172aee2012-04-10 17:05:262657void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2658 base::TerminationStatus status,
2659 int error_code) {
[email protected]151a63d2011-12-20 22:32:522660 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322661 // The pending page's RenderViewHost is gone.
2662 return;
2663 }
2664
2665 SetIsLoading(false, NULL);
2666 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232667 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312668 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322669
[email protected]d8c660432011-12-22 20:51:252670 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272671 observers_,
[email protected]be1f56ab2011-12-22 06:55:312672 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322673}
2674
[email protected]b172aee2012-04-10 17:05:262675void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482676 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252677 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062678}
2679
[email protected]b172aee2012-04-10 17:05:262680void WebContentsImpl::DidNavigate(
2681 RenderViewHost* rvh,
2682 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582683 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322684 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372685
[email protected]434f69f2012-02-06 21:56:522686 // Update the site of the SiteInstance if it doesn't have one yet, unless
2687 // this is for about:blank. In that case, the SiteInstance can still be
2688 // considered unused until a navigation to a real page.
2689 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2690 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332691 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522692 }
[email protected]420ae012009-04-24 05:16:322693
2694 // Need to update MIME type here because it's referred to in
2695 // UpdateNavigationCommands() called by RendererDidNavigate() to
2696 // determine whether or not to enable the encoding menu.
2697 // It's updated only for the main frame. For a subframe,
2698 // RenderView::UpdateURL does not set params.contents_mime_type.
2699 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2700 // TODO(jungshik): Add a test for the encoding menu to avoid
2701 // regressing it again.
[email protected]2905f742011-10-13 03:51:582702 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322703 contents_mime_type_ = params.contents_mime_type;
2704
[email protected]8286f51a2011-05-31 17:39:132705 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002706 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392707
[email protected]a9c0bfe2010-09-17 08:35:222708 // Send notification about committed provisional loads. This notification is
2709 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2710 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082711 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072712 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2713 // that is not recorded in the navigation history. For the purpose of
2714 // tracking navigation events, we treat this event as a sub frame navigation
2715 // event.
2716 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582717 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222718 // Whether or not a page transition was triggered by going backward or
2719 // forward in the history is only stored in the navigation controller's
2720 // entry list.
2721 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512722 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582723 content::PAGE_TRANSITION_FORWARD_BACK)) {
2724 transition_type = content::PageTransitionFromInt(
2725 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222726 }
[email protected]0d60f0192011-04-14 12:40:102727 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102729 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462730 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222731 }
2732
[email protected]76543b92009-08-31 17:27:452733 if (!did_navigate)
2734 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322735
2736 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2737 // for the appropriate notification (best) or you can add it to
2738 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2739 // necessary, please).
2740
2741 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002742 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322743 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512744 if (delegate_)
2745 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002746 }
[email protected]420ae012009-04-24 05:16:322747 DidNavigateAnyFramePostCommit(rvh, details, params);
2748}
2749
[email protected]b172aee2012-04-10 17:05:262750void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2751 int32 page_id,
2752 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152753 // Ensure that this state update comes from either the active RVH or one of
2754 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522755 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322756
2757 // We must be prepared to handle state updates for any page, these occur
2758 // when the user is scrolling and entering form data, as well as when we're
2759 // leaving a page, in which case our state may have already been moved to
2760 // the next page. The navigation controller will look up the appropriate
2761 // NavigationEntry and update it when it is notified via the delegate.
2762
2763 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582764 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322765 if (entry_index < 0)
2766 return;
[email protected]10f417c52011-12-28 21:04:232767 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322768
[email protected]36fc0392011-12-25 03:59:512769 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322770 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512771 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322772 controller_.NotifyEntryChanged(entry, entry_index);
2773}
2774
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2776 int32 page_id,
2777 const string16& title,
2778 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322779 // If we have a title, that's a pretty good indication that we've started
2780 // getting useful data.
2781 SetNotWaitingForResponse();
2782
[email protected]73eb2602012-02-09 19:50:552783 // Try to find the navigation entry, which might not be the current one.
2784 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232785 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582786 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092787
[email protected]73eb2602012-02-09 19:50:552788 // We can handle title updates when we don't have an entry in
2789 // UpdateTitleForEntry, but only if the update is from the current RVH.
2790 if (!entry && rvh != GetRenderViewHost())
2791 return;
2792
[email protected]a49e10b2011-08-01 23:57:462793 // TODO(evan): make use of title_direction.
2794 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092795 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322796 return;
2797
2798 // Broadcast notifications when the UI should be updated.
2799 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462800 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2804 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312805 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322806}
2807
[email protected]b172aee2012-04-10 17:05:262808void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512809 if (delegate_)
2810 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322811}
2812
[email protected]b172aee2012-04-10 17:05:262813void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292814 // The UI may be in an event-tracking loop, such as between the
2815 // mouse-down and mouse-up in text selection or a button click.
2816 // Defer the close until after tracking is complete, so that we
2817 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292818 // TODO(shess): This could get more fine-grained. For instance,
2819 // closing a tab in another window while selecting text in the
2820 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212821 if (GetView()->IsEventTracking()) {
2822 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292823 return;
2824 }
2825
[email protected]420ae012009-04-24 05:16:322826 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522827 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512828 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322829}
2830
[email protected]b172aee2012-04-10 17:05:262831void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522832 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512833 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572834}
2835
[email protected]b172aee2012-04-10 17:05:262836void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512837 if (delegate_ && delegate_->IsPopupOrPanel(this))
2838 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322839}
2840
[email protected]89793072012-07-23 22:25:292841void WebContentsImpl::DidStartLoading(
2842 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322843 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492844
[email protected]82114f52012-03-20 22:53:412845 if (delegate_ && content_restrictions_)
2846 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492847
2848 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292849 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2850 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322851}
2852
[email protected]89793072012-07-23 22:25:292853void WebContentsImpl::DidStopLoading(
2854 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322855 scoped_ptr<LoadNotificationDetails> details;
2856
[email protected]10f417c52011-12-28 21:04:232857 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322858 // An entry may not exist for a stop when loading an initial blank page or
2859 // if an iframe injected by script into a blank page finishes loading.
2860 if (entry) {
[email protected]420ae012009-04-24 05:16:322861 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2862
2863 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512864 entry->GetVirtualURL(),
2865 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322866 elapsed,
2867 &controller_,
2868 controller_.GetCurrentEntryIndex()));
2869 }
2870
[email protected]420ae012009-04-24 05:16:322871 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492872
2873 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292874 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2875 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322876}
2877
[email protected]b172aee2012-04-10 17:05:262878void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162879 controller_.DiscardNonCommittedEntries();
2880
2881 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462882 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162883}
2884
[email protected]b172aee2012-04-10 17:05:262885void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512886 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132887 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402888}
2889
[email protected]0720b532012-08-28 19:23:372890void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2891 render_manager_.DidUpdateFrameTree(rvh);
2892}
2893
[email protected]87717d0e2012-04-26 02:58:432894void WebContentsImpl::DocumentAvailableInMainFrame(
2895 RenderViewHost* render_view_host) {
2896 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2897 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102898}
2899
[email protected]b172aee2012-04-10 17:05:262900void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082901 RenderViewHost* render_view_host,
2902 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072903 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272904 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322905 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532906 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082907}
2908
[email protected]196159d2012-05-04 17:26:542909void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2910 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262911 const content::Referrer& referrer,
2912 WindowOpenDisposition disposition,
2913 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542914 // If this came from a swapped out RenderViewHost, we only allow the request
2915 // if we are still in the same BrowsingInstance.
2916 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2917 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2918 return;
2919 }
2920
[email protected]4ad5d77d2011-12-03 02:00:482921 // Delegate to RequestTransferURL because this is just the generic
2922 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582923 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482924 GlobalRequestID());
2925}
2926
[email protected]b172aee2012-04-10 17:05:262927void WebContentsImpl::RequestTransferURL(
2928 const GURL& url,
2929 const content::Referrer& referrer,
2930 WindowOpenDisposition disposition,
2931 int64 source_frame_id,
2932 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202933 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582934 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582935 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352936 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322937 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2938 // generated suggestions).
2939 //
[email protected]e0112912011-02-02 22:54:352940 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162941 // want web sites to see a referrer of "chrome://blah" (and some
2942 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322943 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432944 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222945 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482946 false /* is_renderer_initiated */);
2947 params.transferred_global_request_id = old_request_id;
2948 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222949 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322950 } else {
[email protected]6bf6a6b52012-02-03 15:41:432951 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482952 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2953 params.transferred_global_request_id = old_request_id;
2954 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582955 }
2956 if (new_contents) {
2957 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582959 DidOpenRequestedURL(new_contents,
2960 url,
2961 referrer,
2962 disposition,
2963 transition_type,
2964 source_frame_id));
[email protected]420ae012009-04-24 05:16:322965 }
2966}
2967
[email protected]e1c3a552012-05-04 20:51:322968void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2969 // Tell the active RenderViewHost to run unload handlers and close, as long
2970 // as the request came from a RenderViewHost in the same BrowsingInstance.
2971 // In most cases, we receive this from a swapped out RenderViewHost.
2972 // It is possible to receive it from one that has just been swapped in,
2973 // in which case we might as well deliver the message anyway.
2974 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2975 GetRenderViewHost()->ClosePage();
2976}
2977
[email protected]f546640b2012-05-15 00:03:492978void WebContentsImpl::RouteMessageEvent(
2979 RenderViewHost* rvh,
2980 const ViewMsg_PostMessage_Params& params) {
2981 // Only deliver the message to the active RenderViewHost if the request
2982 // came from a RenderViewHost in the same BrowsingInstance.
2983 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2984 return;
2985
2986 ViewMsg_PostMessage_Params new_params(params);
2987
[email protected]0720b532012-08-28 19:23:372988 // If the renderer has changed while the post message is being routed,
2989 // drop the message, as it will not be delivered to the right target.
2990 if (GetRenderViewHost()->GetProcess()->GetID() != params.target_process_id)
2991 return;
2992 DCHECK(params.target_frame_id != 0);
2993
[email protected]f546640b2012-05-15 00:03:492994 // If there is a source_routing_id, translate it to the routing ID for
2995 // the equivalent swapped out RVH in the target process. If we need
2996 // to create a swapped out RVH for the source tab, we create its opener
2997 // chain as well, since those will also be accessible to the target page.
2998 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2999 // Try to look up the WebContents for the source page.
3000 WebContentsImpl* source_contents = NULL;
3001 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3002 rvh->GetProcess()->GetID(), params.source_routing_id);
3003 if (source_rvh) {
3004 source_contents = static_cast<WebContentsImpl*>(
3005 source_rvh->GetDelegate()->GetAsWebContents());
3006 }
3007
3008 if (source_contents) {
3009 new_params.source_routing_id =
3010 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3011 } else {
3012 // We couldn't find it, so don't pass a source frame.
3013 new_params.source_routing_id = MSG_ROUTING_NONE;
3014 }
3015 }
3016
3017 // In most cases, we receive this from a swapped out RenderViewHost.
3018 // It is possible to receive it from one that has just been swapped in,
3019 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183020 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493021}
3022
[email protected]b172aee2012-04-10 17:05:263023void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343024 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413025 const string16& message,
3026 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323027 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:143028 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323029 IPC::Message* reply_msg,
3030 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073031 // Suppress JavaScript dialogs when requested. Also suppress messages when
3032 // showing an interstitial as it's shown over the previous page and we don't
3033 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503034 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583035 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273036 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073037 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523038 delegate_->ShouldSuppressDialogs() ||
3039 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323040
3041 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:433042 std::string accept_lang = content::GetContentClient()->browser()->
3043 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553044 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523045 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433046 this,
3047 frame_url.GetOrigin(),
3048 accept_lang,
3049 javascript_message_type,
3050 message,
[email protected]51da7e32012-01-30 19:24:523051 default_prompt,
[email protected]b172aee2012-04-10 17:05:263052 base::Bind(&WebContentsImpl::OnDialogClosed,
3053 base::Unretained(this),
3054 rvh,
3055 reply_msg),
[email protected]51da7e32012-01-30 19:24:523056 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323057 }
[email protected]3ab9cb82011-06-03 18:02:073058
3059 if (suppress_this_message) {
3060 // If we are suppressing messages, just reply as if the user immediately
3061 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343062 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073063 }
3064
3065 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323066}
3067
[email protected]b172aee2012-04-10 17:05:263068void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3069 const string16& message,
3070 bool is_reload,
3071 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583072 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513073 if (delegate_)
3074 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073075
3076 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583077 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073078 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523079 delegate_->ShouldSuppressDialogs() ||
3080 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153081 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343082 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583083 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503084 return;
3085 }
[email protected]3ab9cb82011-06-03 18:02:073086
[email protected]7ab1e7d62009-10-14 23:32:013087 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553088 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523089 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323090 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263091 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523092 reply_msg));
[email protected]420ae012009-04-24 05:16:323093}
3094
[email protected]a796f202012-05-30 14:14:253095bool WebContentsImpl::AddMessageToConsole(int32 level,
3096 const string16& message,
3097 int32 line_no,
3098 const string16& source_id) {
3099 if (!delegate_)
3100 return false;
3101 return delegate_->AddMessageToConsole(this, level, message, line_no,
3102 source_id);
3103}
3104
[email protected]b172aee2012-04-10 17:05:263105WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333106 // We want to base the page config off of the real URL, rather than the
3107 // display URL.
3108 GURL url = controller_.GetActiveEntry()
3109 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3110 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273114 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253115 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223116
[email protected]ea114722012-03-12 01:11:253117 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173118 if (rdh) // NULL in unittests.
3119 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253120}
3121
[email protected]b172aee2012-04-10 17:05:263122void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443123 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253124 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443125}
3126
[email protected]b172aee2012-04-10 17:05:263127void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3128 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153129 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523130 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153131 return;
3132
[email protected]9f76c1e2012-03-05 15:15:583133 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3134
[email protected]e5fc1632011-08-08 07:51:533135 // Ignore renderer unresponsive event if debugger is attached to the tab
3136 // since the event may be a result of the renderer sitting on a breakpoint.
3137 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443138 DevToolsAgentHost* agent =
3139 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3140 if (agent &&
3141 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533142 return;
3143
[email protected]420ae012009-04-24 05:16:323144 if (is_during_unload) {
3145 // Hang occurred while firing the beforeunload/unload handler.
3146 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583147 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323148
3149 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3150 return;
3151
3152 // If the tab hangs in the beforeunload/unload handler there's really
3153 // nothing we can do to recover. Pretend the unload listeners have
3154 // all fired and close the tab. If the hang is in the beforeunload handler
3155 // then the user will not have the option of cancelling the close.
3156 Close(rvh);
3157 return;
3158 }
3159
[email protected]9f76c1e2012-03-05 15:15:583160 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473161 return;
3162
[email protected]6934a702011-12-20 00:04:513163 if (delegate_)
3164 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323165}
3166
[email protected]b172aee2012-04-10 17:05:263167void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513168 if (delegate_)
3169 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323170}
3171
[email protected]b172aee2012-04-10 17:05:263172void WebContentsImpl::LoadStateChanged(
3173 const GURL& url,
3174 const net::LoadStateWithParam& load_state,
3175 uint64 upload_position,
3176 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323177 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563178 upload_position_ = upload_position;
3179 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503180 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203181 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303182 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213183 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323184 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463185 if (IsLoading()) {
3186 NotifyNavigationStateChanged(
3187 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3188 }
[email protected]420ae012009-04-24 05:16:323189}
3190
[email protected]b172aee2012-04-10 17:05:263191void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513192 if (delegate_)
3193 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253194}
3195
[email protected]b172aee2012-04-10 17:05:263196void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553197 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323198 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553199 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513200 if (delegate_)
3201 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323202}
3203
[email protected]b172aee2012-04-10 17:05:263204void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543205 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233206 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3207 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543208}
3209
[email protected]b172aee2012-04-10 17:05:263210void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103211 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263212 gfx::Size size = view_->GetContainerSize();
3213 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3214 // here during container initialization and normal window size will be set
3215 // later. In case of tab duplication this resizing to 0x0 prevents setting
3216 // normal size later so just ignore it.
3217 if (!size.IsEmpty())
3218 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323219}
3220
[email protected]b172aee2012-04-10 17:05:263221void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543222 NotifySwapped();
3223}
3224
[email protected]14392a52012-05-02 20:28:443225int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3226 SiteInstance* instance) {
3227 if (!opener_)
3228 return MSG_ROUTING_NONE;
3229
3230 // Recursively create RenderViews for anything else in the opener chain.
3231 return opener_->CreateOpenerRenderViews(instance);
3232}
3233
3234int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3235 int opener_route_id = MSG_ROUTING_NONE;
3236
3237 // If this tab has an opener, ensure it has a RenderView in the given
3238 // SiteInstance as well.
3239 if (opener_)
3240 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3241
[email protected]0720b532012-08-28 19:23:373242 // If any of the renderers for this WebContents has the same SiteInstance,
3243 // use it.
3244 if (render_manager_.current_host()->GetSiteInstance() == instance)
3245 return render_manager_.current_host()->GetRoutingID();
3246
3247 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3248 instance);
3249 if (rvh)
3250 return rvh->GetRoutingID();
3251
[email protected]14392a52012-05-02 20:28:443252 // Create a swapped out RenderView in the given SiteInstance if none exists,
3253 // setting its opener to the given route_id. Return the new view's route_id.
3254 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3255}
3256
[email protected]b172aee2012-04-10 17:05:263257NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193258 return GetController();
[email protected]3a3d47472010-07-15 21:03:543259}
3260
[email protected]b172aee2012-04-10 17:05:263261WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563262 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323263}
3264
[email protected]10f417c52011-12-28 21:04:233265NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263266 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323267 return controller_.GetLastCommittedEntry();
3268}
3269
[email protected]b172aee2012-04-10 17:05:263270bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443271 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443272 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323273 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523274
[email protected]420ae012009-04-24 05:16:323275 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443276 if (rwh_view)
3277 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323278
[email protected]74ce1ad2011-12-16 21:51:463279 // Make sure we use the correct starting page_id in the new RenderView.
3280 UpdateMaxPageIDIfNecessary(render_view_host);
3281 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583282 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463283
[email protected]7900bfdb2012-05-24 19:31:243284 std::string embedder_channel_name;
3285 int embedder_container_id;
3286 GetBrowserPluginEmbedderInfo(render_view_host,
3287 &embedder_channel_name,
3288 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583289 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493290 render_view_host)->CreateRenderView(string16(),
3291 opener_route_id,
3292 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243293 embedder_channel_name,
3294 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523295 return false;
[email protected]14392a52012-05-02 20:28:443296 }
[email protected]a4127722011-04-27 23:13:523297
[email protected]e60c0232011-11-11 19:56:353298#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503299 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3300 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443301 if (rwh_view) {
3302 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3303 render_widget_host->WasResized();
3304 }
[email protected]f8233cc2011-05-31 20:24:503305#endif
3306
[email protected]420ae012009-04-24 05:16:323307 return true;
3308}
3309
[email protected]b172aee2012-04-10 17:05:263310void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3311 IPC::Message* reply_msg,
3312 bool success,
3313 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543314 if (is_showing_before_unload_dialog_ && !success) {
3315 // If a beforeunload dialog is canceled, we need to stop the throbber from
3316 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293317 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353318 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543319
[email protected]3bbacc5b2012-04-17 17:46:153320 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553321 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543322 }
3323 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583324 static_cast<RenderViewHostImpl*>(
3325 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543326}
3327
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123329 encoding_ = content::GetContentClient()->browser()->
3330 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103331}
[email protected]f45d2a72010-03-08 23:28:353332
[email protected]b172aee2012-04-10 17:05:263333void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463334 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263335 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573336 DownloadManager* dlm =
3337 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143338 if (!dlm)
3339 return;
3340 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263341 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143342 const NavigationEntry* entry = controller_.GetActiveEntry();
3343 if (entry)
3344 post_id = entry->GetPostID();
3345 }
[email protected]29a5ffc82012-03-13 19:35:583346 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143347 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143348 scoped_ptr<DownloadUrlParameters> params(
3349 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493350 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143351 params->set_post_id(post_id);
3352 params->set_prefer_cache(true);
3353 if (post_id >= 0)
3354 params->set_method("POST");
3355 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143356}
3357
[email protected]b172aee2012-04-10 17:05:263358void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213359 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443360 // Can be NULL during tests.
3361 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213362 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363363}
[email protected]9f76c1e2012-03-05 15:15:583364
[email protected]b172aee2012-04-10 17:05:263365RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583366 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3367}
[email protected]7900bfdb2012-05-24 19:31:243368
3369void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3370 content::RenderViewHost* render_view_host,
3371 std::string* embedder_channel_name,
3372 int* embedder_container_id) {
3373 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283374 old_browser_plugin_host()->embedder_render_process_host();
3375 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243376 int embedder_process_id =
3377 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3378 if (embedder_process_id != -1) {
3379 *embedder_channel_name =
3380 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3381 embedder_process_id);
3382 }
3383}
[email protected]7a846df2012-09-20 19:17:393384
3385content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
3386 return browser_plugin_guest_.get();
3387}
3388
3389content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
3390 return browser_plugin_embedder_.get();
3391}