blob: 73d4e6ea362b18c29597543729665bcd40cf2266 [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]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]172cf712012-05-23 15:07:3917#include "content/browser/browser_plugin/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2531#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3733#include "content/browser/web_contents/interstitial_page_impl.h"
34#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5635#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5137#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0238#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5839#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2041#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1445#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4646#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1547#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2748#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0049#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4850#include "content/public/browser/notification_service.h"
[email protected]375fa1b2012-05-22 22:05:3751#include "content/public/browser/notification_details.h"
[email protected]55578b0a2012-04-18 14:31:3252#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3853#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4254#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2555#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1056#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5057#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2158#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4859#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1860#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5461#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0362#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1663#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2964#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5465#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3466#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3767#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]d353541f2012-05-03 22:45:4168#include "ui/base/ui_base_switches.h"
69#include "ui/gfx/monitor.h"
70#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2471#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3172#include "webkit/glue/webpreferences.h"
73
[email protected]f66df822012-05-18 16:52:1774#if defined(OS_MACOSX)
[email protected]d353541f2012-05-03 22:45:4175#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5776#endif
[email protected]3e45ba92009-02-20 21:09:0077
[email protected]420ae012009-04-24 05:16:3278// Cross-Site Navigations
79//
[email protected]b172aee2012-04-10 17:05:2680// If a WebContentsImpl is told to navigate to a different web site (as
81// determined by SiteInstance), it will replace its current RenderViewHost with
82// a new RenderViewHost dedicated to the new SiteInstance. This works as
83// follows:
[email protected]420ae012009-04-24 05:16:3284//
85// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4686// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3287// - The pending RVH is "suspended," so that no navigation messages are sent to
88// its renderer until the onbeforeunload JavaScript handler has a chance to
89// run in the current RVH.
90// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
91// that it has a pending cross-site request. ResourceDispatcherHost will
92// check for this when the response arrives.
93// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4694// cancel all the pending logic. Otherwise we allow the pending RVH to send
95// the navigation request to its renderer.
96// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
97// main resource load on the pending RVH. It checks CrossSiteRequestManager
98// to see that it is a cross-site request, and installs a
99// CrossSiteResourceHandler.
100// - When RDH receives a response, the BufferedResourceHandler determines
101// whether it is a download. If so, it sends a message to the new renderer
102// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26103// pending RVH remains until the next DidNavigate event for this
104// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32105// - After RDH receives a response and determines that it is safe and not a
106// download, it pauses the response to first run the old page's onunload
107// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26108// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32109// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15110// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32111// the ResourceDispatcherHost, who unpauses the response. Data is then sent
112// to the pending RVH.
113// - The pending renderer sends a FrameNavigate message that invokes the
114// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46115// pending RVH.
[email protected]992db4c2011-05-12 15:37:15116// - The previous renderer is kept swapped out in RenderViewHostManager in case
117// the user goes back. The process only stays live if another tab is using
118// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32119
[email protected]0e12d7d2011-12-01 16:21:44120using content::DevToolsAgentHost;
121using content::DevToolsAgentHostRegistry;
122using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17123using content::DownloadItem;
124using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14125using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20126using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56127using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13128using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27129using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54130using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50131using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23132using content::NavigationEntry;
133using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20134using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11135using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57136using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27137using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11138using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58139using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04140using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25141using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14142using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43143using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33144using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38145using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09146using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25147using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56148using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22149using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50150using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25151using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44152
[email protected]420ae012009-04-24 05:16:32153namespace {
154
155// Amount of time we wait between when a key event is received and the renderer
156// is queried for its state and pushed to the NavigationEntry.
157const int kQueryStateDelay = 5000;
158
[email protected]6ebdc9b2010-09-27 16:55:57159const int kSyncWaitDelay = 40;
160
[email protected]82114f52012-03-20 22:53:41161const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05162
[email protected]420ae012009-04-24 05:16:32163#if defined(OS_WIN)
164
165BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
166 // Note: erase is required to properly paint some widgets borders. This can
167 // be seen with textfields.
168 InvalidateRect(hwnd, NULL, TRUE);
169 return TRUE;
170}
171#endif
172
[email protected]2c5569662011-03-22 20:45:02173ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23174 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50175 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16176 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47181 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16182 break; // Fall through to rest of function.
183 }
[email protected]5e369672009-11-03 23:48:30184
[email protected]59246c572012-02-10 13:32:13185 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
186 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23187 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13188 browser_context->DidLastSessionExitCleanly()) {
189 if (entry.GetHasPostData())
190 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13192 }
[email protected]5e369672009-11-03 23:48:30193
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30195}
196
[email protected]10f417c52011-12-28 21:04:23197void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47198 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42199 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50200 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16201 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51202 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54203 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55204 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
205 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51206 params->url = entry.GetURL();
207 params->referrer = entry.GetReferrer();
208 params->transition = entry.GetTransitionType();
209 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00210 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55211 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34212 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47213 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48214 params->transferred_request_child_id =
215 entry.transferred_global_request_id().child_id;
216 params->transferred_request_request_id =
217 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00218 // Avoid downloading when in view-source mode.
219 params->allow_download = !entry.IsViewSourceMode();
[email protected]6c6b02d2011-09-02 03:36:47220
221 if (delegate)
222 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34223}
224
[email protected]f98f5092012-05-19 00:08:14225int GetSwitchValueAsInt(
226 const CommandLine& command_line,
227 const std::string& switch_string,
228 int min_value) {
229 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
230 int int_value;
231 if (base::StringToInt(string_value, &int_value))
232 return std::max(min_value, int_value);
233 else
234 return min_value;
235}
236
[email protected]420ae012009-04-24 05:16:32237} // namespace
238
[email protected]a81343d232011-12-27 07:39:20239namespace content {
240
241WebContents* WebContents::Create(
242 BrowserContext* browser_context,
243 SiteInstance* site_instance,
244 int routing_id,
[email protected]b172aee2012-04-10 17:05:26245 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20246 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26247 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43248 browser_context,
249 site_instance,
250 routing_id,
[email protected]b172aee2012-04-10 17:05:26251 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44252 NULL,
[email protected]adbfb8df2012-02-24 01:19:43253 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20254}
[email protected]746d3052012-05-22 15:15:47255
[email protected]299d7f12012-05-23 05:31:15256WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47257 return rvh->GetDelegate()->GetAsWebContents();
258}
259
[email protected]a81343d232011-12-27 07:39:20260}
[email protected]f4f50ef2011-01-21 19:01:19261
[email protected]b172aee2012-04-10 17:05:26262// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32263
[email protected]b172aee2012-04-10 17:05:26264WebContentsImpl::WebContentsImpl(
265 content::BrowserContext* browser_context,
266 SiteInstance* site_instance,
267 int routing_id,
268 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44269 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26270 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42271 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07272 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37273 this, browser_context, session_storage_namespace)),
[email protected]14392a52012-05-02 20:28:44274 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05275 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34276 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23277 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
278 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34279 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21280 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56281 upload_size_(0),
282 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47283 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57284 capturing_contents_(false),
285 is_being_destroyed_(false),
286 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55287 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57288#if defined(OS_WIN)
289 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
290#endif
[email protected]7ab1e7d62009-10-14 23:32:01291 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56292 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38293 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25294 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01295 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25296 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01297 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00298 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43299 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20300 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37301 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32302
[email protected]38b098f2012-03-14 21:11:57303 view_.reset(content::GetContentClient()->browser()->
304 OverrideCreateWebContentsView(this));
305 if (!view_.get()) {
306 content::WebContentsViewDelegate* delegate =
307 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
308 this);
[email protected]f66df822012-05-18 16:52:17309 view_.reset(CreateWebContentsView(this, delegate));
[email protected]38b098f2012-03-14 21:11:57310 }
311 CHECK(view_.get());
312
[email protected]ca13a442012-04-17 14:00:12313 // We have the initial size of the view be based on the size of the view of
314 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26315 view_->CreateView(base_web_contents ?
316 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00317
[email protected]14392a52012-05-02 20:28:44318 // Listen for whether our opener gets destroyed.
319 if (opener_) {
320 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
321 content::Source<WebContents>(opener_));
322 }
323
[email protected]483623eb2011-10-25 09:30:00324#if defined(ENABLE_JAVA_BRIDGE)
325 java_bridge_dispatcher_host_manager_.reset(
326 new JavaBridgeDispatcherHostManager(this));
327#endif
[email protected]172cf712012-05-23 15:07:39328
329 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35330}
initial.commit09911bf2008-07-26 23:55:29331
[email protected]b172aee2012-04-10 17:05:26332WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32333 is_being_destroyed_ = true;
334
[email protected]3ab9cb82011-06-03 18:02:07335 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55336 if (dialog_creator_)
337 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07338
[email protected]da8543762012-03-20 08:52:20339 if (color_chooser_)
340 color_chooser_->End();
341
[email protected]420ae012009-04-24 05:16:32342 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32343
[email protected]ca13a442012-04-17 14:00:12344 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07345 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09346 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
347 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07348 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32349
350 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07351#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32352 // If we still have a window handle, destroy it. GetNativeView can return
353 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42354 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52355 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58356 if (host && host->GetView())
357 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42358 }
[email protected]420ae012009-04-24 05:16:32359#endif
[email protected]7ab1e7d62009-10-14 23:32:01360
361 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15362 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01363 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15364 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01365 }
[email protected]b5a1d11c2011-02-17 03:09:42366
[email protected]2db9bd72012-04-13 20:20:56367 FOR_EACH_OBSERVER(WebContentsObserver,
368 observers_,
369 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08370
[email protected]6934a702011-12-20 00:04:51371 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42372}
373
[email protected]b172aee2012-04-10 17:05:26374WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
375 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54376 WebPreferences prefs;
377
378 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
379
380 prefs.developer_extras_enabled = true;
381 prefs.javascript_enabled =
382 !command_line.HasSwitch(switches::kDisableJavaScript);
383 prefs.web_security_enabled =
384 !command_line.HasSwitch(switches::kDisableWebSecurity);
385 prefs.plugins_enabled =
386 !command_line.HasSwitch(switches::kDisablePlugins);
387 prefs.java_enabled =
388 !command_line.HasSwitch(switches::kDisableJava);
389
390 prefs.uses_page_cache =
391 command_line.HasSwitch(switches::kEnableFastback);
392 prefs.remote_fonts_enabled =
393 !command_line.HasSwitch(switches::kDisableRemoteFonts);
394 prefs.xss_auditor_enabled =
395 !command_line.HasSwitch(switches::kDisableXSSAuditor);
396 prefs.application_cache_enabled =
397 !command_line.HasSwitch(switches::kDisableApplicationCache);
398
399 prefs.local_storage_enabled =
400 !command_line.HasSwitch(switches::kDisableLocalStorage);
401 prefs.databases_enabled =
402 !command_line.HasSwitch(switches::kDisableDatabases);
403 prefs.webaudio_enabled =
404 !command_line.HasSwitch(switches::kDisableWebAudio);
405
406 prefs.experimental_webgl_enabled =
407 GpuProcessHost::gpu_enabled() &&
408 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
409 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
410
411 prefs.gl_multisampling_enabled =
412 !command_line.HasSwitch(switches::kDisableGLMultisampling);
413 prefs.privileged_webgl_extensions_enabled =
414 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
415 prefs.site_specific_quirks_enabled =
416 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
417 prefs.allow_file_access_from_file_urls =
418 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
419 prefs.show_composited_layer_borders =
420 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
421 prefs.show_composited_layer_tree =
422 command_line.HasSwitch(switches::kShowCompositedLayerTree);
423 prefs.show_fps_counter =
424 command_line.HasSwitch(switches::kShowFPSCounter);
425 prefs.accelerated_compositing_enabled =
426 GpuProcessHost::gpu_enabled() &&
427 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54428 prefs.force_compositing_mode =
429 command_line.HasSwitch(switches::kForceCompositingMode);
430 prefs.fixed_position_compositing_enabled =
431 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
432 prefs.accelerated_2d_canvas_enabled =
433 GpuProcessHost::gpu_enabled() &&
434 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58435 prefs.deferred_2d_canvas_enabled =
436 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36437 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31438 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54439 prefs.accelerated_painting_enabled =
440 GpuProcessHost::gpu_enabled() &&
441 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
442 prefs.accelerated_filters_enabled =
443 GpuProcessHost::gpu_enabled() &&
444 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
445 prefs.accelerated_layers_enabled =
446 prefs.accelerated_animation_enabled =
447 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54448 prefs.accelerated_plugins_enabled =
449 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
450 prefs.accelerated_video_enabled =
451 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
452 prefs.partial_swap_enabled =
453 command_line.HasSwitch(switches::kEnablePartialSwap);
454 prefs.interactive_form_validation_enabled =
455 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
456 prefs.fullscreen_enabled =
457 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16458 prefs.css_regions_enabled =
459 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29460 prefs.css_shaders_enabled =
461 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54462
463#if defined(OS_MACOSX)
464 bool default_enable_scroll_animator = true;
465#else
466 // On CrOS, the launcher always passes in the --enable flag.
467 bool default_enable_scroll_animator = false;
468#endif
469 prefs.enable_scroll_animator = default_enable_scroll_animator;
470 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
471 prefs.enable_scroll_animator = true;
472 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
473 prefs.enable_scroll_animator = false;
474
475 prefs.visual_word_movement_enabled =
476 command_line.HasSwitch(switches::kEnableVisualWordMovement);
477 prefs.per_tile_painting_enabled =
478 command_line.HasSwitch(switches::kEnablePerTilePainting);
479
480 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32481 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54482 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11483 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
484 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54485 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11486 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54487 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11488 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54489 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11490 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54491 prefs.gl_multisampling_enabled = false;
492
493 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45494 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32495 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54496 prefs.accelerated_video_enabled = false;
497 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45498 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09499 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54500 }
501 }
502
[email protected]b9535422012-02-09 01:47:59503 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58504 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54505 prefs.loads_images_automatically = true;
506 prefs.javascript_enabled = true;
507 }
508
509 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
510
511 // Force accelerated compositing and 2d canvas off for chrome:, about: and
512 // chrome-devtools: pages (unless it's specifically allowed).
513 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54514 url.SchemeIs(chrome::kChromeUIScheme) ||
515 (url.SchemeIs(chrome::kAboutScheme) &&
516 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25517 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54518 prefs.accelerated_compositing_enabled = false;
519 prefs.accelerated_2d_canvas_enabled = false;
520 }
[email protected]8b3b36152012-05-01 04:55:07521#if defined(OS_MACOSX)
522 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
523 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23524 prefs.default_device_scale_factor =
525 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07526#else
527 if (rvh->GetView()) {
528 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
529 rvh->GetView()->GetNativeView());
530 prefs.default_device_scale_factor =
531 static_cast<int>(monitor.device_scale_factor());
532 } else {
[email protected]82c9a8e2012-05-02 01:07:23533 prefs.default_device_scale_factor =
534 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07535 }
536#endif
[email protected]43d9d782012-03-01 15:40:09537
[email protected]f98f5092012-05-19 00:08:14538 if (command_line.HasSwitch(switches::kDefaultTileWidth))
539 prefs.default_tile_width =
540 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
541 if (command_line.HasSwitch(switches::kDefaultTileHeight))
542 prefs.default_tile_height =
543 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
544 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
545 prefs.max_untiled_layer_width =
546 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
547 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
548 prefs.max_untiled_layer_height =
549 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
550
[email protected]2486dce2012-05-23 17:18:19551 if (gfx::Screen::IsDIPEnabled()) {
552 // Only apply when using DIP coordinate system as this setting interferes
553 // with fixed layout mode.
554 prefs.apply_default_device_scale_factor_in_compositor = true;
555 }
556
[email protected]2e21fe292012-03-02 22:52:32557 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54558
559 return prefs;
560}
561
[email protected]b172aee2012-04-10 17:05:26562NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20563 return controller_;
564}
565
[email protected]b172aee2012-04-10 17:05:26566RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28567 return &render_manager_;
568}
569
[email protected]b172aee2012-04-10 17:05:26570bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56571 if (GetWebUI() &&
572 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17573 return true;
[email protected]d2353452012-01-19 19:53:56574 }
[email protected]f82d57b52011-04-27 19:13:17575
[email protected]d8c660432011-12-22 20:51:25576 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
577 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10578 while ((observer = it.GetNext()) != NULL)
579 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53580 return true;
[email protected]403415a2011-01-10 18:57:53581
[email protected]724159a2010-12-30 01:11:18582 bool handled = true;
583 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26584 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58585 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
586 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24587 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
588 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18589 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
590 OnDidLoadResourceFromMemoryCache)
591 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
592 OnDidDisplayInsecureContent)
593 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
594 OnDidRunInsecureContent)
595 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
596 OnDocumentLoadedInFrame)
597 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26598 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
599 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17600 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
601 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25602 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26603 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59604 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21605 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20606 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
607 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
608 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16609 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45610 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10611 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20612 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
613 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
614 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
615 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29616 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50617 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18618 IPC_MESSAGE_UNHANDLED(handled = false)
619 IPC_END_MESSAGE_MAP_EX()
620
621 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38622 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18623 GetRenderProcessHost()->ReceivedBadMessage();
624 }
625
626 return handled;
627}
628
[email protected]b172aee2012-04-10 17:05:26629void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18630 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23631 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51632 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18633}
634
[email protected]b172aee2012-04-10 17:05:26635NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56636 return controller_;
637}
638
[email protected]b172aee2012-04-10 17:05:26639const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56640 return controller_;
641}
642
[email protected]b172aee2012-04-10 17:05:26643content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55644 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30645}
646
[email protected]b172aee2012-04-10 17:05:26647const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31648 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23649 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51650 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31651}
652
653
[email protected]b172aee2012-04-10 17:05:26654const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31655 return &property_bag_;
656}
657
[email protected]b172aee2012-04-10 17:05:26658base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31659 return &property_bag_;
660}
661
[email protected]b172aee2012-04-10 17:05:26662content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31663 return delegate_;
664}
665
[email protected]b172aee2012-04-10 17:05:26666void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31667 // TODO(cbentzel): remove this debugging code?
668 if (delegate == delegate_)
669 return;
670 if (delegate_)
671 delegate_->Detach(this);
672 delegate_ = delegate;
673 if (delegate_)
674 delegate_->Attach(this);
675}
676
[email protected]b172aee2012-04-10 17:05:26677content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41678 RenderViewHostImpl* host = render_manager_.current_host();
679 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16680}
681
[email protected]b172aee2012-04-10 17:05:26682RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31683 return render_manager_.current_host();
684}
685
[email protected]b172aee2012-04-10 17:05:26686RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31687 return render_manager_.GetRenderWidgetHostView();
688}
689
[email protected]b172aee2012-04-10 17:05:26690content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31691 return view_.get();
692}
693
[email protected]b172aee2012-04-10 17:05:26694content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50695 WebUIControllerFactory* factory =
696 content::GetContentClient()->browser()->GetWebUIControllerFactory();
697 if (!factory)
698 return NULL;
[email protected]d2353452012-01-19 19:53:56699 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22700 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50701 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22702 if (controller) {
703 web_ui->SetController(controller);
704 return web_ui;
705 }
706
707 delete web_ui;
708 return NULL;
709}
710
[email protected]b172aee2012-04-10 17:05:26711content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31712 return render_manager_.web_ui() ? render_manager_.web_ui()
713 : render_manager_.pending_web_ui();
714}
715
[email protected]b172aee2012-04-10 17:05:26716content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34718}
719
[email protected]86ef6a392012-05-11 22:03:11720void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
721 user_agent_override_ = override;
722}
723
724const std::string& WebContentsImpl::GetUserAgentOverride() const {
725 return user_agent_override_;
726}
727
[email protected]b172aee2012-04-10 17:05:26728const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55729 // Transient entries take precedence. They are used for interstitial pages
730 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23731 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08732 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20733 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30734 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23735 if (entry) {
[email protected]b5cca982011-05-26 04:42:08736 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23737 }
[email protected]7ade2732011-02-10 00:13:58738 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
739 render_manager_.pending_web_ui() : render_manager_.web_ui();
740 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54741 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55742 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54743 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35744 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22745 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54746 if (!title.empty())
747 return title;
748 }
749 }
750
751 // We use the title for the last committed entry rather than a pending
752 // navigation entry. For example, when the user types in a URL, we want to
753 // keep the old page's title until the new load has committed and we get a new
754 // title.
[email protected]96d185d2009-04-24 03:28:54755 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23756 if (entry) {
[email protected]b5cca982011-05-26 04:42:08757 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23758 }
[email protected]987fc3a2011-05-26 14:18:09759
760 // |page_title_when_no_navigation_entry_| is finally used
761 // if no title cannot be retrieved.
762 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54763}
764
[email protected]b172aee2012-04-10 17:05:26765int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46766 return GetMaxPageIDForSiteInstance(GetSiteInstance());
767}
768
[email protected]b172aee2012-04-10 17:05:26769int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
770 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33771 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
772 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46773
[email protected]b6583592012-01-25 19:52:33774 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34775}
776
[email protected]b172aee2012-04-10 17:05:26777void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46778 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
779}
780
[email protected]b172aee2012-04-10 17:05:26781void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33782 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46783 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33784 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34785}
786
[email protected]b172aee2012-04-10 17:05:26787void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
788 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57789}
790
[email protected]b172aee2012-04-10 17:05:26791SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58792 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54793}
794
[email protected]b172aee2012-04-10 17:05:26795SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38796 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
797 render_manager_.pending_render_view_host() :
798 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58799 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38800}
801
[email protected]b172aee2012-04-10 17:05:26802bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49804}
805
[email protected]b172aee2012-04-10 17:05:26806bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31807 return waiting_for_response_;
808}
809
[email protected]b172aee2012-04-10 17:05:26810const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31811 return load_state_;
812}
813
[email protected]b172aee2012-04-10 17:05:26814const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31815 return load_state_host_;
816}
817
[email protected]b172aee2012-04-10 17:05:26818uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31819 return upload_size_;
820}
821
[email protected]b172aee2012-04-10 17:05:26822uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31823 return upload_position_;
824}
825
[email protected]b172aee2012-04-10 17:05:26826const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31827 return encoding_;
828}
829
[email protected]b172aee2012-04-10 17:05:26830bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return displayed_insecure_content_;
832}
833
[email protected]b172aee2012-04-10 17:05:26834void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31835 capturing_contents_ = cap;
836}
837
[email protected]b172aee2012-04-10 17:05:26838bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
840 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
841 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49842}
843
[email protected]b172aee2012-04-10 17:05:26844void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
845 int error_code) {
[email protected]443b80e2010-12-14 00:42:23846 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34847 return;
848
[email protected]443b80e2010-12-14 00:42:23849 crashed_status_ = status;
850 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46851 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34852}
853
[email protected]b172aee2012-04-10 17:05:26854base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return crashed_status_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return is_being_destroyed_;
860}
861
[email protected]b172aee2012-04-10 17:05:26862void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34863 if (delegate_)
864 delegate_->NavigationStateChanged(this, changed_flags);
865}
866
[email protected]b172aee2012-04-10 17:05:26867void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54868 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04869 RenderWidgetHostViewPort* rwhv =
870 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16871 if (rwhv) {
872 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43873#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16874 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43875#endif
876 }
[email protected]96d185d2009-04-24 03:28:54877
[email protected]5ac20162010-11-24 23:33:11878 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38879
[email protected]d8c660432011-12-22 20:51:25880 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59881
882 // The resize rect might have changed while this was inactive -- send the new
883 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58884 RenderViewHostImpl* rvh =
885 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59886 if (rvh) {
887 rvh->ResizeRectChanged(GetRootWindowResizerRect());
888 }
[email protected]96d185d2009-04-24 03:28:54889}
890
[email protected]be1f56ab2011-12-22 06:55:31891
[email protected]b172aee2012-04-10 17:05:26892base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return last_selected_time_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31897 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52898 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
899 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26900 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52901 // removes the |GetRenderViewHost()|; then when we actually destroy the
902 // window, OnWindowPosChanged() notices and calls HideContents() (which
903 // calls us).
[email protected]c30585c2012-02-16 15:02:04904 RenderWidgetHostViewPort* rwhv =
905 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16906 if (rwhv)
907 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54908 }
909
[email protected]375fa1b2012-05-22 22:05:37910 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07911 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37912 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09913 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37914 content::Details<bool>(&is_visible));
915}
916
917void WebContentsImpl::WasRestored() {
918 bool is_visible = true;
919 content::NotificationService::current()->Notify(
920 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
921 content::Source<WebContents>(this),
922 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54923}
924
[email protected]b172aee2012-04-10 17:05:26925void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04926 RenderWidgetHostViewPort* rwhv =
927 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31928 if (rwhv)
929 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37930 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31931}
932
[email protected]b172aee2012-04-10 17:05:26933void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31934 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
935 // our superclass HideContents(), because some callers want to be very picky
936 // about the order in which these get called. In addition to making the code
937 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26938 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
939 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31940 WasHidden();
941}
942
[email protected]b172aee2012-04-10 17:05:26943bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31944 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27945 return WillNotifyDisconnection() &&
946 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58947 !static_cast<RenderViewHostImpl*>(
948 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31949}
950
[email protected]b172aee2012-04-10 17:05:26951void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27952 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25953 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27954}
955
[email protected]b172aee2012-04-10 17:05:26956WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44957 // We use our current SiteInstance since the cloned entry will use it anyway.
958 // We pass |this| for the |base_web_contents| to size the view correctly, and
959 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26960 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44961 GetBrowserContext(), GetSiteInstance(),
962 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20963 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27964 return tc;
965}
966
[email protected]b172aee2012-04-10 17:05:26967void WebContentsImpl::AddNewContents(WebContents* new_contents,
968 WindowOpenDisposition disposition,
969 const gfx::Rect& initial_pos,
970 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27971 if (!delegate_)
972 return;
973
974 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
975 user_gesture);
976}
977
[email protected]b172aee2012-04-10 17:05:26978gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27979 return view_->GetContentNativeView();
980}
981
[email protected]b172aee2012-04-10 17:05:26982gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27983 return view_->GetNativeView();
984}
985
[email protected]b172aee2012-04-10 17:05:26986void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27987 view_->GetContainerBounds(out);
988}
989
[email protected]b172aee2012-04-10 17:05:26990void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27991 view_->Focus();
992}
993
[email protected]14392a52012-05-02 20:28:44994void WebContentsImpl::Observe(int type,
995 const content::NotificationSource& source,
996 const content::NotificationDetails& details) {
997 switch (type) {
998 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
999 OnWebContentsDestroyed(
1000 content::Source<content::WebContents>(source).ptr());
1001 break;
1002 default:
1003 NOTREACHED();
1004 }
1005}
1006
1007void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1008 // Clear the opener if it has been closed.
1009 if (web_contents == opener_) {
1010 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1011 content::Source<WebContents>(opener_));
1012 opener_ = NULL;
1013 }
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311017 observers_.AddObserver(observer);
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311021 observers_.RemoveObserver(observer);
1022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341025 if (delegate_)
1026 delegate_->ActivateContents(this);
1027}
1028
[email protected]b172aee2012-04-10 17:05:261029void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121030 if (delegate_)
1031 delegate_->DeactivateContents(this);
1032}
1033
[email protected]b172aee2012-04-10 17:05:261034void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481035 if (delegate_)
1036 delegate_->LostCapture();
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039bool WebContentsImpl::PreHandleKeyboardEvent(
1040 const NativeWebKeyboardEvent& event,
1041 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481042 return delegate_ &&
1043 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1044}
1045
[email protected]b172aee2012-04-10 17:05:261046void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481047 if (delegate_)
1048 delegate_->HandleKeyboardEvent(event);
1049}
1050
[email protected]b172aee2012-04-10 17:05:261051void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431052 if (delegate_)
1053 delegate_->HandleMouseDown();
1054}
1055
[email protected]b172aee2012-04-10 17:05:261056void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481057 if (delegate_)
1058 delegate_->HandleMouseUp();
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481062 if (delegate_)
1063 delegate_->HandleMouseActivate();
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471067 if (delegate_)
1068 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1069}
1070
[email protected]b172aee2012-04-10 17:05:261071bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381072 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121073}
1074
[email protected]42252e02012-04-26 16:29:391075void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371076 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391077 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371078 } else {
1079 GotResponseToLockMouseRequest(false);
1080 }
1081}
1082
[email protected]b172aee2012-04-10 17:05:261083void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371084 if (delegate_)
1085 delegate_->LostMouseLock();
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231089 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331090 if (delegate_)
1091 delegate_->UpdatePreferredSize(this, pref_size);
1092}
1093
[email protected]b172aee2012-04-10 17:05:261094void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341095 if (delegate_)
1096 delegate_->ResizeDueToAutoResize(this, new_size);
1097}
1098
[email protected]b172aee2012-04-10 17:05:261099WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201100 if (!delegate_)
1101 return NULL;
[email protected]00c37fc2011-08-02 00:22:501102
[email protected]e5d549d2011-12-28 01:29:201103 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1104 // Notify observers.
1105 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1106 DidOpenURL(params.url, params.referrer,
1107 params.disposition, params.transition));
1108 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341109}
1110
[email protected]b172aee2012-04-10 17:05:261111bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501112 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251113 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231114 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251115 reload_type);
[email protected]876bc832010-09-07 16:29:541116}
[email protected]96d185d2009-04-24 03:28:541117
[email protected]ba45bfd2012-05-22 21:51:441118void WebContentsImpl::RenderViewForInterstitialPageCreated(
1119 content::RenderViewHost* render_view_host) {
1120 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1121 RenderViewForInterstitialPageCreated(render_view_host));
1122}
1123
[email protected]b172aee2012-04-10 17:05:261124bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231125 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501126 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401127 // The renderer will reject IPC messages with URLs longer than
1128 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511129 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401130 return false;
1131
[email protected]9f76c1e2012-03-05 15:15:581132 RenderViewHostImpl* dest_render_view_host =
1133 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401134 if (!dest_render_view_host)
1135 return false; // Unable to create the desired render view host.
1136
[email protected]80a8fad2011-01-29 04:02:381137 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071138 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581139 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501140 WebUIControllerFactory* factory =
1141 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271142 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501143 bool is_allowed_in_web_ui_renderer =
1144 factory &&
[email protected]24e18252012-04-16 21:26:271145 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1146 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231147 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1148 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271149 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231150 content::GetContentClient()->SetActiveURL(entry.GetURL());
1151 CHECK(0);
1152 }
[email protected]54ec6472010-04-09 19:39:581153
[email protected]96d185d2009-04-24 03:28:541154 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441155 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521156 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441157 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511158 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541159
[email protected]172cf712012-05-23 15:07:391160 // Tell BrowserPluginHost about the pending cross-process navigation.
1161 // TODO(fsamuel): Remove this once this issue is addressed:
1162 // https://code.google.com/p/chromium/issues/detail?id=128976
1163 browser_plugin_host()->OnPendingNavigation(dest_render_view_host);
1164
[email protected]96d185d2009-04-24 03:28:541165 // Used for page load time metrics.
1166 current_load_start_ = base::TimeTicks::Now();
1167
1168 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341169 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271170 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471171 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341172 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541173
[email protected]36fc0392011-12-25 03:59:511174 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541175 // HACK!! This code suppresses javascript: URLs from being added to
1176 // session history, which is what we want to do for javascript: URLs that
1177 // do not generate content. What we really need is a message from the
1178 // renderer telling us that a new page was not created. The same message
1179 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511180 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541181 return false;
1182 }
1183
[email protected]3c9e1872010-11-18 16:17:491184 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251185 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041186 observers_,
[email protected]36fc0392011-12-25 03:59:511187 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541188
[email protected]09b29342011-06-24 19:18:481189 if (delegate_)
1190 delegate_->DidNavigateToPendingEntry(this);
1191
[email protected]d5f942ba2008-09-26 19:30:341192 return true;
1193}
1194
[email protected]b172aee2012-04-10 17:05:261195void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331196 const SiteInstance* site_instance,
1197 int history_length,
1198 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411199 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1200 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191201 if (render_manager_.pending_render_view_host()) {
1202 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141203 return;
[email protected]9e1ad4b2011-08-14 16:49:191204 }
[email protected]9f76c1e2012-03-05 15:15:581205 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191206 if (!rvh) {
1207 NOTREACHED();
1208 return;
1209 }
[email protected]9f76c1e2012-03-05 15:15:581210 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191211 NOTREACHED();
1212 return;
1213 }
[email protected]9f76c1e2012-03-05 15:15:581214 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191215 history_length,
1216 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141217}
1218
[email protected]b172aee2012-04-10 17:05:261219void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271220 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541221 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1222 return;
1223 }
[email protected]9f76c1e2012-03-05 15:15:581224 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541225}
1226
[email protected]b172aee2012-04-10 17:05:261227bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271228 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541229}
1230
[email protected]b172aee2012-04-10 17:05:261231InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271232 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221233}
1234
[email protected]b172aee2012-04-10 17:05:261235bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161236 // WebKit creates Document object when MIME type is application/xhtml+xml,
1237 // so we also support this MIME type.
1238 return contents_mime_type_ == "text/html" ||
1239 contents_mime_type_ == "text/xml" ||
1240 contents_mime_type_ == "application/xhtml+xml" ||
1241 contents_mime_type_ == "text/plain" ||
1242 contents_mime_type_ == "text/css" ||
1243 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1244}
1245
[email protected]b172aee2012-04-10 17:05:261246void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591247 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161248 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481249 download_stats::RecordDownloadSource(
1250 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461251 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141252 return;
[email protected]c7dd2f62011-07-18 15:57:591253 }
1254
1255 Stop();
1256
1257 // Create the save package and possibly prompt the user for the name to save
1258 // the page as. The user prompt is an asynchronous operation that runs on
1259 // another thread.
1260 save_package_ = new SavePackage(this);
1261 save_package_->GetSaveInfo();
1262}
1263
1264// Used in automated testing to bypass prompting the user for file names.
1265// Instead, the names and paths are hard coded rather than running them through
1266// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261267bool WebContentsImpl::SavePage(const FilePath& main_file,
1268 const FilePath& dir_path,
1269 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591270 // Stop the page from navigating.
1271 Stop();
1272
1273 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271274 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591275}
1276
[email protected]b172aee2012-04-10 17:05:261277void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121278 const FilePath& file,
1279 const base::Callback<void(const FilePath&, int64)>& callback) {
1280 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1281}
1282
[email protected]b172aee2012-04-10 17:05:261283bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231284 NavigationEntryImpl* active_entry =
1285 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321286 return (active_entry != NULL &&
1287 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511288 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321289}
1290
[email protected]b172aee2012-04-10 17:05:261291const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271292 return contents_mime_type_;
1293}
1294
[email protected]b172aee2012-04-10 17:05:261295bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271296 return notify_disconnection_;
1297}
1298
[email protected]b172aee2012-04-10 17:05:261299void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311300 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581301 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1302 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161303}
1304
[email protected]b172aee2012-04-10 17:05:261305void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311306 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581307 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1308 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161309}
1310
[email protected]b172aee2012-04-10 17:05:261311content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271312 return &renderer_preferences_;
1313}
1314
[email protected]b172aee2012-04-10 17:05:261315void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271316 new_tab_start_time_ = time;
1317}
1318
[email protected]b172aee2012-04-10 17:05:261319base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271320 return new_tab_start_time_;
1321}
1322
[email protected]e35ccd52012-05-23 16:22:471323void WebContentsImpl::Close() {
1324 Close(GetRenderViewHost());
1325}
1326
[email protected]b172aee2012-04-10 17:05:261327void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151328 if (close_start_time_.is_null())
1329 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011330}
1331
[email protected]b172aee2012-04-10 17:05:261332bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191333#if defined(OS_CHROMEOS)
1334 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1335 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511336 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201337 return false;
1338 return true;
[email protected]46624bf2010-06-09 16:04:191339#else
1340 return true;
1341#endif
1342}
1343
[email protected]b172aee2012-04-10 17:05:261344void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521345 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581346 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511347 if (delegate_)
1348 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341349}
1350
[email protected]e35ccd52012-05-23 16:22:471351void WebContentsImpl::UserGestureDone() {
1352 OnUserGesture();
1353}
1354
[email protected]b172aee2012-04-10 17:05:261355void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271356 closed_by_user_gesture_ = value;
1357}
1358
[email protected]b172aee2012-04-10 17:05:261359bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271360 return closed_by_user_gesture_;
1361}
1362
[email protected]b172aee2012-04-10 17:05:261363double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051364 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561365 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251366 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171367 return 0;
[email protected]b75b8292010-10-01 07:28:251368
1369 double zoom_level;
1370 if (temporary_zoom_settings_) {
1371 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581372 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251373 } else {
[email protected]2ae88d12011-10-14 09:11:191374 GURL url;
[email protected]10f417c52011-12-28 21:04:231375 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191376 // Since zoom map is updated using rewritten URL, use rewritten URL
1377 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511378 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191379 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251380 }
[email protected]d0b8d092010-10-25 04:05:171381 return zoom_level;
1382}
[email protected]b75b8292010-10-01 07:28:251383
[email protected]b172aee2012-04-10 17:05:261384int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1385 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171386 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011387 // Calculate the zoom percent from the factor. Round up to the nearest whole
1388 // number.
[email protected]b75b8292010-10-01 07:28:251389 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011390 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251391 *enable_decrement = percent > minimum_zoom_percent_;
1392 *enable_increment = percent < maximum_zoom_percent_;
1393 return percent;
1394}
1395
[email protected]b172aee2012-04-10 17:05:261396void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501397 if (!delegate_)
1398 return;
1399
[email protected]10f417c52011-12-28 21:04:231400 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501401 if (!active_entry)
1402 return;
1403
[email protected]36fc0392011-12-25 03:59:511404 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121405}
1406
[email protected]b172aee2012-04-10 17:05:261407void WebContentsImpl::ViewFrameSource(const GURL& url,
1408 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271409 if (!delegate_)
1410 return;
1411
1412 delegate_->ViewSourceForFrame(this, url, content_state);
1413}
1414
[email protected]b172aee2012-04-10 17:05:261415int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271416 return minimum_zoom_percent_;
1417}
1418
[email protected]b172aee2012-04-10 17:05:261419int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271420 return maximum_zoom_percent_;
1421}
1422
[email protected]b172aee2012-04-10 17:05:261423gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231424 return preferred_size_;
1425}
1426
[email protected]b172aee2012-04-10 17:05:261427int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271428 return content_restrictions_;
1429}
1430
[email protected]b172aee2012-04-10 17:05:261431WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501432 WebUIControllerFactory* factory =
1433 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1434 if (!factory)
1435 return WebUI::kNoWebUI;
1436 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271437}
1438
[email protected]b172aee2012-04-10 17:05:261439content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271440 // When there is a pending navigation entry, we want to use the pending WebUI
1441 // that goes along with it to control the basic flags. For example, we want to
1442 // show the pending URL in the URL bar, so we want the display_url flag to
1443 // be from the pending entry.
1444 //
1445 // The confusion comes because there are multiple possibilities for the
1446 // initial load in a tab as a side effect of the way the RenderViewHostManager
1447 // works.
1448 //
1449 // - For the very first tab the load looks "normal". The new tab Web UI is
1450 // the pending one, and we want it to apply here.
1451 //
1452 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1453 // get switched to the one previously associated with the new tab pages.
1454 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1455 // have a committed Web UI in this case.
1456 //
1457 // This condition handles all of these cases:
1458 //
1459 // - First load in first tab: no committed nav entry + pending nav entry +
1460 // pending dom ui:
1461 // -> Use pending Web UI if any.
1462 //
1463 // - First load in second tab: no committed nav entry + pending nav entry +
1464 // no pending Web UI:
1465 // -> Use the committed Web UI if any.
1466 //
1467 // - Second navigation in any tab: committed nav entry + pending nav entry:
1468 // -> Use pending Web UI if any.
1469 //
1470 // - Normal state with no load: committed nav entry + no pending nav entry:
1471 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251472 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271473 (controller_.GetLastCommittedEntry() ||
1474 render_manager_.pending_web_ui()))
1475 return render_manager_.pending_web_ui();
1476 return render_manager_.web_ui();
1477}
1478
[email protected]b172aee2012-04-10 17:05:261479bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271480 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581481 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271482}
1483
[email protected]b172aee2012-04-10 17:05:261484bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441485 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501486}
1487
[email protected]b172aee2012-04-10 17:05:261488void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321489 SkColor color) {
[email protected]da8543762012-03-20 08:52:201490 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1491 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1492}
1493
[email protected]b172aee2012-04-10 17:05:261494void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201495 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1496 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1497 if (delegate_)
1498 delegate_->DidEndColorChooser();
1499 color_chooser_ = NULL;
1500}
1501
[email protected]b172aee2012-04-10 17:05:261502bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471503 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271504 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221505 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231506 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411507 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271508}
1509
[email protected]b172aee2012-04-10 17:05:261510void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271511 if (delegate_)
1512 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211513}
1514
[email protected]b172aee2012-04-10 17:05:261515void WebContentsImpl::OnRegisterIntentService(const string16& action,
1516 const string16& type,
1517 const string16& href,
1518 const string16& title,
1519 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511520 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301521 this, action, type, href, title, disposition);
1522}
1523
[email protected]b172aee2012-04-10 17:05:261524void WebContentsImpl::OnWebIntentDispatch(
1525 const webkit_glue::WebIntentData& intent,
1526 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001527 WebIntentsDispatcherImpl* intents_dispatcher =
1528 new WebIntentsDispatcherImpl(this, intent, intent_id);
1529 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301530}
1531
[email protected]54047eb52012-05-08 21:45:571532void WebContentsImpl::DidStartProvisionalLoadForFrame(
1533 content::RenderViewHost* render_view_host,
1534 int64 frame_id,
1535 bool is_main_frame,
1536 const GURL& opener_url,
1537 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281538 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181539 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451540 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571541 RenderViewHostImpl* render_view_host_impl =
1542 static_cast<RenderViewHostImpl*>(render_view_host);
1543 content::RenderProcessHost* render_process_host =
1544 render_view_host->GetProcess();
1545 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581546 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571547 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451548 false,
[email protected]9f76c1e2012-03-05 15:15:581549 &validated_url);
[email protected]54047eb52012-05-08 21:45:571550 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451551 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571552 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451553 true,
1554 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181555
[email protected]0d60f0192011-04-14 12:40:101556 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251557 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101558 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571559 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101560
[email protected]724159a2010-12-30 01:11:181561 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591562 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251563 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451564 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461565 validated_opener_url,
1566 render_view_host));
[email protected]724159a2010-12-30 01:11:181567 }
1568}
1569
[email protected]54047eb52012-05-08 21:45:571570void WebContentsImpl::DidRedirectProvisionalLoad(
1571 content::RenderViewHost* render_view_host,
1572 int32 page_id,
1573 const GURL& opener_url,
1574 const GURL& source_url,
1575 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491576 // TODO(creis): Remove this method and have the pre-rendering code listen to
1577 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1578 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451579 GURL validated_source_url(source_url);
1580 GURL validated_target_url(target_url);
1581 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571582 RenderViewHostImpl* render_view_host_impl =
1583 static_cast<RenderViewHostImpl*>(render_view_host);
1584 content::RenderProcessHost* render_process_host =
1585 render_view_host->GetProcess();
1586 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451587 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571588 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451589 false,
1590 &validated_source_url);
[email protected]54047eb52012-05-08 21:45:571591 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451592 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571593 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451594 false,
1595 &validated_target_url);
[email protected]54047eb52012-05-08 21:45:571596 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451597 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571598 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451599 true,
1600 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231601 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571602 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251603 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571604 } else {
1605 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1606 page_id);
1607 }
[email protected]6b7cd8f2012-03-21 21:02:451608 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181609 return;
[email protected]e7d50892011-01-19 21:47:381610
[email protected]4850a7f2011-03-08 23:36:591611 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251612 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451613 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]ef16c3e2012-05-16 22:13:461614 validated_opener_url,
1615 render_view_host));
[email protected]724159a2010-12-30 01:11:181616}
1617
[email protected]54047eb52012-05-08 21:45:571618void WebContentsImpl::DidFailProvisionalLoadWithError(
1619 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581620 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1621 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1622 << ", error_code: " << params.error_code
1623 << ", error_description: " << params.error_description
1624 << ", is_main_frame: " << params.is_main_frame
1625 << ", showing_repost_interstitial: " <<
1626 params.showing_repost_interstitial
1627 << ", frame_id: " << params.frame_id;
1628 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571629 RenderViewHostImpl* render_view_host_impl =
1630 static_cast<RenderViewHostImpl*>(render_view_host);
1631 content::RenderProcessHost* render_process_host =
1632 render_view_host->GetProcess();
1633 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581634 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571635 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451636 false,
[email protected]9f76c1e2012-03-05 15:15:581637 &validated_url);
[email protected]724159a2010-12-30 01:11:181638
[email protected]d7b175e2011-10-11 15:31:581639 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181640 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1641 // This means that the interstitial won't be torn down properly, which is
1642 // bad. But if we have an interstitial, go back to another tab type, and
1643 // then load the same interstitial again, we could end up getting the first
1644 // interstitial's "failed" message (as a result of the cancel) when we're on
1645 // the second one.
1646 //
1647 // We can't tell this apart, so we think we're tearing down the current page
1648 // which will cause a crash later one. There is also some code in
1649 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1650 // out because of this problem.
1651 //
1652 // http://code.google.com/p/chromium/issues/detail?id=2855
1653 // Because this will not tear down the interstitial properly, if "back" is
1654 // back to another tab type, the interstitial will still be somewhat alive
1655 // in the previous tab type. If you navigate somewhere that activates the
1656 // tab with the interstitial again, you'll see a flash before the new load
1657 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271658 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181659 LOG(WARNING) << "Discarding message during interstitial.";
1660 return;
1661 }
1662
[email protected]02102f82011-06-13 20:37:021663 // Discard our pending entry if the load canceled (e.g. if we decided to
1664 // download the file instead of load it). We do not verify that the URL
1665 // being canceled matches the pending entry's URL because they will not
1666 // match if a redirect occurred (in which case we do not want to leave a
1667 // stale redirect URL showing). This means that we also cancel the pending
1668 // entry if the user started a new navigation. As a result, the navigation
1669 // controller may not remember that a load is in progress, but the
1670 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251671 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161672 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181673
[email protected]54047eb52012-05-08 21:45:571674 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181675 }
1676
[email protected]d8c660432011-12-22 20:51:251677 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581678 observers_,
1679 DidFailProvisionalLoad(params.frame_id,
1680 params.is_main_frame,
1681 validated_url,
1682 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461683 params.error_description,
1684 render_view_host));
[email protected]724159a2010-12-30 01:11:181685}
1686
[email protected]b172aee2012-04-10 17:05:261687void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181688 const GURL& url,
[email protected]70435962011-08-02 20:13:281689 const std::string& security_info,
1690 const std::string& http_method,
1691 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191692 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181693 cache.Increment();
1694
1695 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081696 int cert_id = 0;
1697 net::CertStatus cert_status = 0;
1698 int security_bits = -1;
1699 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511700 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1701 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301702 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161703 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181704
[email protected]ad50def52011-10-19 23:17:071705 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271706 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501707 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531708 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181709}
1710
[email protected]b172aee2012-04-10 17:05:261711void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381712 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181713 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201714 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181715}
1716
[email protected]b172aee2012-04-10 17:05:261717void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021718 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231719 LOG(INFO) << security_origin << " ran insecure content from "
1720 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381721 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411722 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1723 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181724 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411725 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201726 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181730 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251731 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101732 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181733}
1734
[email protected]b172aee2012-04-10 17:05:261735void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311736 int64 frame_id,
1737 const GURL& validated_url,
1738 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251739 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311740 DidFinishLoad(frame_id, validated_url, is_main_frame));
1741}
1742
[email protected]b172aee2012-04-10 17:05:261743void WebContentsImpl::OnDidFailLoadWithError(
1744 int64 frame_id,
1745 const GURL& validated_url,
1746 bool is_main_frame,
1747 int error_code,
1748 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311750 DidFailLoad(frame_id, validated_url, is_main_frame,
1751 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181752}
1753
[email protected]b172aee2012-04-10 17:05:261754void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271755 content_restrictions_ = restrictions;
1756 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171757}
1758
[email protected]b172aee2012-04-10 17:05:261759void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261760 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231761 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251762 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261763 if (!entry)
1764 return;
1765 // Note that we don't call NavigationController::GotToOffset() as we don't
1766 // want to create a pending navigation entry (it might end up lingering
1767 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251768 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581769 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511770 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581771 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471772 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571773
1774 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1775 // it in now that we know. This allows us to find the entry when it commits.
1776 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231777 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331778 entry->set_site_instance(
1779 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571780 }
[email protected]216813952011-05-19 22:21:261781 }
1782}
1783
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1785 int maximum_percent,
1786 bool remember) {
[email protected]216813952011-05-19 22:21:261787 minimum_zoom_percent_ = minimum_percent;
1788 maximum_zoom_percent_ = maximum_percent;
1789 temporary_zoom_settings_ = !remember;
1790}
1791
[email protected]20b433a2012-05-15 21:23:461792void WebContentsImpl::OnSaveURL(const GURL& url,
1793 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:481794 download_stats::RecordDownloadSource(
1795 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261796 // Check if the URL to save matches the URL of the main frame. Since this
1797 // message originates from Pepper plugins, it may not be the case if the
1798 // plugin is an embedded element.
1799 GURL main_frame_url = GetURL();
1800 if (!main_frame_url.is_valid())
1801 return;
1802 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:461803 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271804}
1805
[email protected]b172aee2012-04-10 17:05:261806void WebContentsImpl::OnEnumerateDirectory(int request_id,
1807 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591808 ChildProcessSecurityPolicyImpl* policy =
1809 ChildProcessSecurityPolicyImpl::GetInstance();
1810 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1811 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211812}
1813
[email protected]b172aee2012-04-10 17:05:261814void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511815 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201816}
1817
[email protected]b172aee2012-04-10 17:05:261818void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1819 const GURL& url,
1820 const string16& title) {
[email protected]b9535422012-02-09 01:47:591821 ChildProcessSecurityPolicyImpl* policy =
1822 ChildProcessSecurityPolicyImpl::GetInstance();
1823 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1824 return;
[email protected]6934a702011-12-20 00:04:511825 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201826}
1827
[email protected]b172aee2012-04-10 17:05:261828void WebContentsImpl::OnFindReply(int request_id,
1829 int number_of_matches,
1830 const gfx::Rect& selection_rect,
1831 int active_match_ordinal,
1832 bool final_update) {
[email protected]6934a702011-12-20 00:04:511833 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1834 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001835 // Send a notification to the renderer that we are ready to receive more
1836 // results from the scoping effort of the Find operation. The FindInPage
1837 // scoping is asynchronous and periodically sends results back up to the
1838 // browser using IPC. In an effort to not spam the browser we have the
1839 // browser send an ACK for each FindReply message and have the renderer
1840 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581841 GetRenderViewHostImpl()->Send(
1842 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161843}
1844
[email protected]b172aee2012-04-10 17:05:261845void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441846 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1847 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451848}
1849
[email protected]b172aee2012-04-10 17:05:261850void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1851 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101852 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251853 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101854 AppCacheAccessed(manifest_url, blocked_by_policy));
1855}
1856
[email protected]b172aee2012-04-10 17:05:261857void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321858 SkColor color) {
[email protected]da8543762012-03-20 08:52:201859 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1860}
1861
[email protected]b172aee2012-04-10 17:05:261862void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201863 if (color_chooser_ &&
1864 color_chooser_id == color_chooser_->identifier())
1865 color_chooser_->End();
1866}
1867
[email protected]b172aee2012-04-10 17:05:261868void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321869 SkColor color) {
[email protected]da8543762012-03-20 08:52:201870 if (color_chooser_ &&
1871 color_chooser_id == color_chooser_->identifier())
1872 color_chooser_->SetSelectedColor(color);
1873}
1874
[email protected]9f2a9d72012-04-16 16:02:221875void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1876 const FilePath& path,
1877 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1879 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291880}
1881
[email protected]d0759f492012-04-19 22:50:501882// This exists for render views that don't have a WebUI, but do have WebUI
1883// bindings enabled.
1884void WebContentsImpl::OnWebUISend(const GURL& source_url,
1885 const std::string& name,
1886 const base::ListValue& args) {
1887 if (delegate_)
1888 delegate_->WebUISend(this, source_url, name, args);
1889}
1890
[email protected]96d185d2009-04-24 03:28:541891// Notifies the RenderWidgetHost instance about the fact that the page is
1892// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261893void WebContentsImpl::SetIsLoading(bool is_loading,
1894 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541895 if (is_loading == is_loading_)
1896 return;
1897
1898 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211899 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541900 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561901 upload_size_ = 0;
1902 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541903 }
1904
1905 render_manager_.SetIsLoading(is_loading);
1906
1907 is_loading_ = is_loading;
1908 waiting_for_response_ = is_loading;
1909
[email protected]6ebdc9b2010-09-27 16:55:571910 if (delegate_)
1911 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461912 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541913
[email protected]432115822011-07-10 15:52:271914 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1915 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071916 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541917 if (details)
[email protected]6c2381d2011-10-19 02:52:531918 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071919 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501920 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541921 det);
1922}
1923
[email protected]b172aee2012-04-10 17:05:261924void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131925 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321926 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561927 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381928 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441929 // that opened the window, as long as both renderers have the same
1930 // privileges.
[email protected]1fd1a502011-03-30 16:55:561931 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561932 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581933 // web_ui might be NULL if the URL refers to a non-existent extension.
1934 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401935 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521936 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441937 }
1938 }
[email protected]1fd1a502011-03-30 16:55:561939 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441940 }
1941
[email protected]4e697b042011-07-08 06:44:561942 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321943 // Clear the status bubble. This is a workaround for a bug where WebKit
1944 // doesn't let us know that the cursor left an element during a
1945 // transition (this is also why the mouse cursor remains as a hand after
1946 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1947 // clear the bubble when a user navigates to a named anchor in the same
1948 // page.
[email protected]36fc0392011-12-25 03:59:511949 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321950 }
1951
[email protected]a6e82fc2010-02-24 22:28:141952 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471953 // Once the main frame is navigated, we're no longer considered to have
1954 // displayed insecure content.
1955 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171956 }
[email protected]ce5c4502009-05-06 16:46:111957
[email protected]3c9e1872010-11-18 16:17:491958 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251959 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041960 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321961}
1962
[email protected]b172aee2012-04-10 17:05:261963void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321964 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131965 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321966 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061967 // If we navigate off the page, reset JavaScript state. This does nothing
1968 // to prevent a malicious script from spamming messages, since the script
1969 // could just reload the page to stop blocking.
1970 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551971 dialog_creator_->ResetJavaScriptState(this);
1972 dialog_creator_ = NULL;
1973 }
[email protected]420ae012009-04-24 05:16:321974
[email protected]3c9e1872010-11-18 16:17:491975 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251976 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041977 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321978}
1979
[email protected]b172aee2012-04-10 17:05:261980void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461981 // If we are creating a RVH for a restored controller, then we need to make
1982 // sure the RenderView starts with a next_page_id_ larger than the number
1983 // of restored entries. This must be called before the RenderView starts
1984 // navigating (to avoid a race between the browser updating max_page_id and
1985 // the renderer updating next_page_id_). Because of this, we only call this
1986 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561987 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581988 if (max_restored_page_id >
1989 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1990 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1991 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321992}
1993
[email protected]b172aee2012-04-10 17:05:261994bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1995 const string16& title) {
[email protected]420ae012009-04-24 05:16:321996 // For file URLs without a title, use the pathname instead. In the case of a
1997 // synthesized title, we don't want the update to count toward the "one set
1998 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511999 string16 final_title;
[email protected]420ae012009-04-24 05:16:322000 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512001 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2002 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322003 explicit_set = false; // Don't count synthetic titles toward the set limit.
2004 } else {
[email protected]acafd272011-07-26 17:35:572005 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322006 explicit_set = true;
2007 }
2008
[email protected]987fc3a2011-05-26 14:18:092009 // If a page is created via window.open and never navigated,
2010 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552011 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092012 if (entry) {
[email protected]36fc0392011-12-25 03:59:512013 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092014 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322015
[email protected]36fc0392011-12-25 03:59:512016 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092017 } else {
2018 if (page_title_when_no_navigation_entry_ == final_title)
2019 return false; // Nothing changed, don't bother.
2020
2021 page_title_when_no_navigation_entry_ = final_title;
2022 }
[email protected]420ae012009-04-24 05:16:322023
[email protected]420ae012009-04-24 05:16:322024 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232025 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322026
[email protected]2bb171882012-03-07 02:09:462027 std::pair<content::NavigationEntry*, bool> details =
2028 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142029
[email protected]ad50def52011-10-19 23:17:072030 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442031 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2032 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462033 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042034
[email protected]420ae012009-04-24 05:16:322035 return true;
2036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322039 // After sending out a swap notification, we need to send a disconnect
2040 // notification so that clients that pick up a pointer to |this| can NULL the
2041 // pointer. See Bug 1230284.
2042 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072043 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202044 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2045 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072046 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322047}
2048
[email protected]b172aee2012-04-10 17:05:262049void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322050 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072051 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122052 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2053 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072054 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322055}
2056
[email protected]b172aee2012-04-10 17:05:262057void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322058 if (!notify_disconnection_)
2059 return;
2060
2061 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072062 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322063 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2064 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072065 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322066}
2067
[email protected]b172aee2012-04-10 17:05:262068RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322069 return view_.get();
2070}
2071
[email protected]8d3347f2009-07-09 22:00:212072RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262073WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212074 return &render_manager_;
2075}
2076
[email protected]b172aee2012-04-10 17:05:262077content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372078 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462079 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512080}
2081
[email protected]b172aee2012-04-10 17:05:262082WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172083 return this;
2084}
2085
[email protected]b172aee2012-04-10 17:05:262086gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172087 if (delegate_)
2088 return delegate_->GetRootWindowResizerRect();
2089 return gfx::Rect();
2090}
2091
[email protected]b172aee2012-04-10 17:05:262092void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442093 // Don't send notifications if we are just creating a swapped-out RVH for
2094 // the opener chain. These won't be used for view-source or WebUI, so it's
2095 // ok to return early.
2096 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2097 return;
2098
[email protected]ad50def52011-10-19 23:17:072099 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272100 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322101 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532102 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232103 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322104 if (!entry)
2105 return;
2106
2107 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352108 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562109 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582110 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322111
2112 if (entry->IsViewSourceMode()) {
2113 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582114 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2115 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322116 }
[email protected]0666aef2009-05-13 19:48:082117
[email protected]d487beefe2011-12-21 05:41:212118 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262119
2120 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252121 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322122}
2123
[email protected]b172aee2012-04-10 17:05:262124void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522125 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322126 // Don't notify the world, since this came from a renderer in the
2127 // background.
2128 return;
2129 }
2130
2131 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312132 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232133 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302134
2135 // Restore the focus to the tab (otherwise the focus will be on the top
2136 // window).
[email protected]484ae5912010-09-29 19:16:142137 if (was_crashed && !FocusLocationBarByDefault() &&
2138 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302139 Focus();
[email protected]484ae5912010-09-29 19:16:142140 }
[email protected]32ded2212011-11-10 18:51:432141
[email protected]d8c660432011-12-22 20:51:252142 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322143}
2144
[email protected]b172aee2012-04-10 17:05:262145void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2146 base::TerminationStatus status,
2147 int error_code) {
[email protected]151a63d2011-12-20 22:32:522148 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322149 // The pending page's RenderViewHost is gone.
2150 return;
2151 }
2152
2153 SetIsLoading(false, NULL);
2154 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232155 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312156 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322157
[email protected]d8c660432011-12-22 20:51:252158 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272159 observers_,
[email protected]be1f56ab2011-12-22 06:55:312160 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482164 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252165 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062166}
2167
[email protected]b172aee2012-04-10 17:05:262168void WebContentsImpl::DidNavigate(
2169 RenderViewHost* rvh,
2170 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582171 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322172 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372173
[email protected]434f69f2012-02-06 21:56:522174 // Update the site of the SiteInstance if it doesn't have one yet, unless
2175 // this is for about:blank. In that case, the SiteInstance can still be
2176 // considered unused until a navigation to a real page.
2177 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2178 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332179 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522180 }
[email protected]420ae012009-04-24 05:16:322181
2182 // Need to update MIME type here because it's referred to in
2183 // UpdateNavigationCommands() called by RendererDidNavigate() to
2184 // determine whether or not to enable the encoding menu.
2185 // It's updated only for the main frame. For a subframe,
2186 // RenderView::UpdateURL does not set params.contents_mime_type.
2187 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2188 // TODO(jungshik): Add a test for the encoding menu to avoid
2189 // regressing it again.
[email protected]2905f742011-10-13 03:51:582190 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322191 contents_mime_type_ = params.contents_mime_type;
2192
[email protected]8286f51a2011-05-31 17:39:132193 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002194 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392195
[email protected]a9c0bfe2010-09-17 08:35:222196 // Send notification about committed provisional loads. This notification is
2197 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2198 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082199 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072200 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2201 // that is not recorded in the navigation history. For the purpose of
2202 // tracking navigation events, we treat this event as a sub frame navigation
2203 // event.
2204 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582205 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222206 // Whether or not a page transition was triggered by going backward or
2207 // forward in the history is only stored in the navigation controller's
2208 // entry list.
2209 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512210 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582211 content::PAGE_TRANSITION_FORWARD_BACK)) {
2212 transition_type = content::PageTransitionFromInt(
2213 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222214 }
[email protected]0d60f0192011-04-14 12:40:102215 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252216 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102217 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462218 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222219 }
2220
[email protected]76543b92009-08-31 17:27:452221 if (!did_navigate)
2222 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322223
2224 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2225 // for the appropriate notification (best) or you can add it to
2226 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2227 // necessary, please).
2228
2229 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002230 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322231 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512232 if (delegate_)
2233 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002234 }
[email protected]420ae012009-04-24 05:16:322235 DidNavigateAnyFramePostCommit(rvh, details, params);
2236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2239 int32 page_id,
2240 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152241 // Ensure that this state update comes from either the active RVH or one of
2242 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522243 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322244
2245 // We must be prepared to handle state updates for any page, these occur
2246 // when the user is scrolling and entering form data, as well as when we're
2247 // leaving a page, in which case our state may have already been moved to
2248 // the next page. The navigation controller will look up the appropriate
2249 // NavigationEntry and update it when it is notified via the delegate.
2250
2251 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582252 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322253 if (entry_index < 0)
2254 return;
[email protected]10f417c52011-12-28 21:04:232255 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322256
[email protected]36fc0392011-12-25 03:59:512257 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322258 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512259 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322260 controller_.NotifyEntryChanged(entry, entry_index);
2261}
2262
[email protected]b172aee2012-04-10 17:05:262263void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2264 int32 page_id,
2265 const string16& title,
2266 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322267 // If we have a title, that's a pretty good indication that we've started
2268 // getting useful data.
2269 SetNotWaitingForResponse();
2270
[email protected]73eb2602012-02-09 19:50:552271 // Try to find the navigation entry, which might not be the current one.
2272 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232273 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582274 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092275
[email protected]73eb2602012-02-09 19:50:552276 // We can handle title updates when we don't have an entry in
2277 // UpdateTitleForEntry, but only if the update is from the current RVH.
2278 if (!entry && rvh != GetRenderViewHost())
2279 return;
2280
[email protected]a49e10b2011-08-01 23:57:462281 // TODO(evan): make use of title_direction.
2282 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092283 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322284 return;
2285
2286 // Broadcast notifications when the UI should be updated.
2287 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462288 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322289}
2290
[email protected]b172aee2012-04-10 17:05:262291void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2292 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312293 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512297 if (delegate_)
2298 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322299}
2300
[email protected]b172aee2012-04-10 17:05:262301void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292302 // The UI may be in an event-tracking loop, such as between the
2303 // mouse-down and mouse-up in text selection or a button click.
2304 // Defer the close until after tracking is complete, so that we
2305 // don't free objects out from under the UI.
2306 // TODO(shess): This could probably be integrated with the
2307 // IsDoingDrag() test below. Punting for now because I need more
2308 // research to understand how this impacts platforms other than Mac.
2309 // TODO(shess): This could get more fine-grained. For instance,
2310 // closing a tab in another window while selecting text in the
2311 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212312 if (GetView()->IsEventTracking()) {
2313 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292314 return;
2315 }
2316
[email protected]24a4d1062009-07-10 23:10:422317 // If we close the tab while we're in the middle of a drag, we'll crash.
2318 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212319 if (GetView()->IsDoingDrag()) {
2320 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422321 return;
2322 }
2323
[email protected]420ae012009-04-24 05:16:322324 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522325 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512326 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522330 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512331 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572332}
2333
[email protected]b172aee2012-04-10 17:05:262334void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512335 if (delegate_ && delegate_->IsPopupOrPanel(this))
2336 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322337}
2338
[email protected]b172aee2012-04-10 17:05:262339void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322340 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492341
[email protected]82114f52012-03-20 22:53:412342 if (delegate_ && content_restrictions_)
2343 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492344
2345 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252346 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322347}
2348
[email protected]b172aee2012-04-10 17:05:262349void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322350 scoped_ptr<LoadNotificationDetails> details;
2351
[email protected]10f417c52011-12-28 21:04:232352 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322353 // An entry may not exist for a stop when loading an initial blank page or
2354 // if an iframe injected by script into a blank page finishes loading.
2355 if (entry) {
[email protected]420ae012009-04-24 05:16:322356 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2357
2358 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512359 entry->GetVirtualURL(),
2360 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322361 elapsed,
2362 &controller_,
2363 controller_.GetCurrentEntryIndex()));
2364 }
2365
[email protected]420ae012009-04-24 05:16:322366 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492367
2368 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252369 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322370}
2371
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162373 controller_.DiscardNonCommittedEntries();
2374
2375 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462376 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512380 if (delegate_)
2381 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402382}
2383
[email protected]87717d0e2012-04-26 02:58:432384void WebContentsImpl::DocumentAvailableInMainFrame(
2385 RenderViewHost* render_view_host) {
2386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2387 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082391 RenderViewHost* render_view_host,
2392 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072393 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272394 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322395 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532396 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082397}
2398
[email protected]196159d2012-05-04 17:26:542399void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2400 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262401 const content::Referrer& referrer,
2402 WindowOpenDisposition disposition,
2403 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542404 // If this came from a swapped out RenderViewHost, we only allow the request
2405 // if we are still in the same BrowsingInstance.
2406 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2407 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2408 return;
2409 }
2410
[email protected]4ad5d77d2011-12-03 02:00:482411 // Delegate to RequestTransferURL because this is just the generic
2412 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582413 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482414 GlobalRequestID());
2415}
2416
[email protected]b172aee2012-04-10 17:05:262417void WebContentsImpl::RequestTransferURL(
2418 const GURL& url,
2419 const content::Referrer& referrer,
2420 WindowOpenDisposition disposition,
2421 int64 source_frame_id,
2422 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202423 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582424 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582425 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352426 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322427 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2428 // generated suggestions).
2429 //
[email protected]e0112912011-02-02 22:54:352430 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162431 // want web sites to see a referrer of "chrome://blah" (and some
2432 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322433 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432434 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222435 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482436 false /* is_renderer_initiated */);
2437 params.transferred_global_request_id = old_request_id;
2438 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222439 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322440 } else {
[email protected]6bf6a6b52012-02-03 15:41:432441 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482442 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2443 params.transferred_global_request_id = old_request_id;
2444 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582445 }
2446 if (new_contents) {
2447 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252448 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582449 DidOpenRequestedURL(new_contents,
2450 url,
2451 referrer,
2452 disposition,
2453 transition_type,
2454 source_frame_id));
[email protected]420ae012009-04-24 05:16:322455 }
2456}
2457
[email protected]e1c3a552012-05-04 20:51:322458void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2459 // Tell the active RenderViewHost to run unload handlers and close, as long
2460 // as the request came from a RenderViewHost in the same BrowsingInstance.
2461 // In most cases, we receive this from a swapped out RenderViewHost.
2462 // It is possible to receive it from one that has just been swapped in,
2463 // in which case we might as well deliver the message anyway.
2464 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2465 GetRenderViewHost()->ClosePage();
2466}
2467
[email protected]f546640b2012-05-15 00:03:492468void WebContentsImpl::RouteMessageEvent(
2469 RenderViewHost* rvh,
2470 const ViewMsg_PostMessage_Params& params) {
2471 // Only deliver the message to the active RenderViewHost if the request
2472 // came from a RenderViewHost in the same BrowsingInstance.
2473 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2474 return;
2475
2476 ViewMsg_PostMessage_Params new_params(params);
2477
2478 // If there is a source_routing_id, translate it to the routing ID for
2479 // the equivalent swapped out RVH in the target process. If we need
2480 // to create a swapped out RVH for the source tab, we create its opener
2481 // chain as well, since those will also be accessible to the target page.
2482 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2483 // Try to look up the WebContents for the source page.
2484 WebContentsImpl* source_contents = NULL;
2485 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2486 rvh->GetProcess()->GetID(), params.source_routing_id);
2487 if (source_rvh) {
2488 source_contents = static_cast<WebContentsImpl*>(
2489 source_rvh->GetDelegate()->GetAsWebContents());
2490 }
2491
2492 if (source_contents) {
2493 new_params.source_routing_id =
2494 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2495 } else {
2496 // We couldn't find it, so don't pass a source frame.
2497 new_params.source_routing_id = MSG_ROUTING_NONE;
2498 }
2499 }
2500
2501 // In most cases, we receive this from a swapped out RenderViewHost.
2502 // It is possible to receive it from one that has just been swapped in,
2503 // in which case we might as well deliver the message anyway.
2504 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2505 GetRenderViewHost()->GetRoutingID(), new_params));
2506}
2507
[email protected]b172aee2012-04-10 17:05:262508void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342509 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412510 const string16& message,
2511 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322512 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472513 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322514 IPC::Message* reply_msg,
2515 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072516 // Suppress JavaScript dialogs when requested. Also suppress messages when
2517 // showing an interstitial as it's shown over the previous page and we don't
2518 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502519 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582520 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272521 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072522 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522523 delegate_->ShouldSuppressDialogs() ||
2524 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322525
2526 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432527 std::string accept_lang = content::GetContentClient()->browser()->
2528 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552529 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522530 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432531 this,
2532 frame_url.GetOrigin(),
2533 accept_lang,
2534 javascript_message_type,
2535 message,
[email protected]51da7e32012-01-30 19:24:522536 default_prompt,
[email protected]b172aee2012-04-10 17:05:262537 base::Bind(&WebContentsImpl::OnDialogClosed,
2538 base::Unretained(this),
2539 rvh,
2540 reply_msg),
[email protected]51da7e32012-01-30 19:24:522541 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322542 }
[email protected]3ab9cb82011-06-03 18:02:072543
2544 if (suppress_this_message) {
2545 // If we are suppressing messages, just reply as if the user immediately
2546 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342547 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072548 }
2549
2550 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322551}
2552
[email protected]b172aee2012-04-10 17:05:262553void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2554 const string16& message,
2555 bool is_reload,
2556 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582557 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512558 if (delegate_)
2559 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072560
2561 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582562 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072563 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522564 delegate_->ShouldSuppressDialogs() ||
2565 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152566 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342567 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582568 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502569 return;
2570 }
[email protected]3ab9cb82011-06-03 18:02:072571
[email protected]7ab1e7d62009-10-14 23:32:012572 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552573 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522574 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322575 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262576 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522577 reply_msg));
[email protected]420ae012009-04-24 05:16:322578}
2579
[email protected]b172aee2012-04-10 17:05:262580WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332581 // We want to base the page config off of the real URL, rather than the
2582 // display URL.
2583 GURL url = controller_.GetActiveEntry()
2584 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2585 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322586}
2587
[email protected]b172aee2012-04-10 17:05:262588void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272589 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252590 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222591
[email protected]ea114722012-03-12 01:11:252592 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172593 if (rdh) // NULL in unittests.
2594 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252595}
2596
[email protected]b172aee2012-04-10 17:05:262597void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442598 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252599 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442600}
2601
[email protected]b172aee2012-04-10 17:05:262602void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2603 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152604 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522605 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152606 return;
2607
[email protected]9f76c1e2012-03-05 15:15:582608 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2609
[email protected]e5fc1632011-08-08 07:51:532610 // Ignore renderer unresponsive event if debugger is attached to the tab
2611 // since the event may be a result of the renderer sitting on a breakpoint.
2612 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442613 DevToolsAgentHost* agent =
2614 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2615 if (agent &&
2616 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532617 return;
2618
[email protected]420ae012009-04-24 05:16:322619 if (is_during_unload) {
2620 // Hang occurred while firing the beforeunload/unload handler.
2621 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582622 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322623
2624 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2625 return;
2626
2627 // If the tab hangs in the beforeunload/unload handler there's really
2628 // nothing we can do to recover. Pretend the unload listeners have
2629 // all fired and close the tab. If the hang is in the beforeunload handler
2630 // then the user will not have the option of cancelling the close.
2631 Close(rvh);
2632 return;
2633 }
2634
[email protected]9f76c1e2012-03-05 15:15:582635 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472636 return;
2637
[email protected]6934a702011-12-20 00:04:512638 if (delegate_)
2639 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322640}
2641
[email protected]b172aee2012-04-10 17:05:262642void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512643 if (delegate_)
2644 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322645}
2646
[email protected]b172aee2012-04-10 17:05:262647void WebContentsImpl::LoadStateChanged(
2648 const GURL& url,
2649 const net::LoadStateWithParam& load_state,
2650 uint64 upload_position,
2651 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322652 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562653 upload_position_ = upload_position;
2654 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502655 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202656 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302657 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212658 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322659 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462660 if (IsLoading()) {
2661 NotifyNavigationStateChanged(
2662 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2663 }
[email protected]420ae012009-04-24 05:16:322664}
2665
[email protected]b172aee2012-04-10 17:05:262666void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512667 if (delegate_)
2668 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252669}
2670
[email protected]b172aee2012-04-10 17:05:262671void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322672 bool proceed,
2673 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512674 if (delegate_)
2675 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322676}
2677
[email protected]b172aee2012-04-10 17:05:262678void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542679 RenderViewHost* render_view_host) {
2680 DidStartLoading();
2681}
2682
[email protected]b172aee2012-04-10 17:05:262683void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542684 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232685 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2686 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542687}
2688
[email protected]b172aee2012-04-10 17:05:262689void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102690 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262691 gfx::Size size = view_->GetContainerSize();
2692 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2693 // here during container initialization and normal window size will be set
2694 // later. In case of tab duplication this resizing to 0x0 prevents setting
2695 // normal size later so just ignore it.
2696 if (!size.IsEmpty())
2697 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322698}
2699
[email protected]b172aee2012-04-10 17:05:262700void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542701 NotifySwapped();
2702}
2703
[email protected]14392a52012-05-02 20:28:442704int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2705 SiteInstance* instance) {
2706 if (!opener_)
2707 return MSG_ROUTING_NONE;
2708
2709 // Recursively create RenderViews for anything else in the opener chain.
2710 return opener_->CreateOpenerRenderViews(instance);
2711}
2712
2713int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2714 int opener_route_id = MSG_ROUTING_NONE;
2715
2716 // If this tab has an opener, ensure it has a RenderView in the given
2717 // SiteInstance as well.
2718 if (opener_)
2719 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2720
2721 // Create a swapped out RenderView in the given SiteInstance if none exists,
2722 // setting its opener to the given route_id. Return the new view's route_id.
2723 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2724}
2725
[email protected]b172aee2012-04-10 17:05:262726NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202727 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542728}
2729
[email protected]b172aee2012-04-10 17:05:262730WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562731 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322732}
2733
[email protected]10f417c52011-12-28 21:04:232734NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262735 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322736 return controller_.GetLastCommittedEntry();
2737}
2738
[email protected]b172aee2012-04-10 17:05:262739bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442740 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442741 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322742 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522743
[email protected]420ae012009-04-24 05:16:322744 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442745 if (rwh_view)
2746 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322747
[email protected]74ce1ad2011-12-16 21:51:462748 // Make sure we use the correct starting page_id in the new RenderView.
2749 UpdateMaxPageIDIfNecessary(render_view_host);
2750 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582751 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462752
[email protected]172cf712012-05-23 15:07:392753 content::RenderProcessHost* embedder_render_process_host =
2754 browser_plugin_host()->embedder_render_process_host();
2755 int embedder_process_id =
2756 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
[email protected]9f76c1e2012-03-05 15:15:582757 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492758 render_view_host)->CreateRenderView(string16(),
2759 opener_route_id,
2760 max_page_id,
[email protected]172cf712012-05-23 15:07:392761 embedder_process_id)) {
[email protected]a4127722011-04-27 23:13:522762 return false;
[email protected]14392a52012-05-02 20:28:442763 }
[email protected]a4127722011-04-27 23:13:522764
[email protected]e60c0232011-11-11 19:56:352765#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502766 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2767 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442768 if (rwh_view) {
2769 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2770 render_widget_host->WasResized();
2771 }
[email protected]f8233cc2011-05-31 20:24:502772#endif
2773
[email protected]420ae012009-04-24 05:16:322774 return true;
2775}
2776
[email protected]b172aee2012-04-10 17:05:262777void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2778 IPC::Message* reply_msg,
2779 bool success,
2780 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542781 if (is_showing_before_unload_dialog_ && !success) {
2782 // If a beforeunload dialog is canceled, we need to stop the throbber from
2783 // spinning, since we forced it to start spinning in Navigate.
2784 DidStopLoading();
2785
[email protected]3bbacc5b2012-04-17 17:46:152786 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542787 }
2788 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582789 static_cast<RenderViewHostImpl*>(
2790 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542791}
2792
[email protected]b172aee2012-04-10 17:05:262793void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122794 encoding_ = content::GetContentClient()->browser()->
2795 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102796}
[email protected]f45d2a72010-03-08 23:28:352797
[email protected]b172aee2012-04-10 17:05:262798void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:462799 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262800 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142801 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2802 if (!dlm)
2803 return;
2804 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262805 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142806 const NavigationEntry* entry = controller_.GetActiveEntry();
2807 if (entry)
2808 post_id = entry->GetPostID();
2809 }
[email protected]29a5ffc82012-03-13 19:35:582810 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142811 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:142812 scoped_ptr<DownloadUrlParameters> params(
2813 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]20b433a2012-05-15 21:23:462814 // TODO(jochen): Pass in the referrer policy as well.
2815 params->set_referrer(referrer.url);
[email protected]c5a5c0842012-05-04 20:05:142816 params->set_post_id(post_id);
2817 params->set_prefer_cache(true);
2818 if (post_id >= 0)
2819 params->set_method("POST");
2820 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:142821}
2822
[email protected]b172aee2012-04-10 17:05:262823void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212824 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442825 // Can be NULL during tests.
2826 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212827 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362828}
[email protected]9f76c1e2012-03-05 15:15:582829
[email protected]b172aee2012-04-10 17:05:262830RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582831 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2832}