blob: 30d1190aa74d390e60804e765823eb62f95404a1 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]cc510d7e2012-08-08 04:40:1018#include "content/browser/browser_plugin/old/old_browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5919#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4420#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1921#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0422#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4623#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1224#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1625#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3226#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5427#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0528#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0029#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3030#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3231#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5032#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2533#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3334#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3735#include "content/browser/web_contents/interstitial_page_impl.h"
36#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5741#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5842#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1143#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2044#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4445#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4446#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1747#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1448#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4649#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1550#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0051#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2752#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0053#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3754#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1455#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3256#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3457#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3858#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4259#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2560#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1061#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5062#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2163#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4864#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1865#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5466#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0367#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1668#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2969#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5470#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3471#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3772#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5673#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4174#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0175#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4176#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5277#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2478#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3679#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3180#include "webkit/glue/webpreferences.h"
81
[email protected]f66df822012-05-18 16:52:1782#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5083#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4184#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5785#endif
[email protected]3e45ba92009-02-20 21:09:0086
[email protected]c71fe6402012-08-15 15:22:5587#if defined(USE_AURA) && defined(USE_X11)
88#include "ui/base/touch/touch_factory.h"
89#endif // defined (USE_AURA) && defined(USE_X11)
90
[email protected]420ae012009-04-24 05:16:3291// Cross-Site Navigations
92//
[email protected]b172aee2012-04-10 17:05:2693// If a WebContentsImpl is told to navigate to a different web site (as
94// determined by SiteInstance), it will replace its current RenderViewHost with
95// a new RenderViewHost dedicated to the new SiteInstance. This works as
96// follows:
[email protected]420ae012009-04-24 05:16:3297//
98// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4699// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32100// - The pending RVH is "suspended," so that no navigation messages are sent to
101// its renderer until the onbeforeunload JavaScript handler has a chance to
102// run in the current RVH.
103// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
104// that it has a pending cross-site request. ResourceDispatcherHost will
105// check for this when the response arrives.
106// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46107// cancel all the pending logic. Otherwise we allow the pending RVH to send
108// the navigation request to its renderer.
109// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
110// main resource load on the pending RVH. It checks CrossSiteRequestManager
111// to see that it is a cross-site request, and installs a
112// CrossSiteResourceHandler.
113// - When RDH receives a response, the BufferedResourceHandler determines
114// whether it is a download. If so, it sends a message to the new renderer
115// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26116// pending RVH remains until the next DidNavigate event for this
117// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32118// - After RDH receives a response and determines that it is safe and not a
119// download, it pauses the response to first run the old page's onunload
120// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26121// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32122// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15123// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32124// the ResourceDispatcherHost, who unpauses the response. Data is then sent
125// to the pending RVH.
126// - The pending renderer sends a FrameNavigate message that invokes the
127// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46128// pending RVH.
[email protected]992db4c2011-05-12 15:37:15129// - The previous renderer is kept swapped out in RenderViewHostManager in case
130// the user goes back. The process only stays live if another tab is using
131// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32132
[email protected]b441a8492012-06-06 14:55:57133using content::BrowserContext;
[email protected]0e12d7d2011-12-01 16:21:44134using content::DevToolsAgentHost;
135using content::DevToolsAgentHostRegistry;
136using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17137using content::DownloadItem;
138using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14139using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20140using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56141using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13142using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27143using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54144using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50145using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23146using content::NavigationEntry;
147using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20148using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11149using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57150using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57151using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27152using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11153using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50154using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58155using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04156using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25157using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14158using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43159using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33160using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38161using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09162using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25163using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56164using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22165using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50166using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25167using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44168
[email protected]420ae012009-04-24 05:16:32169namespace {
170
171// Amount of time we wait between when a key event is received and the renderer
172// is queried for its state and pushed to the NavigationEntry.
173const int kQueryStateDelay = 5000;
174
[email protected]6ebdc9b2010-09-27 16:55:57175const int kSyncWaitDelay = 40;
176
[email protected]82114f52012-03-20 22:53:41177const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05178
[email protected]420ae012009-04-24 05:16:32179#if defined(OS_WIN)
180
181BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
182 // Note: erase is required to properly paint some widgets borders. This can
183 // be seen with textfields.
184 InvalidateRect(hwnd, NULL, TRUE);
185 return TRUE;
186}
187#endif
188
[email protected]2c5569662011-03-22 20:45:02189ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23190 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50191 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16192 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47193 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47195 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23197 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
198 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47199 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16200 break; // Fall through to rest of function.
201 }
[email protected]5e369672009-11-03 23:48:30202
[email protected]59246c572012-02-10 13:32:13203 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
204 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23205 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13206 browser_context->DidLastSessionExitCleanly()) {
207 if (entry.GetHasPostData())
208 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02209 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13210 }
[email protected]5e369672009-11-03 23:48:30211
[email protected]2c5569662011-03-22 20:45:02212 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30213}
214
[email protected]10f417c52011-12-28 21:04:23215void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47216 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42217 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50218 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24219 const std::string& embedder_channel_name,
220 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16221 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51222 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54223 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55224 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
225 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36226 if (!entry.GetBaseURLForDataURL().is_empty()) {
227 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
228 params->history_url_for_data_url = entry.GetVirtualURL();
229 }
[email protected]36fc0392011-12-25 03:59:51230 params->referrer = entry.GetReferrer();
231 params->transition = entry.GetTransitionType();
232 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00233 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55234 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34235 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47236 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48237 params->transferred_request_child_id =
238 entry.transferred_global_request_id().child_id;
239 params->transferred_request_request_id =
240 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22241 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00242 // Avoid downloading when in view-source mode.
243 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24244 params->embedder_channel_name = embedder_channel_name;
245 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44246 params->is_post = entry.GetHasPostData();
247 if(entry.GetBrowserInitiatedPostData()) {
248 params->browser_initiated_post_data.assign(
249 entry.GetBrowserInitiatedPostData()->front(),
250 entry.GetBrowserInitiatedPostData()->front() +
251 entry.GetBrowserInitiatedPostData()->size());
252
253 }
[email protected]6c6b02d2011-09-02 03:36:47254
[email protected]7c16976c2012-08-04 02:38:23255 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
256 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
257 // We may have been redirected when navigating to the current URL.
258 // Use the URL the user originally intended to visit, if it's valid and if a
259 // POST wasn't involved; the latter case avoids issues with sending data to
260 // the wrong page.
261 params->url = entry.GetOriginalRequestURL();
262 } else {
263 params->url = entry.GetURL();
264 }
265
[email protected]6c6b02d2011-09-02 03:36:47266 if (delegate)
267 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34268}
269
[email protected]f98f5092012-05-19 00:08:14270int GetSwitchValueAsInt(
271 const CommandLine& command_line,
272 const std::string& switch_string,
273 int min_value) {
274 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
275 int int_value;
276 if (base::StringToInt(string_value, &int_value))
277 return std::max(min_value, int_value);
278 else
279 return min_value;
280}
281
[email protected]420ae012009-04-24 05:16:32282} // namespace
283
[email protected]a81343d232011-12-27 07:39:20284namespace content {
285
286WebContents* WebContents::Create(
287 BrowserContext* browser_context,
288 SiteInstance* site_instance,
289 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19290 const WebContents* base_web_contents) {
291 return WebContentsImpl::Create(
292 browser_context, site_instance, routing_id,
293 static_cast<const WebContentsImpl*>(base_web_contents));
294}
295
296WebContents* WebContents::CreateWithSessionStorage(
297 BrowserContext* browser_context,
298 SiteInstance* site_instance,
299 int routing_id,
[email protected]b172aee2012-04-10 17:05:26300 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19301 const SessionStorageNamespaceMap& session_storage_namespace_map) {
302 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
303
304 for (SessionStorageNamespaceMap::const_iterator it =
305 session_storage_namespace_map.begin();
306 it != session_storage_namespace_map.end();
307 ++it) {
308 new_contents->GetController().SetSessionStorageNamespace(it->first,
309 it->second);
310 }
311
312 new_contents->Init(browser_context, site_instance, routing_id,
313 static_cast<const WebContentsImpl*>(base_web_contents));
314 return new_contents;
[email protected]a81343d232011-12-27 07:39:20315}
[email protected]746d3052012-05-22 15:15:47316
[email protected]299d7f12012-05-23 05:31:15317WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47318 return rvh->GetDelegate()->GetAsWebContents();
319}
320
[email protected]a81343d232011-12-27 07:39:20321}
[email protected]f4f50ef2011-01-21 19:01:19322
[email protected]b172aee2012-04-10 17:05:26323// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32324
[email protected]b172aee2012-04-10 17:05:26325WebContentsImpl::WebContentsImpl(
326 content::BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19327 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42328 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19329 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57330 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44331 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05332 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34333 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23334 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
335 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34336 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21337 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56338 upload_size_(0),
339 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47340 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57341 capturing_contents_(false),
342 is_being_destroyed_(false),
343 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55344 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57345#if defined(OS_WIN)
346 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
347#endif
[email protected]7ab1e7d62009-10-14 23:32:01348 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56349 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38350 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25351 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01352 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25353 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01354 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00355 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43356 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20357 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35358}
initial.commit09911bf2008-07-26 23:55:29359
[email protected]b172aee2012-04-10 17:05:26360WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32361 is_being_destroyed_ = true;
362
[email protected]3ab9cb82011-06-03 18:02:07363 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55364 if (dialog_creator_)
365 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07366
[email protected]da8543762012-03-20 08:52:20367 if (color_chooser_)
368 color_chooser_->End();
369
[email protected]420ae012009-04-24 05:16:32370 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32371
[email protected]ca13a442012-04-17 14:00:12372 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07373 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09374 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
375 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32377
378 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07379#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32380 // If we still have a window handle, destroy it. GetNativeView can return
381 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42382 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52383 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58384 if (host && host->GetView())
385 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42386 }
[email protected]420ae012009-04-24 05:16:32387#endif
[email protected]7ab1e7d62009-10-14 23:32:01388
389 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15390 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01391 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15392 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01393 }
[email protected]b5a1d11c2011-02-17 03:09:42394
[email protected]2db9bd72012-04-13 20:20:56395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
397 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08398
[email protected]6934a702011-12-20 00:04:51399 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42400}
401
[email protected]d1198fd2012-08-13 22:50:19402WebContentsImpl* WebContentsImpl::Create(
403 BrowserContext* browser_context,
404 SiteInstance* site_instance,
405 int routing_id,
406 const WebContentsImpl* base_web_contents) {
407 return CreateWithOpener(browser_context, site_instance, routing_id,
408 base_web_contents, NULL);
409}
410
411WebContentsImpl* WebContentsImpl::CreateWithOpener(
412 BrowserContext* browser_context,
413 SiteInstance* site_instance,
414 int routing_id,
415 const WebContentsImpl* base_web_contents,
416 WebContentsImpl* opener) {
417 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
418
419 new_contents->Init(browser_context, site_instance, routing_id,
420 static_cast<const WebContentsImpl*>(base_web_contents));
421 return new_contents;
422}
423
[email protected]b172aee2012-04-10 17:05:26424WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
425 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54426 WebPreferences prefs;
427
428 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
429
430 prefs.developer_extras_enabled = true;
431 prefs.javascript_enabled =
432 !command_line.HasSwitch(switches::kDisableJavaScript);
433 prefs.web_security_enabled =
434 !command_line.HasSwitch(switches::kDisableWebSecurity);
435 prefs.plugins_enabled =
436 !command_line.HasSwitch(switches::kDisablePlugins);
437 prefs.java_enabled =
438 !command_line.HasSwitch(switches::kDisableJava);
439
440 prefs.uses_page_cache =
441 command_line.HasSwitch(switches::kEnableFastback);
442 prefs.remote_fonts_enabled =
443 !command_line.HasSwitch(switches::kDisableRemoteFonts);
444 prefs.xss_auditor_enabled =
445 !command_line.HasSwitch(switches::kDisableXSSAuditor);
446 prefs.application_cache_enabled =
447 !command_line.HasSwitch(switches::kDisableApplicationCache);
448
449 prefs.local_storage_enabled =
450 !command_line.HasSwitch(switches::kDisableLocalStorage);
451 prefs.databases_enabled =
452 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01453#if defined(OS_ANDROID)
454 prefs.webaudio_enabled =
455 command_line.HasSwitch(switches::kEnableWebAudio);
456#else
[email protected]64d69de42012-02-06 00:19:54457 prefs.webaudio_enabled =
458 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01459#endif
[email protected]64d69de42012-02-06 00:19:54460
461 prefs.experimental_webgl_enabled =
462 GpuProcessHost::gpu_enabled() &&
463 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07464#if defined(OS_ANDROID)
465 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
466#else
[email protected]64d69de42012-02-06 00:19:54467 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07468#endif
[email protected]64d69de42012-02-06 00:19:54469
[email protected]5a073092012-06-08 00:42:51470 prefs.flash_3d_enabled =
471 GpuProcessHost::gpu_enabled() &&
472 !command_line.HasSwitch(switches::kDisableFlash3d);
473 prefs.flash_stage3d_enabled =
474 GpuProcessHost::gpu_enabled() &&
475 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19476
[email protected]64d69de42012-02-06 00:19:54477 prefs.gl_multisampling_enabled =
478 !command_line.HasSwitch(switches::kDisableGLMultisampling);
479 prefs.privileged_webgl_extensions_enabled =
480 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
481 prefs.site_specific_quirks_enabled =
482 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
483 prefs.allow_file_access_from_file_urls =
484 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
485 prefs.show_composited_layer_borders =
486 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
487 prefs.show_composited_layer_tree =
488 command_line.HasSwitch(switches::kShowCompositedLayerTree);
489 prefs.show_fps_counter =
490 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19491 prefs.show_paint_rects =
492 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52493 prefs.render_vsync_enabled =
494 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54495 prefs.accelerated_compositing_enabled =
496 GpuProcessHost::gpu_enabled() &&
497 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54498 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23499 command_line.HasSwitch(switches::kForceCompositingMode) &&
500 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54501 prefs.fixed_position_compositing_enabled =
502 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
503 prefs.accelerated_2d_canvas_enabled =
504 GpuProcessHost::gpu_enabled() &&
505 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58506 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27507 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54508 prefs.accelerated_painting_enabled =
509 GpuProcessHost::gpu_enabled() &&
510 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
511 prefs.accelerated_filters_enabled =
512 GpuProcessHost::gpu_enabled() &&
513 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
514 prefs.accelerated_layers_enabled =
515 prefs.accelerated_animation_enabled =
516 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54517 prefs.accelerated_plugins_enabled =
518 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
519 prefs.accelerated_video_enabled =
520 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54521 prefs.fullscreen_enabled =
522 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16523 prefs.css_regions_enabled =
524 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29525 prefs.css_shaders_enabled =
526 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01527 prefs.css_variables_enabled =
528 command_line.HasSwitch(switches::kEnableCssVariables);
[email protected]a08412b62012-05-29 21:28:56529 prefs.device_supports_touch =
530 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]c71fe6402012-08-15 15:22:55531#if defined(USE_AURA) && defined(USE_X11)
532 prefs.device_supports_touch |=
533 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
534#endif
[email protected]d849b122012-07-18 07:35:26535#if defined(OS_ANDROID)
536 prefs.device_supports_mouse = false;
537#endif
[email protected]64d69de42012-02-06 00:19:54538
539#if defined(OS_MACOSX)
540 bool default_enable_scroll_animator = true;
541#else
542 // On CrOS, the launcher always passes in the --enable flag.
543 bool default_enable_scroll_animator = false;
544#endif
545 prefs.enable_scroll_animator = default_enable_scroll_animator;
546 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
547 prefs.enable_scroll_animator = true;
548 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
549 prefs.enable_scroll_animator = false;
550
551 prefs.visual_word_movement_enabled =
552 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54553
554 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32555 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54556 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11557 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
558 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54559 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11560 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54561 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19562 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
563 prefs.flash_3d_enabled = false;
564 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
565 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11566 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54567 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11568 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54569 prefs.gl_multisampling_enabled = false;
570
571 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45572 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32573 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54574 prefs.accelerated_video_enabled = false;
575 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45576 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09577 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54578 }
579 }
580
[email protected]b9535422012-02-09 01:47:59581 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58582 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54583 prefs.loads_images_automatically = true;
584 prefs.javascript_enabled = true;
585 }
586
587 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
588
589 // Force accelerated compositing and 2d canvas off for chrome:, about: and
590 // chrome-devtools: pages (unless it's specifically allowed).
591 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54592 url.SchemeIs(chrome::kChromeUIScheme) ||
593 (url.SchemeIs(chrome::kAboutScheme) &&
594 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25595 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54596 prefs.accelerated_compositing_enabled = false;
597 prefs.accelerated_2d_canvas_enabled = false;
598 }
[email protected]43d9d782012-03-01 15:40:09599
[email protected]f98f5092012-05-19 00:08:14600 if (command_line.HasSwitch(switches::kDefaultTileWidth))
601 prefs.default_tile_width =
602 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
603 if (command_line.HasSwitch(switches::kDefaultTileHeight))
604 prefs.default_tile_height =
605 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
606 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
607 prefs.max_untiled_layer_width =
608 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
609 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
610 prefs.max_untiled_layer_height =
611 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
612
[email protected]2486dce2012-05-23 17:18:19613 if (gfx::Screen::IsDIPEnabled()) {
614 // Only apply when using DIP coordinate system as this setting interferes
615 // with fixed layout mode.
616 prefs.apply_default_device_scale_factor_in_compositor = true;
617 }
618
[email protected]de023762012-07-26 17:10:17619 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
620 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10621
[email protected]6b4dcb072012-06-18 22:26:51622 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
623
[email protected]2e21fe292012-03-02 22:52:32624 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54625
626 return prefs;
627}
628
[email protected]b172aee2012-04-10 17:05:26629RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28630 return &render_manager_;
631}
632
[email protected]7bb761892012-07-20 09:32:47633bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
634 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56635 if (GetWebUI() &&
636 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17637 return true;
[email protected]d2353452012-01-19 19:53:56638 }
[email protected]f82d57b52011-04-27 19:13:17639
[email protected]d8c660432011-12-22 20:51:25640 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
641 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10642 while ((observer = it.GetNext()) != NULL)
643 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53644 return true;
[email protected]403415a2011-01-10 18:57:53645
[email protected]7bb761892012-07-20 09:32:47646 // Message handlers should be aware of which RenderViewHost sent the
647 // message, which is temporarily stored in message_source_.
648 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18649 bool handled = true;
650 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26651 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58652 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
653 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24654 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
655 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18656 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
657 OnDidLoadResourceFromMemoryCache)
658 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
659 OnDidDisplayInsecureContent)
660 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
661 OnDidRunInsecureContent)
662 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
663 OnDocumentLoadedInFrame)
664 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26665 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
666 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17667 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
668 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25669 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26670 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59671 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21672 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20673 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
674 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
675 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16676 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45677 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10678 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20679 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
681 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
682 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29683 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50684 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50685 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
686 OnRequestPpapiBrokerPermission)
[email protected]724159a2010-12-30 01:11:18687 IPC_MESSAGE_UNHANDLED(handled = false)
688 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47689 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18690
691 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38692 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18693 GetRenderProcessHost()->ReceivedBadMessage();
694 }
695
696 return handled;
697}
698
[email protected]b172aee2012-04-10 17:05:26699void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18700 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23701 const content::FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43702 if (delegate_)
703 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18704}
705
[email protected]d1198fd2012-08-13 22:50:19706NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56707 return controller_;
708}
709
[email protected]d1198fd2012-08-13 22:50:19710const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56711 return controller_;
712}
713
[email protected]b172aee2012-04-10 17:05:26714content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55715 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30716}
717
[email protected]b172aee2012-04-10 17:05:26718const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31719 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23720 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51721 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31722}
723
[email protected]b172aee2012-04-10 17:05:26724content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31725 return delegate_;
726}
727
[email protected]b172aee2012-04-10 17:05:26728void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31729 // TODO(cbentzel): remove this debugging code?
730 if (delegate == delegate_)
731 return;
732 if (delegate_)
733 delegate_->Detach(this);
734 delegate_ = delegate;
735 if (delegate_)
736 delegate_->Attach(this);
737}
738
[email protected]b172aee2012-04-10 17:05:26739content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41740 RenderViewHostImpl* host = render_manager_.current_host();
741 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16742}
743
[email protected]b172aee2012-04-10 17:05:26744RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31745 return render_manager_.current_host();
746}
747
[email protected]6b618e62012-08-16 12:59:18748int WebContentsImpl::GetRoutingID() const {
749 if (!GetRenderViewHost())
750 return MSG_ROUTING_NONE;
751
752 return GetRenderViewHost()->GetRoutingID();
753}
754
[email protected]b172aee2012-04-10 17:05:26755RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31756 return render_manager_.GetRenderWidgetHostView();
757}
758
[email protected]b172aee2012-04-10 17:05:26759content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31760 return view_.get();
761}
762
[email protected]b172aee2012-04-10 17:05:26763content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50764 WebUIControllerFactory* factory =
765 content::GetContentClient()->browser()->GetWebUIControllerFactory();
766 if (!factory)
767 return NULL;
[email protected]d2353452012-01-19 19:53:56768 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22769 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50770 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22771 if (controller) {
772 web_ui->SetController(controller);
773 return web_ui;
774 }
775
776 delete web_ui;
777 return NULL;
778}
779
[email protected]b172aee2012-04-10 17:05:26780content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31781 return render_manager_.web_ui() ? render_manager_.web_ui()
782 : render_manager_.pending_web_ui();
783}
784
[email protected]b172aee2012-04-10 17:05:26785content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31786 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34787}
788
[email protected]86ef6a392012-05-11 22:03:11789void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22790 if (GetUserAgentOverride() == override)
791 return;
792
793 renderer_preferences_.user_agent_override = override;
794
795 // Send the new override string to the renderer.
796 RenderViewHost* host = GetRenderViewHost();
797 if (host)
798 host->SyncRendererPrefs();
799
800 // Reload the page if a load is currently in progress to avoid having
801 // different parts of the page loaded using different user agents.
802 NavigationEntry* entry = controller_.GetActiveEntry();
803 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
804 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53805
806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
807 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11808}
809
810const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22811 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11812}
813
[email protected]b172aee2012-04-10 17:05:26814const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55815 // Transient entries take precedence. They are used for interstitial pages
816 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23817 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08818 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20819 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30820 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23821 if (entry) {
[email protected]b5cca982011-05-26 04:42:08822 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23823 }
[email protected]7ade2732011-02-10 00:13:58824 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
825 render_manager_.pending_web_ui() : render_manager_.web_ui();
826 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54827 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55828 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54829 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35830 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22831 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54832 if (!title.empty())
833 return title;
834 }
835 }
836
837 // We use the title for the last committed entry rather than a pending
838 // navigation entry. For example, when the user types in a URL, we want to
839 // keep the old page's title until the new load has committed and we get a new
840 // title.
[email protected]96d185d2009-04-24 03:28:54841 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23842 if (entry) {
[email protected]b5cca982011-05-26 04:42:08843 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23844 }
[email protected]987fc3a2011-05-26 14:18:09845
846 // |page_title_when_no_navigation_entry_| is finally used
847 // if no title cannot be retrieved.
848 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54849}
850
[email protected]b172aee2012-04-10 17:05:26851int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46852 return GetMaxPageIDForSiteInstance(GetSiteInstance());
853}
854
[email protected]b172aee2012-04-10 17:05:26855int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
856 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33857 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
858 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46859
[email protected]b6583592012-01-25 19:52:33860 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34861}
862
[email protected]b172aee2012-04-10 17:05:26863void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46864 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
865}
866
[email protected]b172aee2012-04-10 17:05:26867void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33868 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46869 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33870 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34871}
872
[email protected]b172aee2012-04-10 17:05:26873void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
874 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57875}
876
[email protected]b172aee2012-04-10 17:05:26877SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58878 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54879}
880
[email protected]b172aee2012-04-10 17:05:26881SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38882 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
883 render_manager_.pending_render_view_host() :
884 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58885 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38886}
887
[email protected]b172aee2012-04-10 17:05:26888bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49890}
891
[email protected]b172aee2012-04-10 17:05:26892bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return waiting_for_response_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31897 return load_state_;
898}
899
[email protected]b172aee2012-04-10 17:05:26900const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31901 return load_state_host_;
902}
903
[email protected]b172aee2012-04-10 17:05:26904uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31905 return upload_size_;
906}
907
[email protected]b172aee2012-04-10 17:05:26908uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31909 return upload_position_;
910}
911
[email protected]b172aee2012-04-10 17:05:26912const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return encoding_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31917 return displayed_insecure_content_;
918}
919
[email protected]b172aee2012-04-10 17:05:26920void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31921 capturing_contents_ = cap;
922}
923
[email protected]b172aee2012-04-10 17:05:26924bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31925 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
926 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
927 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
931 int error_code) {
[email protected]443b80e2010-12-14 00:42:23932 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34933 return;
934
[email protected]443b80e2010-12-14 00:42:23935 crashed_status_ = status;
936 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46937 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34938}
939
[email protected]b172aee2012-04-10 17:05:26940base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31941 return crashed_status_;
942}
943
[email protected]b172aee2012-04-10 17:05:26944bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31945 return is_being_destroyed_;
946}
947
[email protected]b172aee2012-04-10 17:05:26948void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34949 if (delegate_)
950 delegate_->NavigationStateChanged(this, changed_flags);
951}
952
[email protected]3e324142012-06-25 18:26:33953base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
954 return last_selected_time_;
955}
956
[email protected]9e2e4632012-07-27 16:38:41957void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54958 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04959 RenderWidgetHostViewPort* rwhv =
960 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16961 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:41962 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:43963#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16964 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43965#endif
966 }
[email protected]96d185d2009-04-24 03:28:54967
[email protected]5ac20162010-11-24 23:33:11968 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38969
[email protected]9e2e4632012-07-27 16:38:41970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:59971
972 // The resize rect might have changed while this was inactive -- send the new
973 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58974 RenderViewHostImpl* rvh =
975 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59976 if (rvh) {
977 rvh->ResizeRectChanged(GetRootWindowResizerRect());
978 }
[email protected]96d185d2009-04-24 03:28:54979
[email protected]3e324142012-06-25 18:26:33980 bool is_visible = true;
981 content::NotificationService::current()->Notify(
982 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
983 content::Source<WebContents>(this),
984 content::Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:31985}
986
[email protected]b172aee2012-04-10 17:05:26987void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31988 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52989 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
990 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26991 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52992 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33993 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52994 // calls us).
[email protected]c30585c2012-02-16 15:02:04995 RenderWidgetHostViewPort* rwhv =
996 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16997 if (rwhv)
998 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54999 }
1000
[email protected]375fa1b2012-05-22 22:05:371001 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:071002 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:371003 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:091004 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:371005 content::Details<bool>(&is_visible));
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311009 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271010 return WillNotifyDisconnection() &&
1011 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581012 !static_cast<RenderViewHostImpl*>(
1013 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311014}
1015
[email protected]b172aee2012-04-10 17:05:261016void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271017 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251018 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271019}
1020
[email protected]b172aee2012-04-10 17:05:261021WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441022 // We use our current SiteInstance since the cloned entry will use it anyway.
1023 // We pass |this| for the |base_web_contents| to size the view correctly, and
1024 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191025 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1026 GetSiteInstance(), MSG_ROUTING_NONE,
1027 this, opener_);
1028 tc->GetController().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:271029 return tc;
1030}
1031
[email protected]b172aee2012-04-10 17:05:261032void WebContentsImpl::AddNewContents(WebContents* new_contents,
1033 WindowOpenDisposition disposition,
1034 const gfx::Rect& initial_pos,
1035 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271036 if (!delegate_)
1037 return;
1038
1039 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1040 user_gesture);
1041}
1042
[email protected]b172aee2012-04-10 17:05:261043gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271044 return view_->GetContentNativeView();
1045}
1046
[email protected]b172aee2012-04-10 17:05:261047gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271048 return view_->GetNativeView();
1049}
1050
[email protected]b172aee2012-04-10 17:05:261051void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271052 view_->GetContainerBounds(out);
1053}
1054
[email protected]b172aee2012-04-10 17:05:261055void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271056 view_->Focus();
1057}
1058
[email protected]14392a52012-05-02 20:28:441059void WebContentsImpl::Observe(int type,
1060 const content::NotificationSource& source,
1061 const content::NotificationDetails& details) {
1062 switch (type) {
1063 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1064 OnWebContentsDestroyed(
1065 content::Source<content::WebContents>(source).ptr());
1066 break;
[email protected]bafe6cd2012-05-23 23:09:501067 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1068 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1069 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1070 i != pending_widget_views_.end(); ++i) {
1071 if (host->GetView() == i->second) {
1072 pending_widget_views_.erase(i);
1073 break;
1074 }
1075 }
1076 break;
1077 }
[email protected]14392a52012-05-02 20:28:441078 default:
1079 NOTREACHED();
1080 }
1081}
1082
[email protected]d1198fd2012-08-13 22:50:191083void WebContentsImpl::Init(BrowserContext* browser_context,
1084 SiteInstance* site_instance,
1085 int routing_id,
1086 const WebContents* base_web_contents) {
1087 render_manager_.Init(browser_context, site_instance, routing_id);
1088
1089 view_.reset(content::GetContentClient()->browser()->
1090 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1091 if (view_.get()) {
1092 CHECK(render_view_host_delegate_view_);
1093 } else {
1094 content::WebContentsViewDelegate* delegate =
1095 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
1096 this);
1097 view_.reset(CreateWebContentsView(
1098 this, delegate, &render_view_host_delegate_view_));
1099 CHECK(render_view_host_delegate_view_);
1100 }
1101 CHECK(view_.get());
1102
1103 // We have the initial size of the view be based on the size of the view of
1104 // the passed in WebContents.
1105 view_->CreateView(base_web_contents ?
1106 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1107
1108 // Listen for whether our opener gets destroyed.
1109 if (opener_) {
1110 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1111 content::Source<WebContents>(opener_));
1112 }
1113
1114 registrar_.Add(this,
1115 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1116 content::NotificationService::AllBrowserContextsAndSources());
1117#if defined(ENABLE_JAVA_BRIDGE)
1118 java_bridge_dispatcher_host_manager_.reset(
1119 new JavaBridgeDispatcherHostManager(this));
1120#endif
1121
1122 old_browser_plugin_host_.reset(new content::old::BrowserPluginHost(this));
1123}
1124
[email protected]14392a52012-05-02 20:28:441125void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1126 // Clear the opener if it has been closed.
1127 if (web_contents == opener_) {
1128 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1129 content::Source<WebContents>(opener_));
1130 opener_ = NULL;
1131 }
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311135 observers_.AddObserver(observer);
1136}
1137
[email protected]b172aee2012-04-10 17:05:261138void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311139 observers_.RemoveObserver(observer);
1140}
1141
[email protected]b172aee2012-04-10 17:05:261142void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341143 if (delegate_)
1144 delegate_->ActivateContents(this);
1145}
1146
[email protected]b172aee2012-04-10 17:05:261147void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121148 if (delegate_)
1149 delegate_->DeactivateContents(this);
1150}
1151
[email protected]b172aee2012-04-10 17:05:261152void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481153 if (delegate_)
1154 delegate_->LostCapture();
1155}
1156
[email protected]b172aee2012-04-10 17:05:261157bool WebContentsImpl::PreHandleKeyboardEvent(
1158 const NativeWebKeyboardEvent& event,
1159 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481160 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131161 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481162}
1163
[email protected]b172aee2012-04-10 17:05:261164void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481165 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131166 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431170 if (delegate_)
1171 delegate_->HandleMouseDown();
1172}
1173
[email protected]b172aee2012-04-10 17:05:261174void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481175 if (delegate_)
1176 delegate_->HandleMouseUp();
1177}
1178
[email protected]590a634e2012-07-19 16:38:231179void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481180 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231181 delegate_->HandlePointerActivate();
1182}
1183
1184void WebContentsImpl::HandleGestureBegin() {
1185 if (delegate_)
1186 delegate_->HandleGestureBegin();
1187}
1188
1189void WebContentsImpl::HandleGestureEnd() {
1190 if (delegate_)
1191 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481192}
1193
[email protected]b172aee2012-04-10 17:05:261194void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471195 if (delegate_)
1196 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1197}
1198
[email protected]b172aee2012-04-10 17:05:261199bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381200 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121201}
1202
[email protected]a9c81f02012-06-01 00:15:441203void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1204 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371205 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441206 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371207 } else {
1208 GotResponseToLockMouseRequest(false);
1209 }
1210}
1211
[email protected]b172aee2012-04-10 17:05:261212void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371213 if (delegate_)
1214 delegate_->LostMouseLock();
1215}
1216
[email protected]bafe6cd2012-05-23 23:09:501217void WebContentsImpl::CreateNewWindow(
1218 int route_id,
[email protected]97714c82012-06-06 10:15:131219 const ViewHostMsg_CreateWindow_Params& params,
1220 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501221 if (delegate_ && !delegate_->ShouldCreateWebContents(
1222 this, route_id, params.window_container_type, params.frame_name,
1223 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091224 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501225 return;
1226 }
1227
1228 // We usually create the new window in the same BrowsingInstance (group of
1229 // script-related windows), by passing in the current SiteInstance. However,
1230 // if the opener is being suppressed, we create a new SiteInstance in its own
1231 // BrowsingInstance.
1232 scoped_refptr<SiteInstance> site_instance =
1233 params.opener_suppressed ?
1234 SiteInstance::Create(GetBrowserContext()) :
1235 GetSiteInstance();
1236
1237 // Create the new web contents. This will automatically create the new
1238 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191239 WebContentsImpl* new_contents =
1240 new WebContentsImpl(GetBrowserContext(),
1241 params.opener_suppressed ? NULL : this);
1242
1243 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341244 //
1245 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191246 const std::string& partition_id =
1247 content::GetContentClient()->browser()->
1248 GetStoragePartitionIdForSiteInstance(GetBrowserContext(),
1249 site_instance);
[email protected]4c3a23582012-08-18 08:54:341250 content::StoragePartition* partition =
1251 BrowserContext::GetStoragePartition(GetBrowserContext(),
1252 site_instance);
[email protected]d1198fd2012-08-13 22:50:191253 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341254 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191255 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1256 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1257 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1258 new_contents->GetController().SetSessionStorageNamespace(
1259 partition_id,
1260 session_storage_namespace);
1261 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1262
[email protected]bafe6cd2012-05-23 23:09:501263 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1264
1265 if (!params.opener_suppressed) {
1266 content::WebContentsView* new_view = new_contents->GetView();
1267
1268 // TODO(brettw): It seems bogus that we have to call this function on the
1269 // newly created object and give it one of its own member variables.
1270 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1271
1272 // Save the created window associated with the route so we can show it
1273 // later.
1274 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1275 pending_contents_[route_id] = new_contents;
1276 }
1277
1278 if (delegate_) {
1279 delegate_->WebContentsCreated(
1280 this, params.opener_frame_id, params.target_url, new_contents);
1281 }
1282
1283 if (params.opener_suppressed) {
1284 // When the opener is suppressed, the original renderer cannot access the
1285 // new window. As a result, we need to show and navigate the window here.
1286 gfx::Rect initial_pos;
1287 AddNewContents(
1288 new_contents, params.disposition, initial_pos, params.user_gesture);
1289
1290 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1291 CURRENT_TAB,
1292 content::PAGE_TRANSITION_LINK,
1293 true /* is_renderer_initiated */);
1294 new_contents->OpenURL(open_params);
1295 }
1296}
1297
1298void WebContentsImpl::CreateNewWidget(int route_id,
1299 WebKit::WebPopupType popup_type) {
1300 CreateNewWidget(route_id, false, popup_type);
1301}
1302
1303void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1304 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1305}
1306
1307void WebContentsImpl::CreateNewWidget(int route_id,
1308 bool is_fullscreen,
1309 WebKit::WebPopupType popup_type) {
1310 content::RenderProcessHost* process = GetRenderProcessHost();
1311 RenderWidgetHostImpl* widget_host =
1312 new RenderWidgetHostImpl(this, process, route_id);
1313 RenderWidgetHostViewPort* widget_view =
1314 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1315 if (!is_fullscreen) {
1316 // Popups should not get activated.
1317 widget_view->SetPopupType(popup_type);
1318 }
1319 // Save the created widget associated with the route so we can show it later.
1320 pending_widget_views_[route_id] = widget_view;
1321
1322#if defined(OS_MACOSX)
1323 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1324 // to allow it to survive the trip without being hosted.
1325 base::mac::NSObjectRetain(widget_view->GetNativeView());
1326#endif
1327}
1328
1329void WebContentsImpl::ShowCreatedWindow(int route_id,
1330 WindowOpenDisposition disposition,
1331 const gfx::Rect& initial_pos,
1332 bool user_gesture) {
1333 WebContentsImpl* contents = GetCreatedWindow(route_id);
1334 if (contents)
1335 AddNewContents(contents, disposition, initial_pos, user_gesture);
1336}
1337
1338void WebContentsImpl::ShowCreatedWidget(int route_id,
1339 const gfx::Rect& initial_pos) {
1340 ShowCreatedWidget(route_id, false, initial_pos);
1341}
1342
1343void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1344 ShowCreatedWidget(route_id, true, gfx::Rect());
1345}
1346
1347void WebContentsImpl::ShowCreatedWidget(int route_id,
1348 bool is_fullscreen,
1349 const gfx::Rect& initial_pos) {
1350 if (delegate_)
1351 delegate_->RenderWidgetShowing();
1352
1353 RenderWidgetHostViewPort* widget_host_view =
1354 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1355 if (!widget_host_view)
1356 return;
1357 if (is_fullscreen) {
1358 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1359 } else {
1360 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1361 }
[email protected]89054502012-06-03 10:29:241362
1363 RenderWidgetHostImpl* render_widget_host_impl =
1364 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1365 render_widget_host_impl->Init();
1366 // Only allow privileged mouse lock for fullscreen render widget, which is
1367 // used to implement Pepper Flash fullscreen.
1368 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501369
1370#if defined(OS_MACOSX)
1371 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1372 // properly embedded (or purposefully ignored) we can release the retain we
1373 // took in CreateNewWidget().
1374 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1375#endif
1376}
1377
1378WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1379 PendingContents::iterator iter = pending_contents_.find(route_id);
1380
1381 // Certain systems can block the creation of new windows. If we didn't succeed
1382 // in creating one, just return NULL.
1383 if (iter == pending_contents_.end()) {
1384 return NULL;
1385 }
1386
1387 WebContentsImpl* new_contents = iter->second;
1388 pending_contents_.erase(route_id);
1389
1390 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1391 !new_contents->GetRenderViewHost()->GetView())
1392 return NULL;
1393
1394 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1395 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1396 return new_contents;
1397}
1398
1399RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1400 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1401 if (iter == pending_widget_views_.end()) {
1402 DCHECK(false);
1403 return NULL;
1404 }
1405
1406 RenderWidgetHostView* widget_host_view = iter->second;
1407 pending_widget_views_.erase(route_id);
1408
1409 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1410 if (!widget_host->GetProcess()->HasConnection()) {
1411 // The view has gone away or the renderer crashed. Nothing to do.
1412 return NULL;
1413 }
1414
1415 return widget_host_view;
1416}
1417
1418void WebContentsImpl::ShowContextMenu(
1419 const content::ContextMenuParams& params) {
1420 // Allow WebContentsDelegates to handle the context menu operation first.
1421 if (delegate_ && delegate_->HandleContextMenu(params))
1422 return;
1423
[email protected]5a3bdf52012-05-24 15:12:571424 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501425}
1426
[email protected]f13b4202012-06-12 23:53:231427void WebContentsImpl::RequestMediaAccessPermission(
1428 const content::MediaStreamRequest* request,
1429 const content::MediaResponseCallback& callback) {
1430 if (delegate_)
1431 delegate_->RequestMediaAccessPermission(this, request, callback);
1432 else
1433 callback.Run(content::MediaStreamDevices());
1434}
1435
[email protected]b172aee2012-04-10 17:05:261436void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231437 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331438 if (delegate_)
1439 delegate_->UpdatePreferredSize(this, pref_size);
1440}
1441
[email protected]b172aee2012-04-10 17:05:261442void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341443 if (delegate_)
1444 delegate_->ResizeDueToAutoResize(this, new_size);
1445}
1446
[email protected]b172aee2012-04-10 17:05:261447WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201448 if (!delegate_)
1449 return NULL;
[email protected]00c37fc2011-08-02 00:22:501450
[email protected]e5d549d2011-12-28 01:29:201451 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1452 // Notify observers.
1453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1454 DidOpenURL(params.url, params.referrer,
1455 params.disposition, params.transition));
1456 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341457}
1458
[email protected]6b618e62012-08-16 12:59:181459bool WebContentsImpl::Send(IPC::Message* message) {
1460 if (!GetRenderViewHost()) {
1461 delete message;
1462 return false;
1463 }
1464
1465 return GetRenderViewHost()->Send(message);
1466}
1467
[email protected]b172aee2012-04-10 17:05:261468bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501469 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251470 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231471 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251472 reload_type);
[email protected]876bc832010-09-07 16:29:541473}
[email protected]96d185d2009-04-24 03:28:541474
[email protected]ba45bfd2012-05-22 21:51:441475void WebContentsImpl::RenderViewForInterstitialPageCreated(
1476 content::RenderViewHost* render_view_host) {
1477 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1478 RenderViewForInterstitialPageCreated(render_view_host));
1479}
1480
[email protected]b172aee2012-04-10 17:05:261481bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231482 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501483 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401484 // The renderer will reject IPC messages with URLs longer than
1485 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511486 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401487 return false;
1488
[email protected]9f76c1e2012-03-05 15:15:581489 RenderViewHostImpl* dest_render_view_host =
1490 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401491 if (!dest_render_view_host)
1492 return false; // Unable to create the desired render view host.
1493
[email protected]80a8fad2011-01-29 04:02:381494 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071495 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581496 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501497 WebUIControllerFactory* factory =
1498 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271499 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501500 bool is_allowed_in_web_ui_renderer =
1501 factory &&
[email protected]24e18252012-04-16 21:26:271502 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1503 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231504 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1505 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271506 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231507 content::GetContentClient()->SetActiveURL(entry.GetURL());
1508 CHECK(0);
1509 }
[email protected]54ec6472010-04-09 19:39:581510
[email protected]96d185d2009-04-24 03:28:541511 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441512 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521513 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441514 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511515 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541516
[email protected]7bb761892012-07-20 09:32:471517 // Notify observers that we will navigate in this RV.
1518 FOR_EACH_OBSERVER(WebContentsObserver,
1519 observers_,
1520 AboutToNavigateRenderView(dest_render_view_host));
1521
[email protected]96d185d2009-04-24 03:28:541522 // Used for page load time metrics.
1523 current_load_start_ = base::TimeTicks::Now();
1524
1525 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241526 std::string embedder_channel_name;
1527 int embedder_container_id;
1528 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1529 &embedder_channel_name,
1530 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341531 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271532 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241533 embedder_channel_name,
1534 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471535 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341536 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541537
[email protected]36fc0392011-12-25 03:59:511538 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541539 // HACK!! This code suppresses javascript: URLs from being added to
1540 // session history, which is what we want to do for javascript: URLs that
1541 // do not generate content. What we really need is a message from the
1542 // renderer telling us that a new page was not created. The same message
1543 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511544 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541545 return false;
1546 }
1547
[email protected]3c9e1872010-11-18 16:17:491548 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251549 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041550 observers_,
[email protected]36fc0392011-12-25 03:59:511551 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541552
[email protected]09b29342011-06-24 19:18:481553 if (delegate_)
1554 delegate_->DidNavigateToPendingEntry(this);
1555
[email protected]d5f942ba2008-09-26 19:30:341556 return true;
1557}
1558
[email protected]b172aee2012-04-10 17:05:261559void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331560 const SiteInstance* site_instance,
1561 int history_length,
1562 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411563 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1564 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191565 if (render_manager_.pending_render_view_host()) {
1566 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141567 return;
[email protected]9e1ad4b2011-08-14 16:49:191568 }
[email protected]9f76c1e2012-03-05 15:15:581569 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191570 if (!rvh) {
1571 NOTREACHED();
1572 return;
1573 }
[email protected]9f76c1e2012-03-05 15:15:581574 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191575 NOTREACHED();
1576 return;
1577 }
[email protected]6b618e62012-08-16 12:59:181578 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1579 history_length,
1580 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271584 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541585 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1586 return;
1587 }
[email protected]9f76c1e2012-03-05 15:15:581588 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541589}
1590
[email protected]b172aee2012-04-10 17:05:261591bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271592 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541593}
1594
[email protected]b172aee2012-04-10 17:05:261595InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271596 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221597}
1598
[email protected]b172aee2012-04-10 17:05:261599bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161600 // WebKit creates Document object when MIME type is application/xhtml+xml,
1601 // so we also support this MIME type.
1602 return contents_mime_type_ == "text/html" ||
1603 contents_mime_type_ == "text/xml" ||
1604 contents_mime_type_ == "application/xhtml+xml" ||
1605 contents_mime_type_ == "text/plain" ||
1606 contents_mime_type_ == "text/css" ||
1607 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1608}
1609
[email protected]b172aee2012-04-10 17:05:261610void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591611 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161612 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481613 download_stats::RecordDownloadSource(
1614 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461615 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141616 return;
[email protected]c7dd2f62011-07-18 15:57:591617 }
1618
1619 Stop();
1620
1621 // Create the save package and possibly prompt the user for the name to save
1622 // the page as. The user prompt is an asynchronous operation that runs on
1623 // another thread.
1624 save_package_ = new SavePackage(this);
1625 save_package_->GetSaveInfo();
1626}
1627
1628// Used in automated testing to bypass prompting the user for file names.
1629// Instead, the names and paths are hard coded rather than running them through
1630// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261631bool WebContentsImpl::SavePage(const FilePath& main_file,
1632 const FilePath& dir_path,
1633 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591634 // Stop the page from navigating.
1635 Stop();
1636
1637 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271638 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591639}
1640
[email protected]b172aee2012-04-10 17:05:261641void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121642 const FilePath& file,
1643 const base::Callback<void(const FilePath&, int64)>& callback) {
1644 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1645}
1646
[email protected]b172aee2012-04-10 17:05:261647bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231648 NavigationEntryImpl* active_entry =
1649 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321650 return (active_entry != NULL &&
1651 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511652 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321653}
1654
[email protected]b172aee2012-04-10 17:05:261655const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271656 return contents_mime_type_;
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271660 return notify_disconnection_;
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311664 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181665 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161666}
1667
[email protected]b172aee2012-04-10 17:05:261668void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311669 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181670 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161671}
1672
[email protected]b172aee2012-04-10 17:05:261673content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271674 return &renderer_preferences_;
1675}
1676
[email protected]b172aee2012-04-10 17:05:261677void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271678 new_tab_start_time_ = time;
1679}
1680
[email protected]b172aee2012-04-10 17:05:261681base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271682 return new_tab_start_time_;
1683}
1684
[email protected]e35ccd52012-05-23 16:22:471685void WebContentsImpl::Close() {
1686 Close(GetRenderViewHost());
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151690 if (close_start_time_.is_null())
1691 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011692}
1693
[email protected]b172aee2012-04-10 17:05:261694bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191695#if defined(OS_CHROMEOS)
1696 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1697 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511698 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201699 return false;
1700 return true;
[email protected]46624bf2010-06-09 16:04:191701#else
1702 return true;
1703#endif
1704}
1705
[email protected]b172aee2012-04-10 17:05:261706void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521707 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581708 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511709 if (delegate_)
1710 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341711}
1712
[email protected]e35ccd52012-05-23 16:22:471713void WebContentsImpl::UserGestureDone() {
1714 OnUserGesture();
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271718 closed_by_user_gesture_ = value;
1719}
1720
[email protected]b172aee2012-04-10 17:05:261721bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271722 return closed_by_user_gesture_;
1723}
1724
[email protected]b172aee2012-04-10 17:05:261725double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051726 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561727 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251728 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171729 return 0;
[email protected]b75b8292010-10-01 07:28:251730
1731 double zoom_level;
1732 if (temporary_zoom_settings_) {
1733 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581734 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251735 } else {
[email protected]2ae88d12011-10-14 09:11:191736 GURL url;
[email protected]10f417c52011-12-28 21:04:231737 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191738 // Since zoom map is updated using rewritten URL, use rewritten URL
1739 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511740 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191741 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251742 }
[email protected]d0b8d092010-10-25 04:05:171743 return zoom_level;
1744}
[email protected]b75b8292010-10-01 07:28:251745
[email protected]b172aee2012-04-10 17:05:261746int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1747 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171748 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011749 // Calculate the zoom percent from the factor. Round up to the nearest whole
1750 // number.
[email protected]b75b8292010-10-01 07:28:251751 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011752 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251753 *enable_decrement = percent > minimum_zoom_percent_;
1754 *enable_increment = percent < maximum_zoom_percent_;
1755 return percent;
1756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501759 if (!delegate_)
1760 return;
1761
[email protected]10f417c52011-12-28 21:04:231762 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501763 if (!active_entry)
1764 return;
1765
[email protected]36fc0392011-12-25 03:59:511766 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121767}
1768
[email protected]b172aee2012-04-10 17:05:261769void WebContentsImpl::ViewFrameSource(const GURL& url,
1770 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271771 if (!delegate_)
1772 return;
1773
1774 delegate_->ViewSourceForFrame(this, url, content_state);
1775}
1776
[email protected]b172aee2012-04-10 17:05:261777int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271778 return minimum_zoom_percent_;
1779}
1780
[email protected]b172aee2012-04-10 17:05:261781int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271782 return maximum_zoom_percent_;
1783}
1784
[email protected]b172aee2012-04-10 17:05:261785gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231786 return preferred_size_;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271790 return content_restrictions_;
1791}
1792
[email protected]b172aee2012-04-10 17:05:261793WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501794 WebUIControllerFactory* factory =
1795 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1796 if (!factory)
1797 return WebUI::kNoWebUI;
1798 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271799}
1800
[email protected]b172aee2012-04-10 17:05:261801content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271802 // When there is a pending navigation entry, we want to use the pending WebUI
1803 // that goes along with it to control the basic flags. For example, we want to
1804 // show the pending URL in the URL bar, so we want the display_url flag to
1805 // be from the pending entry.
1806 //
1807 // The confusion comes because there are multiple possibilities for the
1808 // initial load in a tab as a side effect of the way the RenderViewHostManager
1809 // works.
1810 //
1811 // - For the very first tab the load looks "normal". The new tab Web UI is
1812 // the pending one, and we want it to apply here.
1813 //
1814 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1815 // get switched to the one previously associated with the new tab pages.
1816 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1817 // have a committed Web UI in this case.
1818 //
1819 // This condition handles all of these cases:
1820 //
1821 // - First load in first tab: no committed nav entry + pending nav entry +
1822 // pending dom ui:
1823 // -> Use pending Web UI if any.
1824 //
1825 // - First load in second tab: no committed nav entry + pending nav entry +
1826 // no pending Web UI:
1827 // -> Use the committed Web UI if any.
1828 //
1829 // - Second navigation in any tab: committed nav entry + pending nav entry:
1830 // -> Use pending Web UI if any.
1831 //
1832 // - Normal state with no load: committed nav entry + no pending nav entry:
1833 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251834 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271835 (controller_.GetLastCommittedEntry() ||
1836 render_manager_.pending_web_ui()))
1837 return render_manager_.pending_web_ui();
1838 return render_manager_.web_ui();
1839}
1840
[email protected]b172aee2012-04-10 17:05:261841bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271842 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581843 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271844}
1845
[email protected]b172aee2012-04-10 17:05:261846bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441847 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501848}
1849
[email protected]b172aee2012-04-10 17:05:261850void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321851 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181852 Send(new ViewMsg_DidChooseColorResponse(
1853 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201854}
1855
[email protected]b172aee2012-04-10 17:05:261856void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181857 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201858 if (delegate_)
1859 delegate_->DidEndColorChooser();
1860 color_chooser_ = NULL;
1861}
1862
[email protected]b172aee2012-04-10 17:05:261863bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471864 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271865 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221866 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231867 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411868 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271869}
1870
[email protected]b172aee2012-04-10 17:05:261871void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271872 if (delegate_)
1873 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211874}
1875
[email protected]3a3b75a2012-06-01 08:38:361876void WebContentsImpl::OnRegisterIntentService(
1877 const webkit_glue::WebIntentServiceData& data,
1878 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431879 if (delegate_)
1880 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301881}
1882
[email protected]b172aee2012-04-10 17:05:261883void WebContentsImpl::OnWebIntentDispatch(
1884 const webkit_glue::WebIntentData& intent,
1885 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431886 if (!delegate_)
1887 return;
1888
[email protected]0d9989d2011-12-21 20:26:001889 WebIntentsDispatcherImpl* intents_dispatcher =
1890 new WebIntentsDispatcherImpl(this, intent, intent_id);
1891 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301892}
1893
[email protected]54047eb52012-05-08 21:45:571894void WebContentsImpl::DidStartProvisionalLoadForFrame(
1895 content::RenderViewHost* render_view_host,
1896 int64 frame_id,
1897 bool is_main_frame,
1898 const GURL& opener_url,
1899 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281900 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181901 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451902 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571903 content::RenderProcessHost* render_process_host =
1904 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541905 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571906 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451907 false,
[email protected]9f76c1e2012-03-05 15:15:581908 &validated_url);
[email protected]ef108e72012-06-20 14:03:541909 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571910 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451911 true,
1912 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181913
[email protected]0d60f0192011-04-14 12:40:101914 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101916 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571917 validated_url, is_error_page, render_view_host));
[email protected]400992b2012-06-14 00:03:541918
1919 if (is_main_frame) {
1920 // Notify observers about the provisional change in the main frame URL.
1921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1922 ProvisionalChangeToMainFrameUrl(validated_url,
1923 validated_opener_url,
1924 render_view_host));
1925 }
1926}
1927
1928void WebContentsImpl::DidRedirectProvisionalLoad(
1929 content::RenderViewHost* render_view_host,
1930 int32 page_id,
1931 const GURL& opener_url,
1932 const GURL& source_url,
1933 const GURL& target_url) {
1934 // TODO(creis): Remove this method and have the pre-rendering code listen to
1935 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1936 // instead. See http://crbug.com/78512.
1937 GURL validated_source_url(source_url);
1938 GURL validated_target_url(target_url);
1939 GURL validated_opener_url(opener_url);
1940 content::RenderProcessHost* render_process_host =
1941 render_view_host->GetProcess();
1942 RenderViewHostImpl::FilterURL(
1943 ChildProcessSecurityPolicyImpl::GetInstance(),
1944 render_process_host->GetID(),
1945 false,
1946 &validated_source_url);
1947 RenderViewHostImpl::FilterURL(
1948 ChildProcessSecurityPolicyImpl::GetInstance(),
1949 render_process_host->GetID(),
1950 false,
1951 &validated_target_url);
1952 RenderViewHostImpl::FilterURL(
1953 ChildProcessSecurityPolicyImpl::GetInstance(),
1954 render_process_host->GetID(),
1955 true,
1956 &validated_opener_url);
1957 NavigationEntry* entry;
1958 if (page_id == -1) {
1959 entry = controller_.GetPendingEntry();
1960 } else {
1961 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1962 page_id);
1963 }
1964 if (!entry || entry->GetURL() != validated_source_url)
1965 return;
1966
1967 // Notify observers about the provisional change in the main frame URL.
1968 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1969 ProvisionalChangeToMainFrameUrl(validated_target_url,
1970 validated_opener_url,
1971 render_view_host));
[email protected]724159a2010-12-30 01:11:181972}
1973
[email protected]54047eb52012-05-08 21:45:571974void WebContentsImpl::DidFailProvisionalLoadWithError(
1975 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581976 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1977 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1978 << ", error_code: " << params.error_code
1979 << ", error_description: " << params.error_description
1980 << ", is_main_frame: " << params.is_main_frame
1981 << ", showing_repost_interstitial: " <<
1982 params.showing_repost_interstitial
1983 << ", frame_id: " << params.frame_id;
1984 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571985 content::RenderProcessHost* render_process_host =
1986 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541987 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571988 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451989 false,
[email protected]9f76c1e2012-03-05 15:15:581990 &validated_url);
[email protected]724159a2010-12-30 01:11:181991
[email protected]d7b175e2011-10-11 15:31:581992 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181993 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1994 // This means that the interstitial won't be torn down properly, which is
1995 // bad. But if we have an interstitial, go back to another tab type, and
1996 // then load the same interstitial again, we could end up getting the first
1997 // interstitial's "failed" message (as a result of the cancel) when we're on
1998 // the second one.
1999 //
2000 // We can't tell this apart, so we think we're tearing down the current page
2001 // which will cause a crash later one. There is also some code in
2002 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2003 // out because of this problem.
2004 //
2005 // http://code.google.com/p/chromium/issues/detail?id=2855
2006 // Because this will not tear down the interstitial properly, if "back" is
2007 // back to another tab type, the interstitial will still be somewhat alive
2008 // in the previous tab type. If you navigate somewhere that activates the
2009 // tab with the interstitial again, you'll see a flash before the new load
2010 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272011 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182012 LOG(WARNING) << "Discarding message during interstitial.";
2013 return;
2014 }
2015
[email protected]a16690732012-07-13 19:22:172016 // Do not clear the pending entry if one exists, so that the user's typed
2017 // URL is not lost when a navigation fails or is aborted. We'll allow
2018 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182019
[email protected]54047eb52012-05-08 21:45:572020 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182021 }
2022
[email protected]d8c660432011-12-22 20:51:252023 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582024 observers_,
2025 DidFailProvisionalLoad(params.frame_id,
2026 params.is_main_frame,
2027 validated_url,
2028 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462029 params.error_description,
2030 render_view_host));
[email protected]724159a2010-12-30 01:11:182031}
2032
[email protected]b172aee2012-04-10 17:05:262033void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182034 const GURL& url,
[email protected]70435962011-08-02 20:13:282035 const std::string& security_info,
2036 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182037 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282038 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192039 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182040 cache.Increment();
2041
2042 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082043 int cert_id = 0;
2044 net::CertStatus cert_status = 0;
2045 int security_bits = -1;
2046 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:512047 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2048 &security_bits, &connection_status);
[email protected]a02cf4c2012-06-20 01:02:002049 content::LoadFromMemoryCacheDetails details(
2050 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2051 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182052
[email protected]ad50def52011-10-19 23:17:072053 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272054 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:502055 content::Source<NavigationController>(&controller_),
[email protected]a02cf4c2012-06-20 01:02:002056 content::Details<content::LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182057}
2058
[email protected]b172aee2012-04-10 17:05:262059void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:382060 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182061 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192062 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182063}
2064
[email protected]b172aee2012-04-10 17:05:262065void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022066 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232067 LOG(INFO) << security_origin << " ran insecure content from "
2068 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:382069 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412070 if (EndsWith(security_origin, kDotGoogleDotCom, false))
2071 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182072 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412073 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192074 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182075}
2076
[email protected]b172aee2012-04-10 17:05:262077void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182078 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472080 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312084 int64 frame_id,
2085 const GURL& validated_url,
2086 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472088 DidFinishLoad(frame_id, validated_url, is_main_frame,
2089 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312090}
2091
[email protected]b172aee2012-04-10 17:05:262092void WebContentsImpl::OnDidFailLoadWithError(
2093 int64 frame_id,
2094 const GURL& validated_url,
2095 bool is_main_frame,
2096 int error_code,
2097 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252098 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312099 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472100 error_code, error_description,
2101 message_source_));
[email protected]724159a2010-12-30 01:11:182102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272105 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432106 if (delegate_)
2107 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172108}
2109
[email protected]b172aee2012-04-10 17:05:262110void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262111 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232112 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252113 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262114 if (!entry)
2115 return;
2116 // Note that we don't call NavigationController::GotToOffset() as we don't
2117 // want to create a pending navigation entry (it might end up lingering
2118 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252119 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582120 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512121 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582122 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472123 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572124
2125 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2126 // it in now that we know. This allows us to find the entry when it commits.
2127 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232128 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332129 entry->set_site_instance(
2130 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572131 }
[email protected]216813952011-05-19 22:21:262132 }
2133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2136 int maximum_percent,
2137 bool remember) {
[email protected]216813952011-05-19 22:21:262138 minimum_zoom_percent_ = minimum_percent;
2139 maximum_zoom_percent_ = maximum_percent;
2140 temporary_zoom_settings_ = !remember;
2141}
2142
[email protected]20b433a2012-05-15 21:23:462143void WebContentsImpl::OnSaveURL(const GURL& url,
2144 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482145 download_stats::RecordDownloadSource(
2146 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262147 // Check if the URL to save matches the URL of the main frame. Since this
2148 // message originates from Pepper plugins, it may not be the case if the
2149 // plugin is an embedded element.
2150 GURL main_frame_url = GetURL();
2151 if (!main_frame_url.is_valid())
2152 return;
2153 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462154 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::OnEnumerateDirectory(int request_id,
2158 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432159 if (!delegate_)
2160 return;
2161
[email protected]b9535422012-02-09 01:47:592162 ChildProcessSecurityPolicyImpl* policy =
2163 ChildProcessSecurityPolicyImpl::GetInstance();
2164 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2165 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212166}
2167
[email protected]b172aee2012-04-10 17:05:262168void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432169 if (delegate_)
2170 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202171}
2172
[email protected]b172aee2012-04-10 17:05:262173void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2174 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362175 const string16& title,
2176 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432177 if (!delegate_)
2178 return;
2179
[email protected]b9535422012-02-09 01:47:592180 ChildProcessSecurityPolicyImpl* policy =
2181 ChildProcessSecurityPolicyImpl::GetInstance();
2182 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2183 return;
[email protected]3a3b75a2012-06-01 08:38:362184 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202185}
2186
[email protected]b172aee2012-04-10 17:05:262187void WebContentsImpl::OnFindReply(int request_id,
2188 int number_of_matches,
2189 const gfx::Rect& selection_rect,
2190 int active_match_ordinal,
2191 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432192 if (delegate_) {
2193 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2194 active_match_ordinal, final_update);
2195 }
[email protected]b888919c2011-09-02 00:32:162196}
2197
[email protected]b172aee2012-04-10 17:05:262198void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442199 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2200 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2204 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102205 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102207 AppCacheAccessed(manifest_url, blocked_by_policy));
2208}
2209
[email protected]b172aee2012-04-10 17:05:262210void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322211 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432212 color_chooser_ = delegate_ ?
2213 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202217 if (color_chooser_ &&
2218 color_chooser_id == color_chooser_->identifier())
2219 color_chooser_->End();
2220}
2221
[email protected]b172aee2012-04-10 17:05:262222void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322223 SkColor color) {
[email protected]da8543762012-03-20 08:52:202224 if (color_chooser_ &&
2225 color_chooser_id == color_chooser_->identifier())
2226 color_chooser_->SetSelectedColor(color);
2227}
2228
[email protected]9f2a9d72012-04-16 16:02:222229void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2230 const FilePath& path,
2231 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442232 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2233 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292234}
2235
[email protected]d0759f492012-04-19 22:50:502236// This exists for render views that don't have a WebUI, but do have WebUI
2237// bindings enabled.
2238void WebContentsImpl::OnWebUISend(const GURL& source_url,
2239 const std::string& name,
2240 const base::ListValue& args) {
2241 if (delegate_)
2242 delegate_->WebUISend(this, source_url, name, args);
2243}
2244
[email protected]d8415ad92012-08-23 14:40:502245void WebContentsImpl::OnRequestPpapiBrokerPermission(
2246 int request_id,
2247 const GURL& url,
2248 const FilePath& plugin_path) {
2249 base::Callback<void(bool)> callback =
2250 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2251 base::Unretained(this), request_id);
2252 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2253 WebContentsObserver* observer;
2254 while ((observer = it.GetNext()) != NULL) {
2255 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2256 callback))
2257 return;
2258 }
2259
2260 // Fall back to allowing the request if no observer handled it.
2261 OnPpapiBrokerPermissionResult(request_id, true);
2262}
2263
2264void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2265 bool result) {
2266 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2267 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2268 request_id,
2269 result));
2270}
2271
[email protected]96d185d2009-04-24 03:28:542272// Notifies the RenderWidgetHost instance about the fact that the page is
2273// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262274void WebContentsImpl::SetIsLoading(bool is_loading,
2275 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542276 if (is_loading == is_loading_)
2277 return;
2278
2279 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212280 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542281 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562282 upload_size_ = 0;
2283 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542284 }
2285
2286 render_manager_.SetIsLoading(is_loading);
2287
2288 is_loading_ = is_loading;
2289 waiting_for_response_ = is_loading;
2290
[email protected]6ebdc9b2010-09-27 16:55:572291 if (delegate_)
2292 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462293 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542294
[email protected]432115822011-07-10 15:52:272295 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2296 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072297 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542298 if (details)
[email protected]6c2381d2011-10-19 02:52:532299 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072300 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502301 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542302 det);
2303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132306 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322307 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562308 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382309 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442310 // that opened the window, as long as both renderers have the same
2311 // privileges.
[email protected]1fd1a502011-03-30 16:55:562312 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562313 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582314 // web_ui might be NULL if the URL refers to a non-existent extension.
2315 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402316 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522317 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442318 }
2319 }
[email protected]1fd1a502011-03-30 16:55:562320 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442321 }
2322
[email protected]4e697b042011-07-08 06:44:562323 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322324 // Clear the status bubble. This is a workaround for a bug where WebKit
2325 // doesn't let us know that the cursor left an element during a
2326 // transition (this is also why the mouse cursor remains as a hand after
2327 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2328 // clear the bubble when a user navigates to a named anchor in the same
2329 // page.
[email protected]36fc0392011-12-25 03:59:512330 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322331 }
2332
[email protected]a6e82fc2010-02-24 22:28:142333 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472334 // Once the main frame is navigated, we're no longer considered to have
2335 // displayed insecure content.
2336 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172337 }
[email protected]ce5c4502009-05-06 16:46:112338
[email protected]3c9e1872010-11-18 16:17:492339 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252340 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042341 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322342}
2343
[email protected]b172aee2012-04-10 17:05:262344void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322345 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132346 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322347 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062348 // If we navigate off the page, reset JavaScript state. This does nothing
2349 // to prevent a malicious script from spamming messages, since the script
2350 // could just reload the page to stop blocking.
2351 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552352 dialog_creator_->ResetJavaScriptState(this);
2353 dialog_creator_ = NULL;
2354 }
[email protected]420ae012009-04-24 05:16:322355
[email protected]3c9e1872010-11-18 16:17:492356 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252357 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042358 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]b172aee2012-04-10 17:05:262361void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462362 // If we are creating a RVH for a restored controller, then we need to make
2363 // sure the RenderView starts with a next_page_id_ larger than the number
2364 // of restored entries. This must be called before the RenderView starts
2365 // navigating (to avoid a race between the browser updating max_page_id and
2366 // the renderer updating next_page_id_). Because of this, we only call this
2367 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562368 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582369 if (max_restored_page_id >
2370 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2371 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2372 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322373}
2374
[email protected]b172aee2012-04-10 17:05:262375bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2376 const string16& title) {
[email protected]420ae012009-04-24 05:16:322377 // For file URLs without a title, use the pathname instead. In the case of a
2378 // synthesized title, we don't want the update to count toward the "one set
2379 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512380 string16 final_title;
[email protected]420ae012009-04-24 05:16:322381 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512382 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2383 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322384 explicit_set = false; // Don't count synthetic titles toward the set limit.
2385 } else {
[email protected]acafd272011-07-26 17:35:572386 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322387 explicit_set = true;
2388 }
2389
[email protected]987fc3a2011-05-26 14:18:092390 // If a page is created via window.open and never navigated,
2391 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552392 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092393 if (entry) {
[email protected]36fc0392011-12-25 03:59:512394 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092395 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322396
[email protected]36fc0392011-12-25 03:59:512397 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092398 } else {
2399 if (page_title_when_no_navigation_entry_ == final_title)
2400 return false; // Nothing changed, don't bother.
2401
2402 page_title_when_no_navigation_entry_ = final_title;
2403 }
[email protected]420ae012009-04-24 05:16:322404
[email protected]420ae012009-04-24 05:16:322405 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232406 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322407
[email protected]2bb171882012-03-07 02:09:462408 std::pair<content::NavigationEntry*, bool> details =
2409 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142410
[email protected]ad50def52011-10-19 23:17:072411 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442412 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2413 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462414 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042415
[email protected]420ae012009-04-24 05:16:322416 return true;
2417}
2418
[email protected]b172aee2012-04-10 17:05:262419void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322420 // After sending out a swap notification, we need to send a disconnect
2421 // notification so that clients that pick up a pointer to |this| can NULL the
2422 // pointer. See Bug 1230284.
2423 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072424 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202425 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2426 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072427 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322428}
2429
[email protected]b172aee2012-04-10 17:05:262430void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322431 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072432 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122433 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2434 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072435 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322436}
2437
[email protected]b172aee2012-04-10 17:05:262438void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322439 if (!notify_disconnection_)
2440 return;
2441
2442 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072443 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322444 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2445 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072446 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322447}
2448
[email protected]5a3bdf52012-05-24 15:12:572449RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2450 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322451}
2452
[email protected]8d3347f2009-07-09 22:00:212453RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262454WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212455 return &render_manager_;
2456}
2457
[email protected]b172aee2012-04-10 17:05:262458content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372459 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462460 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512461}
2462
[email protected]b172aee2012-04-10 17:05:262463WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172464 return this;
2465}
2466
[email protected]b172aee2012-04-10 17:05:262467gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172468 if (delegate_)
2469 return delegate_->GetRootWindowResizerRect();
2470 return gfx::Rect();
2471}
2472
[email protected]b172aee2012-04-10 17:05:262473void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442474 // Don't send notifications if we are just creating a swapped-out RVH for
2475 // the opener chain. These won't be used for view-source or WebUI, so it's
2476 // ok to return early.
2477 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2478 return;
2479
[email protected]ad50def52011-10-19 23:17:072480 content::NotificationService::current()->Notify(
[email protected]d53a08c2012-07-18 20:35:302481 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]fbc5e5f92012-01-02 06:08:322482 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532483 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232484 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322485 if (!entry)
2486 return;
2487
2488 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352489 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562490 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582491 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322492
2493 if (entry->IsViewSourceMode()) {
2494 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182495 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582496 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322497 }
[email protected]0666aef2009-05-13 19:48:082498
[email protected]d487beefe2011-12-21 05:41:212499 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262500
2501 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252502 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322503}
2504
[email protected]b172aee2012-04-10 17:05:262505void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522506 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322507 // Don't notify the world, since this came from a renderer in the
2508 // background.
2509 return;
2510 }
2511
2512 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312513 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232514 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302515
2516 // Restore the focus to the tab (otherwise the focus will be on the top
2517 // window).
[email protected]484ae5912010-09-29 19:16:142518 if (was_crashed && !FocusLocationBarByDefault() &&
2519 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302520 Focus();
[email protected]484ae5912010-09-29 19:16:142521 }
[email protected]32ded2212011-11-10 18:51:432522
[email protected]d8c660432011-12-22 20:51:252523 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322524}
2525
[email protected]b172aee2012-04-10 17:05:262526void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2527 base::TerminationStatus status,
2528 int error_code) {
[email protected]151a63d2011-12-20 22:32:522529 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322530 // The pending page's RenderViewHost is gone.
2531 return;
2532 }
2533
2534 SetIsLoading(false, NULL);
2535 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232536 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312537 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322538
[email protected]d8c660432011-12-22 20:51:252539 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272540 observers_,
[email protected]be1f56ab2011-12-22 06:55:312541 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322542}
2543
[email protected]b172aee2012-04-10 17:05:262544void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482545 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252546 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062547}
2548
[email protected]b172aee2012-04-10 17:05:262549void WebContentsImpl::DidNavigate(
2550 RenderViewHost* rvh,
2551 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582552 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322553 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372554
[email protected]434f69f2012-02-06 21:56:522555 // Update the site of the SiteInstance if it doesn't have one yet, unless
2556 // this is for about:blank. In that case, the SiteInstance can still be
2557 // considered unused until a navigation to a real page.
2558 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2559 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332560 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522561 }
[email protected]420ae012009-04-24 05:16:322562
2563 // Need to update MIME type here because it's referred to in
2564 // UpdateNavigationCommands() called by RendererDidNavigate() to
2565 // determine whether or not to enable the encoding menu.
2566 // It's updated only for the main frame. For a subframe,
2567 // RenderView::UpdateURL does not set params.contents_mime_type.
2568 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2569 // TODO(jungshik): Add a test for the encoding menu to avoid
2570 // regressing it again.
[email protected]2905f742011-10-13 03:51:582571 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322572 contents_mime_type_ = params.contents_mime_type;
2573
[email protected]8286f51a2011-05-31 17:39:132574 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002575 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392576
[email protected]a9c0bfe2010-09-17 08:35:222577 // Send notification about committed provisional loads. This notification is
2578 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2579 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082580 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072581 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2582 // that is not recorded in the navigation history. For the purpose of
2583 // tracking navigation events, we treat this event as a sub frame navigation
2584 // event.
2585 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582586 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222587 // Whether or not a page transition was triggered by going backward or
2588 // forward in the history is only stored in the navigation controller's
2589 // entry list.
2590 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512591 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582592 content::PAGE_TRANSITION_FORWARD_BACK)) {
2593 transition_type = content::PageTransitionFromInt(
2594 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222595 }
[email protected]0d60f0192011-04-14 12:40:102596 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252597 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102598 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462599 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222600 }
2601
[email protected]76543b92009-08-31 17:27:452602 if (!did_navigate)
2603 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322604
2605 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2606 // for the appropriate notification (best) or you can add it to
2607 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2608 // necessary, please).
2609
2610 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002611 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322612 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512613 if (delegate_)
2614 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002615 }
[email protected]420ae012009-04-24 05:16:322616 DidNavigateAnyFramePostCommit(rvh, details, params);
2617}
2618
[email protected]b172aee2012-04-10 17:05:262619void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2620 int32 page_id,
2621 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152622 // Ensure that this state update comes from either the active RVH or one of
2623 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522624 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322625
2626 // We must be prepared to handle state updates for any page, these occur
2627 // when the user is scrolling and entering form data, as well as when we're
2628 // leaving a page, in which case our state may have already been moved to
2629 // the next page. The navigation controller will look up the appropriate
2630 // NavigationEntry and update it when it is notified via the delegate.
2631
2632 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582633 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322634 if (entry_index < 0)
2635 return;
[email protected]10f417c52011-12-28 21:04:232636 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322637
[email protected]36fc0392011-12-25 03:59:512638 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322639 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512640 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322641 controller_.NotifyEntryChanged(entry, entry_index);
2642}
2643
[email protected]b172aee2012-04-10 17:05:262644void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2645 int32 page_id,
2646 const string16& title,
2647 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322648 // If we have a title, that's a pretty good indication that we've started
2649 // getting useful data.
2650 SetNotWaitingForResponse();
2651
[email protected]73eb2602012-02-09 19:50:552652 // Try to find the navigation entry, which might not be the current one.
2653 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232654 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582655 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092656
[email protected]73eb2602012-02-09 19:50:552657 // We can handle title updates when we don't have an entry in
2658 // UpdateTitleForEntry, but only if the update is from the current RVH.
2659 if (!entry && rvh != GetRenderViewHost())
2660 return;
2661
[email protected]a49e10b2011-08-01 23:57:462662 // TODO(evan): make use of title_direction.
2663 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092664 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322665 return;
2666
2667 // Broadcast notifications when the UI should be updated.
2668 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462669 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322670}
2671
[email protected]b172aee2012-04-10 17:05:262672void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2673 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312674 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322675}
2676
[email protected]b172aee2012-04-10 17:05:262677void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512678 if (delegate_)
2679 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322680}
2681
[email protected]b172aee2012-04-10 17:05:262682void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292683 // The UI may be in an event-tracking loop, such as between the
2684 // mouse-down and mouse-up in text selection or a button click.
2685 // Defer the close until after tracking is complete, so that we
2686 // don't free objects out from under the UI.
2687 // TODO(shess): This could probably be integrated with the
2688 // IsDoingDrag() test below. Punting for now because I need more
2689 // research to understand how this impacts platforms other than Mac.
2690 // TODO(shess): This could get more fine-grained. For instance,
2691 // closing a tab in another window while selecting text in the
2692 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212693 if (GetView()->IsEventTracking()) {
2694 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292695 return;
2696 }
2697
[email protected]24a4d1062009-07-10 23:10:422698 // If we close the tab while we're in the middle of a drag, we'll crash.
2699 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212700 if (GetView()->IsDoingDrag()) {
2701 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422702 return;
2703 }
2704
[email protected]420ae012009-04-24 05:16:322705 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522706 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512707 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322708}
2709
[email protected]b172aee2012-04-10 17:05:262710void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522711 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512712 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572713}
2714
[email protected]b172aee2012-04-10 17:05:262715void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512716 if (delegate_ && delegate_->IsPopupOrPanel(this))
2717 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322718}
2719
[email protected]89793072012-07-23 22:25:292720void WebContentsImpl::DidStartLoading(
2721 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322722 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492723
[email protected]82114f52012-03-20 22:53:412724 if (delegate_ && content_restrictions_)
2725 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492726
2727 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2729 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322730}
2731
[email protected]89793072012-07-23 22:25:292732void WebContentsImpl::DidStopLoading(
2733 content::RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322734 scoped_ptr<LoadNotificationDetails> details;
2735
[email protected]10f417c52011-12-28 21:04:232736 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322737 // An entry may not exist for a stop when loading an initial blank page or
2738 // if an iframe injected by script into a blank page finishes loading.
2739 if (entry) {
[email protected]420ae012009-04-24 05:16:322740 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2741
2742 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512743 entry->GetVirtualURL(),
2744 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322745 elapsed,
2746 &controller_,
2747 controller_.GetCurrentEntryIndex()));
2748 }
2749
[email protected]420ae012009-04-24 05:16:322750 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492751
2752 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292753 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2754 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322755}
2756
[email protected]b172aee2012-04-10 17:05:262757void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162758 controller_.DiscardNonCommittedEntries();
2759
2760 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462761 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162762}
2763
[email protected]b172aee2012-04-10 17:05:262764void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512765 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132766 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402767}
2768
[email protected]87717d0e2012-04-26 02:58:432769void WebContentsImpl::DocumentAvailableInMainFrame(
2770 RenderViewHost* render_view_host) {
2771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2772 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102773}
2774
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082776 RenderViewHost* render_view_host,
2777 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072778 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272779 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322780 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532781 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082782}
2783
[email protected]196159d2012-05-04 17:26:542784void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2785 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262786 const content::Referrer& referrer,
2787 WindowOpenDisposition disposition,
2788 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542789 // If this came from a swapped out RenderViewHost, we only allow the request
2790 // if we are still in the same BrowsingInstance.
2791 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2792 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2793 return;
2794 }
2795
[email protected]4ad5d77d2011-12-03 02:00:482796 // Delegate to RequestTransferURL because this is just the generic
2797 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582798 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482799 GlobalRequestID());
2800}
2801
[email protected]b172aee2012-04-10 17:05:262802void WebContentsImpl::RequestTransferURL(
2803 const GURL& url,
2804 const content::Referrer& referrer,
2805 WindowOpenDisposition disposition,
2806 int64 source_frame_id,
2807 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202808 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582809 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582810 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352811 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322812 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2813 // generated suggestions).
2814 //
[email protected]e0112912011-02-02 22:54:352815 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162816 // want web sites to see a referrer of "chrome://blah" (and some
2817 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322818 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432819 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222820 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482821 false /* is_renderer_initiated */);
2822 params.transferred_global_request_id = old_request_id;
2823 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222824 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322825 } else {
[email protected]6bf6a6b52012-02-03 15:41:432826 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482827 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2828 params.transferred_global_request_id = old_request_id;
2829 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582830 }
2831 if (new_contents) {
2832 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252833 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582834 DidOpenRequestedURL(new_contents,
2835 url,
2836 referrer,
2837 disposition,
2838 transition_type,
2839 source_frame_id));
[email protected]420ae012009-04-24 05:16:322840 }
2841}
2842
[email protected]e1c3a552012-05-04 20:51:322843void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2844 // Tell the active RenderViewHost to run unload handlers and close, as long
2845 // as the request came from a RenderViewHost in the same BrowsingInstance.
2846 // In most cases, we receive this from a swapped out RenderViewHost.
2847 // It is possible to receive it from one that has just been swapped in,
2848 // in which case we might as well deliver the message anyway.
2849 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2850 GetRenderViewHost()->ClosePage();
2851}
2852
[email protected]f546640b2012-05-15 00:03:492853void WebContentsImpl::RouteMessageEvent(
2854 RenderViewHost* rvh,
2855 const ViewMsg_PostMessage_Params& params) {
2856 // Only deliver the message to the active RenderViewHost if the request
2857 // came from a RenderViewHost in the same BrowsingInstance.
2858 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2859 return;
2860
2861 ViewMsg_PostMessage_Params new_params(params);
2862
2863 // If there is a source_routing_id, translate it to the routing ID for
2864 // the equivalent swapped out RVH in the target process. If we need
2865 // to create a swapped out RVH for the source tab, we create its opener
2866 // chain as well, since those will also be accessible to the target page.
2867 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2868 // Try to look up the WebContents for the source page.
2869 WebContentsImpl* source_contents = NULL;
2870 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2871 rvh->GetProcess()->GetID(), params.source_routing_id);
2872 if (source_rvh) {
2873 source_contents = static_cast<WebContentsImpl*>(
2874 source_rvh->GetDelegate()->GetAsWebContents());
2875 }
2876
2877 if (source_contents) {
2878 new_params.source_routing_id =
2879 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2880 } else {
2881 // We couldn't find it, so don't pass a source frame.
2882 new_params.source_routing_id = MSG_ROUTING_NONE;
2883 }
2884 }
2885
2886 // In most cases, we receive this from a swapped out RenderViewHost.
2887 // It is possible to receive it from one that has just been swapped in,
2888 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182889 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492890}
2891
[email protected]b172aee2012-04-10 17:05:262892void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342893 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412894 const string16& message,
2895 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322896 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142897 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322898 IPC::Message* reply_msg,
2899 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072900 // Suppress JavaScript dialogs when requested. Also suppress messages when
2901 // showing an interstitial as it's shown over the previous page and we don't
2902 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502903 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582904 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272905 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072906 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522907 delegate_->ShouldSuppressDialogs() ||
2908 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322909
2910 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432911 std::string accept_lang = content::GetContentClient()->browser()->
2912 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552913 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522914 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432915 this,
2916 frame_url.GetOrigin(),
2917 accept_lang,
2918 javascript_message_type,
2919 message,
[email protected]51da7e32012-01-30 19:24:522920 default_prompt,
[email protected]b172aee2012-04-10 17:05:262921 base::Bind(&WebContentsImpl::OnDialogClosed,
2922 base::Unretained(this),
2923 rvh,
2924 reply_msg),
[email protected]51da7e32012-01-30 19:24:522925 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322926 }
[email protected]3ab9cb82011-06-03 18:02:072927
2928 if (suppress_this_message) {
2929 // If we are suppressing messages, just reply as if the user immediately
2930 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342931 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072932 }
2933
2934 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322935}
2936
[email protected]b172aee2012-04-10 17:05:262937void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2938 const string16& message,
2939 bool is_reload,
2940 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582941 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512942 if (delegate_)
2943 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072944
2945 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582946 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072947 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522948 delegate_->ShouldSuppressDialogs() ||
2949 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152950 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342951 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582952 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502953 return;
2954 }
[email protected]3ab9cb82011-06-03 18:02:072955
[email protected]7ab1e7d62009-10-14 23:32:012956 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552957 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522958 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322959 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262960 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522961 reply_msg));
[email protected]420ae012009-04-24 05:16:322962}
2963
[email protected]a796f202012-05-30 14:14:252964bool WebContentsImpl::AddMessageToConsole(int32 level,
2965 const string16& message,
2966 int32 line_no,
2967 const string16& source_id) {
2968 if (!delegate_)
2969 return false;
2970 return delegate_->AddMessageToConsole(this, level, message, line_no,
2971 source_id);
2972}
2973
[email protected]b172aee2012-04-10 17:05:262974WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332975 // We want to base the page config off of the real URL, rather than the
2976 // display URL.
2977 GURL url = controller_.GetActiveEntry()
2978 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2979 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322980}
2981
[email protected]b172aee2012-04-10 17:05:262982void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272983 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252984 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222985
[email protected]ea114722012-03-12 01:11:252986 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172987 if (rdh) // NULL in unittests.
2988 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252989}
2990
[email protected]b172aee2012-04-10 17:05:262991void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442992 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252993 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442994}
2995
[email protected]b172aee2012-04-10 17:05:262996void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2997 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152998 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522999 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153000 return;
3001
[email protected]9f76c1e2012-03-05 15:15:583002 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3003
[email protected]e5fc1632011-08-08 07:51:533004 // Ignore renderer unresponsive event if debugger is attached to the tab
3005 // since the event may be a result of the renderer sitting on a breakpoint.
3006 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443007 DevToolsAgentHost* agent =
3008 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
3009 if (agent &&
3010 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533011 return;
3012
[email protected]420ae012009-04-24 05:16:323013 if (is_during_unload) {
3014 // Hang occurred while firing the beforeunload/unload handler.
3015 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583016 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323017
3018 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3019 return;
3020
3021 // If the tab hangs in the beforeunload/unload handler there's really
3022 // nothing we can do to recover. Pretend the unload listeners have
3023 // all fired and close the tab. If the hang is in the beforeunload handler
3024 // then the user will not have the option of cancelling the close.
3025 Close(rvh);
3026 return;
3027 }
3028
[email protected]9f76c1e2012-03-05 15:15:583029 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473030 return;
3031
[email protected]6934a702011-12-20 00:04:513032 if (delegate_)
3033 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323034}
3035
[email protected]b172aee2012-04-10 17:05:263036void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513037 if (delegate_)
3038 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323039}
3040
[email protected]b172aee2012-04-10 17:05:263041void WebContentsImpl::LoadStateChanged(
3042 const GURL& url,
3043 const net::LoadStateWithParam& load_state,
3044 uint64 upload_position,
3045 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323046 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563047 upload_position_ = upload_position;
3048 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503049 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:203050 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303051 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213052 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323053 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463054 if (IsLoading()) {
3055 NotifyNavigationStateChanged(
3056 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
3057 }
[email protected]420ae012009-04-24 05:16:323058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513061 if (delegate_)
3062 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253063}
3064
[email protected]b172aee2012-04-10 17:05:263065void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:323066 bool proceed,
3067 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:513068 if (delegate_)
3069 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323070}
3071
[email protected]b172aee2012-04-10 17:05:263072void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543073 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233074 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3075 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543076}
3077
[email protected]b172aee2012-04-10 17:05:263078void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103079 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263080 gfx::Size size = view_->GetContainerSize();
3081 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3082 // here during container initialization and normal window size will be set
3083 // later. In case of tab duplication this resizing to 0x0 prevents setting
3084 // normal size later so just ignore it.
3085 if (!size.IsEmpty())
3086 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323087}
3088
[email protected]b172aee2012-04-10 17:05:263089void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543090 NotifySwapped();
3091}
3092
[email protected]14392a52012-05-02 20:28:443093int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3094 SiteInstance* instance) {
3095 if (!opener_)
3096 return MSG_ROUTING_NONE;
3097
3098 // Recursively create RenderViews for anything else in the opener chain.
3099 return opener_->CreateOpenerRenderViews(instance);
3100}
3101
3102int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3103 int opener_route_id = MSG_ROUTING_NONE;
3104
3105 // If this tab has an opener, ensure it has a RenderView in the given
3106 // SiteInstance as well.
3107 if (opener_)
3108 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3109
3110 // Create a swapped out RenderView in the given SiteInstance if none exists,
3111 // setting its opener to the given route_id. Return the new view's route_id.
3112 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3113}
3114
[email protected]b172aee2012-04-10 17:05:263115NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193116 return GetController();
[email protected]3a3d47472010-07-15 21:03:543117}
3118
[email protected]b172aee2012-04-10 17:05:263119WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563120 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323121}
3122
[email protected]10f417c52011-12-28 21:04:233123NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263124 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323125 return controller_.GetLastCommittedEntry();
3126}
3127
[email protected]b172aee2012-04-10 17:05:263128bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443129 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443130 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323131 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523132
[email protected]420ae012009-04-24 05:16:323133 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443134 if (rwh_view)
3135 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323136
[email protected]74ce1ad2011-12-16 21:51:463137 // Make sure we use the correct starting page_id in the new RenderView.
3138 UpdateMaxPageIDIfNecessary(render_view_host);
3139 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583140 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463141
[email protected]7900bfdb2012-05-24 19:31:243142 std::string embedder_channel_name;
3143 int embedder_container_id;
3144 GetBrowserPluginEmbedderInfo(render_view_host,
3145 &embedder_channel_name,
3146 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583147 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493148 render_view_host)->CreateRenderView(string16(),
3149 opener_route_id,
3150 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243151 embedder_channel_name,
3152 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523153 return false;
[email protected]14392a52012-05-02 20:28:443154 }
[email protected]a4127722011-04-27 23:13:523155
[email protected]e60c0232011-11-11 19:56:353156#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503157 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3158 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443159 if (rwh_view) {
3160 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3161 render_widget_host->WasResized();
3162 }
[email protected]f8233cc2011-05-31 20:24:503163#endif
3164
[email protected]420ae012009-04-24 05:16:323165 return true;
3166}
3167
[email protected]b172aee2012-04-10 17:05:263168void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3169 IPC::Message* reply_msg,
3170 bool success,
3171 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543172 if (is_showing_before_unload_dialog_ && !success) {
3173 // If a beforeunload dialog is canceled, we need to stop the throbber from
3174 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293175 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353176 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543177
[email protected]3bbacc5b2012-04-17 17:46:153178 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543179 }
3180 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583181 static_cast<RenderViewHostImpl*>(
3182 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543183}
3184
[email protected]b172aee2012-04-10 17:05:263185void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123186 encoding_ = content::GetContentClient()->browser()->
3187 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103188}
[email protected]f45d2a72010-03-08 23:28:353189
[email protected]b172aee2012-04-10 17:05:263190void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463191 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263192 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573193 DownloadManager* dlm =
3194 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143195 if (!dlm)
3196 return;
3197 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263198 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143199 const NavigationEntry* entry = controller_.GetActiveEntry();
3200 if (entry)
3201 post_id = entry->GetPostID();
3202 }
[email protected]29a5ffc82012-03-13 19:35:583203 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143204 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143205 scoped_ptr<DownloadUrlParameters> params(
3206 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493207 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143208 params->set_post_id(post_id);
3209 params->set_prefer_cache(true);
3210 if (post_id >= 0)
3211 params->set_method("POST");
3212 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143213}
3214
[email protected]b172aee2012-04-10 17:05:263215void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213216 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443217 // Can be NULL during tests.
3218 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213219 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363220}
[email protected]9f76c1e2012-03-05 15:15:583221
[email protected]b172aee2012-04-10 17:05:263222RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583223 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3224}
[email protected]7900bfdb2012-05-24 19:31:243225
3226void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3227 content::RenderViewHost* render_view_host,
3228 std::string* embedder_channel_name,
3229 int* embedder_container_id) {
3230 content::RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283231 old_browser_plugin_host()->embedder_render_process_host();
3232 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243233 int embedder_process_id =
3234 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3235 if (embedder_process_id != -1) {
3236 *embedder_channel_name =
3237 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3238 embedder_process_id);
3239 }
3240}