blob: b19ed132ec868c96491889c734356f1a7a4a1d8c [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]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0419#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1221#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1622#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3223#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5424#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0525#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0026#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0127#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3229#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2530#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3732#include "content/browser/web_contents/interstitial_page_impl.h"
33#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5634#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2435#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5136#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5838#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1139#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2040#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1444#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4645#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1546#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2747#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0048#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4849#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3250#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3851#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4252#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2553#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1054#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5055#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2156#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4857#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1858#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5459#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0360#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1661#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2962#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5463#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3464#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3765#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]d353541f2012-05-03 22:45:4166#include "ui/base/ui_base_switches.h"
67#include "ui/gfx/monitor.h"
68#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2469#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3170#include "webkit/glue/webpreferences.h"
71
[email protected]68b52252012-04-04 19:26:1372#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:3573#include "content/browser/web_contents/web_contents_view_aura.h"
[email protected]68b52252012-04-04 19:26:1374#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:3575#include "content/browser/web_contents/web_contents_view_win.h"
[email protected]38b098f2012-03-14 21:11:5776#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:3577#include "content/browser/web_contents/web_contents_view_gtk.h"
[email protected]38b098f2012-03-14 21:11:5778#elif defined(OS_MACOSX)
[email protected]0c4e92e62012-04-11 15:19:0079#include "content/browser/web_contents/web_contents_view_mac.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5781#elif defined(OS_ANDROID)
[email protected]0c4e92e62012-04-11 15:19:0082#include "content/browser/web_contents/web_contents_view_android.h"
[email protected]38b098f2012-03-14 21:11:5783#endif
[email protected]3e45ba92009-02-20 21:09:0084
[email protected]420ae012009-04-24 05:16:3285// Cross-Site Navigations
86//
[email protected]b172aee2012-04-10 17:05:2687// If a WebContentsImpl is told to navigate to a different web site (as
88// determined by SiteInstance), it will replace its current RenderViewHost with
89// a new RenderViewHost dedicated to the new SiteInstance. This works as
90// follows:
[email protected]420ae012009-04-24 05:16:3291//
92// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4693// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3294// - The pending RVH is "suspended," so that no navigation messages are sent to
95// its renderer until the onbeforeunload JavaScript handler has a chance to
96// run in the current RVH.
97// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
98// that it has a pending cross-site request. ResourceDispatcherHost will
99// check for this when the response arrives.
100// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46101// cancel all the pending logic. Otherwise we allow the pending RVH to send
102// the navigation request to its renderer.
103// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
104// main resource load on the pending RVH. It checks CrossSiteRequestManager
105// to see that it is a cross-site request, and installs a
106// CrossSiteResourceHandler.
107// - When RDH receives a response, the BufferedResourceHandler determines
108// whether it is a download. If so, it sends a message to the new renderer
109// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26110// pending RVH remains until the next DidNavigate event for this
111// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32112// - After RDH receives a response and determines that it is safe and not a
113// download, it pauses the response to first run the old page's onunload
114// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26115// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32116// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15117// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32118// the ResourceDispatcherHost, who unpauses the response. Data is then sent
119// to the pending RVH.
120// - The pending renderer sends a FrameNavigate message that invokes the
121// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46122// pending RVH.
[email protected]992db4c2011-05-12 15:37:15123// - The previous renderer is kept swapped out in RenderViewHostManager in case
124// the user goes back. The process only stays live if another tab is using
125// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32126
[email protected]0e12d7d2011-12-01 16:21:44127using content::DevToolsAgentHost;
128using content::DevToolsAgentHostRegistry;
129using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17130using content::DownloadItem;
131using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14132using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20133using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56134using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13135using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27136using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50137using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23138using content::NavigationEntry;
139using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20140using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11141using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57142using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27143using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58145using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04146using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25147using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14148using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43149using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33150using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38151using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09152using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25153using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56154using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22155using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50156using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25157using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44158
[email protected]420ae012009-04-24 05:16:32159namespace {
160
161// Amount of time we wait between when a key event is received and the renderer
162// is queried for its state and pushed to the NavigationEntry.
163const int kQueryStateDelay = 5000;
164
[email protected]6ebdc9b2010-09-27 16:55:57165const int kSyncWaitDelay = 40;
166
[email protected]82114f52012-03-20 22:53:41167const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05168
[email protected]420ae012009-04-24 05:16:32169#if defined(OS_WIN)
170
171BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
172 // Note: erase is required to properly paint some widgets borders. This can
173 // be seen with textfields.
174 InvalidateRect(hwnd, NULL, TRUE);
175 return TRUE;
176}
177#endif
178
[email protected]2c5569662011-03-22 20:45:02179ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23180 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50181 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16182 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47185 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02186 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16188 break; // Fall through to rest of function.
189 }
[email protected]5e369672009-11-03 23:48:30190
[email protected]59246c572012-02-10 13:32:13191 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
192 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23193 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13194 browser_context->DidLastSessionExitCleanly()) {
195 if (entry.GetHasPostData())
196 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13198 }
[email protected]5e369672009-11-03 23:48:30199
[email protected]2c5569662011-03-22 20:45:02200 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30201}
202
[email protected]10f417c52011-12-28 21:04:23203void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47204 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42205 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50206 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16207 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51208 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54209 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55210 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
211 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51212 params->url = entry.GetURL();
213 params->referrer = entry.GetReferrer();
214 params->transition = entry.GetTransitionType();
215 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00216 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55217 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34218 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47219 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48220 params->transferred_request_child_id =
221 entry.transferred_global_request_id().child_id;
222 params->transferred_request_request_id =
223 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00224 // Avoid downloading when in view-source mode.
225 params->allow_download = !entry.IsViewSourceMode();
[email protected]6c6b02d2011-09-02 03:36:47226
227 if (delegate)
228 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34229}
230
[email protected]420ae012009-04-24 05:16:32231} // namespace
232
[email protected]a81343d232011-12-27 07:39:20233namespace content {
234
235WebContents* WebContents::Create(
236 BrowserContext* browser_context,
237 SiteInstance* site_instance,
238 int routing_id,
[email protected]b172aee2012-04-10 17:05:26239 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20240 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26241 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43242 browser_context,
243 site_instance,
244 routing_id,
[email protected]b172aee2012-04-10 17:05:26245 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44246 NULL,
[email protected]adbfb8df2012-02-24 01:19:43247 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20248}
249}
[email protected]f4f50ef2011-01-21 19:01:19250
[email protected]b172aee2012-04-10 17:05:26251// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32252
[email protected]b172aee2012-04-10 17:05:26253WebContentsImpl::WebContentsImpl(
254 content::BrowserContext* browser_context,
255 SiteInstance* site_instance,
256 int routing_id,
257 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44258 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26259 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42260 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07261 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37262 this, browser_context, session_storage_namespace)),
[email protected]14392a52012-05-02 20:28:44263 opener_(opener),
[email protected]d82ed61e2009-06-16 02:46:22264 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34265 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23266 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
267 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34268 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21269 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56270 upload_size_(0),
271 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47272 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57273 capturing_contents_(false),
274 is_being_destroyed_(false),
275 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55276 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57277#if defined(OS_WIN)
278 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
279#endif
[email protected]7ab1e7d62009-10-14 23:32:01280 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56281 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38282 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25283 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01284 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25285 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01286 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00287 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43288 content_restrictions_(0),
[email protected]c8160f22012-05-14 06:44:03289 view_type_(content::VIEW_TYPE_INVALID),
[email protected]da8543762012-03-20 08:52:20290 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37291 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32292
[email protected]38b098f2012-03-14 21:11:57293 view_.reset(content::GetContentClient()->browser()->
294 OverrideCreateWebContentsView(this));
295 if (!view_.get()) {
296 content::WebContentsViewDelegate* delegate =
297 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
298 this);
[email protected]68b52252012-04-04 19:26:13299#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:35300 view_.reset(new WebContentsViewAura(this, delegate));
[email protected]68b52252012-04-04 19:26:13301#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:35302 view_.reset(new WebContentsViewWin(this, delegate));
[email protected]38b098f2012-03-14 21:11:57303#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:35304 view_.reset(new content::WebContentsViewGtk(this, delegate));
[email protected]38b098f2012-03-14 21:11:57305#elif defined(OS_MACOSX)
306 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
307#elif defined(OS_ANDROID)
308 view_.reset(new WebContentsViewAndroid(this));
309#endif
[email protected]dbd407f2012-03-14 21:30:37310 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57311 }
312 CHECK(view_.get());
313
[email protected]ca13a442012-04-17 14:00:12314 // We have the initial size of the view be based on the size of the view of
315 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26316 view_->CreateView(base_web_contents ?
317 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00318
[email protected]14392a52012-05-02 20:28:44319 // Listen for whether our opener gets destroyed.
320 if (opener_) {
321 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
322 content::Source<WebContents>(opener_));
323 }
324
[email protected]483623eb2011-10-25 09:30:00325#if defined(ENABLE_JAVA_BRIDGE)
326 java_bridge_dispatcher_host_manager_.reset(
327 new JavaBridgeDispatcherHostManager(this));
328#endif
[email protected]332af7732009-03-11 13:21:35329}
initial.commit09911bf2008-07-26 23:55:29330
[email protected]b172aee2012-04-10 17:05:26331WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32332 is_being_destroyed_ = true;
333
[email protected]3ab9cb82011-06-03 18:02:07334 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55335 if (dialog_creator_)
336 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07337
[email protected]da8543762012-03-20 08:52:20338 if (color_chooser_)
339 color_chooser_->End();
340
[email protected]420ae012009-04-24 05:16:32341 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32342
[email protected]ca13a442012-04-17 14:00:12343 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07344 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09345 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
346 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07347 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32348
349 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07350#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32351 // If we still have a window handle, destroy it. GetNativeView can return
352 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42353 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52354 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58355 if (host && host->GetView())
356 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42357 }
[email protected]420ae012009-04-24 05:16:32358#endif
[email protected]7ab1e7d62009-10-14 23:32:01359
360 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15361 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01362 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15363 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01364 }
[email protected]b5a1d11c2011-02-17 03:09:42365
[email protected]2db9bd72012-04-13 20:20:56366 FOR_EACH_OBSERVER(WebContentsObserver,
367 observers_,
368 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08369
[email protected]6934a702011-12-20 00:04:51370 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42371}
372
[email protected]b172aee2012-04-10 17:05:26373WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
374 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54375 WebPreferences prefs;
376
377 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
378
379 prefs.developer_extras_enabled = true;
380 prefs.javascript_enabled =
381 !command_line.HasSwitch(switches::kDisableJavaScript);
382 prefs.web_security_enabled =
383 !command_line.HasSwitch(switches::kDisableWebSecurity);
384 prefs.plugins_enabled =
385 !command_line.HasSwitch(switches::kDisablePlugins);
386 prefs.java_enabled =
387 !command_line.HasSwitch(switches::kDisableJava);
388
389 prefs.uses_page_cache =
390 command_line.HasSwitch(switches::kEnableFastback);
391 prefs.remote_fonts_enabled =
392 !command_line.HasSwitch(switches::kDisableRemoteFonts);
393 prefs.xss_auditor_enabled =
394 !command_line.HasSwitch(switches::kDisableXSSAuditor);
395 prefs.application_cache_enabled =
396 !command_line.HasSwitch(switches::kDisableApplicationCache);
397
398 prefs.local_storage_enabled =
399 !command_line.HasSwitch(switches::kDisableLocalStorage);
400 prefs.databases_enabled =
401 !command_line.HasSwitch(switches::kDisableDatabases);
402 prefs.webaudio_enabled =
403 !command_line.HasSwitch(switches::kDisableWebAudio);
404
405 prefs.experimental_webgl_enabled =
406 GpuProcessHost::gpu_enabled() &&
407 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
408 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
409
410 prefs.gl_multisampling_enabled =
411 !command_line.HasSwitch(switches::kDisableGLMultisampling);
412 prefs.privileged_webgl_extensions_enabled =
413 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
414 prefs.site_specific_quirks_enabled =
415 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
416 prefs.allow_file_access_from_file_urls =
417 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
418 prefs.show_composited_layer_borders =
419 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
420 prefs.show_composited_layer_tree =
421 command_line.HasSwitch(switches::kShowCompositedLayerTree);
422 prefs.show_fps_counter =
423 command_line.HasSwitch(switches::kShowFPSCounter);
424 prefs.accelerated_compositing_enabled =
425 GpuProcessHost::gpu_enabled() &&
426 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54427 prefs.force_compositing_mode =
428 command_line.HasSwitch(switches::kForceCompositingMode);
429 prefs.fixed_position_compositing_enabled =
430 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
431 prefs.accelerated_2d_canvas_enabled =
432 GpuProcessHost::gpu_enabled() &&
433 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58434 prefs.deferred_2d_canvas_enabled =
435 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36436 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31437 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54438 prefs.accelerated_painting_enabled =
439 GpuProcessHost::gpu_enabled() &&
440 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
441 prefs.accelerated_filters_enabled =
442 GpuProcessHost::gpu_enabled() &&
443 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
444 prefs.accelerated_layers_enabled =
445 prefs.accelerated_animation_enabled =
446 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54447 prefs.accelerated_plugins_enabled =
448 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
449 prefs.accelerated_video_enabled =
450 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
451 prefs.partial_swap_enabled =
452 command_line.HasSwitch(switches::kEnablePartialSwap);
453 prefs.interactive_form_validation_enabled =
454 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
455 prefs.fullscreen_enabled =
456 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16457 prefs.css_regions_enabled =
458 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29459 prefs.css_shaders_enabled =
460 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54461
462#if defined(OS_MACOSX)
463 bool default_enable_scroll_animator = true;
464#else
465 // On CrOS, the launcher always passes in the --enable flag.
466 bool default_enable_scroll_animator = false;
467#endif
468 prefs.enable_scroll_animator = default_enable_scroll_animator;
469 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
470 prefs.enable_scroll_animator = true;
471 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
472 prefs.enable_scroll_animator = false;
473
474 prefs.visual_word_movement_enabled =
475 command_line.HasSwitch(switches::kEnableVisualWordMovement);
476 prefs.per_tile_painting_enabled =
477 command_line.HasSwitch(switches::kEnablePerTilePainting);
478
479 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32480 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54481 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11482 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
483 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54484 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11485 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54486 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11487 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54488 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11489 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54490 prefs.gl_multisampling_enabled = false;
491
492 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45493 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32494 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54495 prefs.accelerated_video_enabled = false;
496 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45497 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09498 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54499 }
500 }
501
[email protected]b9535422012-02-09 01:47:59502 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58503 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54504 prefs.loads_images_automatically = true;
505 prefs.javascript_enabled = true;
506 }
507
508 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
509
510 // Force accelerated compositing and 2d canvas off for chrome:, about: and
511 // chrome-devtools: pages (unless it's specifically allowed).
512 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54513 url.SchemeIs(chrome::kChromeUIScheme) ||
514 (url.SchemeIs(chrome::kAboutScheme) &&
515 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25516 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54517 prefs.accelerated_compositing_enabled = false;
518 prefs.accelerated_2d_canvas_enabled = false;
519 }
[email protected]8b3b36152012-05-01 04:55:07520#if defined(OS_MACOSX)
521 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
522 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23523 prefs.default_device_scale_factor =
524 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07525#else
526 if (rvh->GetView()) {
527 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
528 rvh->GetView()->GetNativeView());
529 prefs.default_device_scale_factor =
530 static_cast<int>(monitor.device_scale_factor());
531 } else {
[email protected]82c9a8e2012-05-02 01:07:23532 prefs.default_device_scale_factor =
533 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07534 }
535#endif
[email protected]43d9d782012-03-01 15:40:09536
[email protected]2e21fe292012-03-02 22:52:32537 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54538
539 return prefs;
540}
541
[email protected]b172aee2012-04-10 17:05:26542NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20543 return controller_;
544}
545
[email protected]b172aee2012-04-10 17:05:26546RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28547 return &render_manager_;
548}
549
[email protected]b172aee2012-04-10 17:05:26550bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56551 if (GetWebUI() &&
552 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17553 return true;
[email protected]d2353452012-01-19 19:53:56554 }
[email protected]f82d57b52011-04-27 19:13:17555
[email protected]d8c660432011-12-22 20:51:25556 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
557 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10558 while ((observer = it.GetNext()) != NULL)
559 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53560 return true;
[email protected]403415a2011-01-10 18:57:53561
[email protected]724159a2010-12-30 01:11:18562 bool handled = true;
563 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26564 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58565 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
566 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24567 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
568 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18569 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
570 OnDidLoadResourceFromMemoryCache)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
572 OnDidDisplayInsecureContent)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
574 OnDidRunInsecureContent)
575 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
576 OnDocumentLoadedInFrame)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26578 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
579 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17580 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
581 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25582 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26583 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59584 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21585 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20586 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
587 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
588 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16589 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45590 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10591 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20592 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
593 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
594 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
595 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29596 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50597 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18598 IPC_MESSAGE_UNHANDLED(handled = false)
599 IPC_END_MESSAGE_MAP_EX()
600
601 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38602 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18603 GetRenderProcessHost()->ReceivedBadMessage();
604 }
605
606 return handled;
607}
608
[email protected]b172aee2012-04-10 17:05:26609void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18610 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23611 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51612 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18613}
614
[email protected]b172aee2012-04-10 17:05:26615NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56616 return controller_;
617}
618
[email protected]b172aee2012-04-10 17:05:26619const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56620 return controller_;
621}
622
[email protected]b172aee2012-04-10 17:05:26623content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55624 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30625}
626
[email protected]b172aee2012-04-10 17:05:26627void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56628 view_type_ = type;
629}
630
[email protected]b172aee2012-04-10 17:05:26631content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09632 return view_type_;
633}
634
[email protected]b172aee2012-04-10 17:05:26635const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31636 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23637 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51638 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31639}
640
641
[email protected]b172aee2012-04-10 17:05:26642const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31643 return &property_bag_;
644}
645
[email protected]b172aee2012-04-10 17:05:26646base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31647 return &property_bag_;
648}
649
[email protected]b172aee2012-04-10 17:05:26650content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31651 return delegate_;
652}
653
[email protected]b172aee2012-04-10 17:05:26654void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31655 // TODO(cbentzel): remove this debugging code?
656 if (delegate == delegate_)
657 return;
658 if (delegate_)
659 delegate_->Detach(this);
660 delegate_ = delegate;
661 if (delegate_)
662 delegate_->Attach(this);
663}
664
[email protected]b172aee2012-04-10 17:05:26665content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41666 RenderViewHostImpl* host = render_manager_.current_host();
667 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16668}
669
[email protected]b172aee2012-04-10 17:05:26670RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31671 return render_manager_.current_host();
672}
673
[email protected]b172aee2012-04-10 17:05:26674RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31675 return render_manager_.GetRenderWidgetHostView();
676}
677
[email protected]b172aee2012-04-10 17:05:26678content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31679 return view_.get();
680}
681
[email protected]b172aee2012-04-10 17:05:26682content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50683 WebUIControllerFactory* factory =
684 content::GetContentClient()->browser()->GetWebUIControllerFactory();
685 if (!factory)
686 return NULL;
[email protected]d2353452012-01-19 19:53:56687 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22688 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50689 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22690 if (controller) {
691 web_ui->SetController(controller);
692 return web_ui;
693 }
694
695 delete web_ui;
696 return NULL;
697}
698
[email protected]b172aee2012-04-10 17:05:26699content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31700 return render_manager_.web_ui() ? render_manager_.web_ui()
701 : render_manager_.pending_web_ui();
702}
703
[email protected]b172aee2012-04-10 17:05:26704content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31705 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34706}
707
[email protected]86ef6a392012-05-11 22:03:11708void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
709 user_agent_override_ = override;
710}
711
712const std::string& WebContentsImpl::GetUserAgentOverride() const {
713 return user_agent_override_;
714}
715
[email protected]b172aee2012-04-10 17:05:26716const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55717 // Transient entries take precedence. They are used for interstitial pages
718 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23719 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08720 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20721 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30722 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23723 if (entry) {
[email protected]b5cca982011-05-26 04:42:08724 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23725 }
[email protected]7ade2732011-02-10 00:13:58726 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
727 render_manager_.pending_web_ui() : render_manager_.web_ui();
728 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54729 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55730 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54731 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35732 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22733 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54734 if (!title.empty())
735 return title;
736 }
737 }
738
739 // We use the title for the last committed entry rather than a pending
740 // navigation entry. For example, when the user types in a URL, we want to
741 // keep the old page's title until the new load has committed and we get a new
742 // title.
[email protected]96d185d2009-04-24 03:28:54743 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23744 if (entry) {
[email protected]b5cca982011-05-26 04:42:08745 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23746 }
[email protected]987fc3a2011-05-26 14:18:09747
748 // |page_title_when_no_navigation_entry_| is finally used
749 // if no title cannot be retrieved.
750 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54751}
752
[email protected]b172aee2012-04-10 17:05:26753int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46754 return GetMaxPageIDForSiteInstance(GetSiteInstance());
755}
756
[email protected]b172aee2012-04-10 17:05:26757int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
758 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33759 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
760 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46761
[email protected]b6583592012-01-25 19:52:33762 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34763}
764
[email protected]b172aee2012-04-10 17:05:26765void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46766 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
767}
768
[email protected]b172aee2012-04-10 17:05:26769void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33770 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46771 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33772 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34773}
774
[email protected]b172aee2012-04-10 17:05:26775void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
776 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57777}
778
[email protected]b172aee2012-04-10 17:05:26779SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58780 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54781}
782
[email protected]b172aee2012-04-10 17:05:26783SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38784 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
785 render_manager_.pending_render_view_host() :
786 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58787 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38788}
789
[email protected]b172aee2012-04-10 17:05:26790bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31791 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49792}
793
[email protected]b172aee2012-04-10 17:05:26794bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31795 return waiting_for_response_;
796}
797
[email protected]b172aee2012-04-10 17:05:26798const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31799 return load_state_;
800}
801
[email protected]b172aee2012-04-10 17:05:26802const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return load_state_host_;
804}
805
[email protected]b172aee2012-04-10 17:05:26806uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31807 return upload_size_;
808}
809
[email protected]b172aee2012-04-10 17:05:26810uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31811 return upload_position_;
812}
813
[email protected]b172aee2012-04-10 17:05:26814const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31815 return encoding_;
816}
817
[email protected]b172aee2012-04-10 17:05:26818bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31819 return displayed_insecure_content_;
820}
821
[email protected]b172aee2012-04-10 17:05:26822void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31823 capturing_contents_ = cap;
824}
825
[email protected]b172aee2012-04-10 17:05:26826bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31827 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
828 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
829 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49830}
831
[email protected]b172aee2012-04-10 17:05:26832void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
833 int error_code) {
[email protected]443b80e2010-12-14 00:42:23834 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34835 return;
836
[email protected]443b80e2010-12-14 00:42:23837 crashed_status_ = status;
838 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46839 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34840}
841
[email protected]b172aee2012-04-10 17:05:26842base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return crashed_status_;
844}
845
[email protected]b172aee2012-04-10 17:05:26846bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return is_being_destroyed_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34851 if (delegate_)
852 delegate_->NavigationStateChanged(this, changed_flags);
853}
854
[email protected]b172aee2012-04-10 17:05:26855void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54856 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04857 RenderWidgetHostViewPort* rwhv =
858 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16859 if (rwhv) {
860 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43861#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16862 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43863#endif
864 }
[email protected]96d185d2009-04-24 03:28:54865
[email protected]5ac20162010-11-24 23:33:11866 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38867
[email protected]d8c660432011-12-22 20:51:25868 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59869
870 // The resize rect might have changed while this was inactive -- send the new
871 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58872 RenderViewHostImpl* rvh =
873 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59874 if (rvh) {
875 rvh->ResizeRectChanged(GetRootWindowResizerRect());
876 }
[email protected]96d185d2009-04-24 03:28:54877}
878
[email protected]be1f56ab2011-12-22 06:55:31879
[email protected]b172aee2012-04-10 17:05:26880base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31881 return last_selected_time_;
882}
883
[email protected]b172aee2012-04-10 17:05:26884void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31885 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52886 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
887 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26888 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52889 // removes the |GetRenderViewHost()|; then when we actually destroy the
890 // window, OnWindowPosChanged() notices and calls HideContents() (which
891 // calls us).
[email protected]c30585c2012-02-16 15:02:04892 RenderWidgetHostViewPort* rwhv =
893 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16894 if (rwhv)
895 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54896 }
897
[email protected]ad50def52011-10-19 23:17:07898 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09899 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
900 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07901 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54902}
903
[email protected]b172aee2012-04-10 17:05:26904void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04905 RenderWidgetHostViewPort* rwhv =
906 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31907 if (rwhv)
908 rwhv->DidBecomeSelected();
909}
910
[email protected]b172aee2012-04-10 17:05:26911void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31912 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
913 // our superclass HideContents(), because some callers want to be very picky
914 // about the order in which these get called. In addition to making the code
915 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26916 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
917 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31918 WasHidden();
919}
920
[email protected]b172aee2012-04-10 17:05:26921bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31922 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27923 return WillNotifyDisconnection() &&
924 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58925 !static_cast<RenderViewHostImpl*>(
926 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31927}
928
[email protected]b172aee2012-04-10 17:05:26929void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27930 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25931 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27932}
933
[email protected]b172aee2012-04-10 17:05:26934WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44935 // We use our current SiteInstance since the cloned entry will use it anyway.
936 // We pass |this| for the |base_web_contents| to size the view correctly, and
937 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26938 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44939 GetBrowserContext(), GetSiteInstance(),
940 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20941 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27942 return tc;
943}
944
[email protected]b172aee2012-04-10 17:05:26945void WebContentsImpl::AddNewContents(WebContents* new_contents,
946 WindowOpenDisposition disposition,
947 const gfx::Rect& initial_pos,
948 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27949 if (!delegate_)
950 return;
951
952 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
953 user_gesture);
954}
955
[email protected]b172aee2012-04-10 17:05:26956gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27957 return view_->GetContentNativeView();
958}
959
[email protected]b172aee2012-04-10 17:05:26960gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27961 return view_->GetNativeView();
962}
963
[email protected]b172aee2012-04-10 17:05:26964void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27965 view_->GetContainerBounds(out);
966}
967
[email protected]b172aee2012-04-10 17:05:26968void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27969 view_->Focus();
970}
971
[email protected]14392a52012-05-02 20:28:44972void WebContentsImpl::Observe(int type,
973 const content::NotificationSource& source,
974 const content::NotificationDetails& details) {
975 switch (type) {
976 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
977 OnWebContentsDestroyed(
978 content::Source<content::WebContents>(source).ptr());
979 break;
980 default:
981 NOTREACHED();
982 }
983}
984
985void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
986 // Clear the opener if it has been closed.
987 if (web_contents == opener_) {
988 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
989 content::Source<WebContents>(opener_));
990 opener_ = NULL;
991 }
992}
993
[email protected]b172aee2012-04-10 17:05:26994void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31995 observers_.AddObserver(observer);
996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31999 observers_.RemoveObserver(observer);
1000}
1001
[email protected]b172aee2012-04-10 17:05:261002void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341003 if (delegate_)
1004 delegate_->ActivateContents(this);
1005}
1006
[email protected]b172aee2012-04-10 17:05:261007void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121008 if (delegate_)
1009 delegate_->DeactivateContents(this);
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481013 if (delegate_)
1014 delegate_->LostCapture();
1015}
1016
[email protected]b172aee2012-04-10 17:05:261017bool WebContentsImpl::PreHandleKeyboardEvent(
1018 const NativeWebKeyboardEvent& event,
1019 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481020 return delegate_ &&
1021 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481025 if (delegate_)
1026 delegate_->HandleKeyboardEvent(event);
1027}
1028
[email protected]b172aee2012-04-10 17:05:261029void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431030 if (delegate_)
1031 delegate_->HandleMouseDown();
1032}
1033
[email protected]b172aee2012-04-10 17:05:261034void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481035 if (delegate_)
1036 delegate_->HandleMouseUp();
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481040 if (delegate_)
1041 delegate_->HandleMouseActivate();
1042}
1043
[email protected]b172aee2012-04-10 17:05:261044void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471045 if (delegate_)
1046 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1047}
1048
[email protected]b172aee2012-04-10 17:05:261049bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381050 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121051}
1052
[email protected]42252e02012-04-26 16:29:391053void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371054 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391055 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371056 } else {
1057 GotResponseToLockMouseRequest(false);
1058 }
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371062 if (delegate_)
1063 delegate_->LostMouseLock();
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231067 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331068 if (delegate_)
1069 delegate_->UpdatePreferredSize(this, pref_size);
1070}
1071
[email protected]b172aee2012-04-10 17:05:261072void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341073 if (delegate_)
1074 delegate_->ResizeDueToAutoResize(this, new_size);
1075}
1076
[email protected]b172aee2012-04-10 17:05:261077WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201078 if (!delegate_)
1079 return NULL;
[email protected]00c37fc2011-08-02 00:22:501080
[email protected]e5d549d2011-12-28 01:29:201081 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1082 // Notify observers.
1083 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1084 DidOpenURL(params.url, params.referrer,
1085 params.disposition, params.transition));
1086 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341087}
1088
[email protected]b172aee2012-04-10 17:05:261089bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501090 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251091 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231092 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251093 reload_type);
[email protected]876bc832010-09-07 16:29:541094}
[email protected]96d185d2009-04-24 03:28:541095
[email protected]b172aee2012-04-10 17:05:261096bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231097 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501098 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401099 // The renderer will reject IPC messages with URLs longer than
1100 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511101 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401102 return false;
1103
[email protected]9f76c1e2012-03-05 15:15:581104 RenderViewHostImpl* dest_render_view_host =
1105 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401106 if (!dest_render_view_host)
1107 return false; // Unable to create the desired render view host.
1108
[email protected]80a8fad2011-01-29 04:02:381109 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071110 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581111 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501112 WebUIControllerFactory* factory =
1113 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271114 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501115 bool is_allowed_in_web_ui_renderer =
1116 factory &&
[email protected]24e18252012-04-16 21:26:271117 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1118 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231119 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1120 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271121 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231122 content::GetContentClient()->SetActiveURL(entry.GetURL());
1123 CHECK(0);
1124 }
[email protected]54ec6472010-04-09 19:39:581125
[email protected]96d185d2009-04-24 03:28:541126 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441127 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521128 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441129 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511130 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541131
1132 // Used for page load time metrics.
1133 current_load_start_ = base::TimeTicks::Now();
1134
1135 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341136 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271137 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471138 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341139 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541140
[email protected]36fc0392011-12-25 03:59:511141 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541142 // HACK!! This code suppresses javascript: URLs from being added to
1143 // session history, which is what we want to do for javascript: URLs that
1144 // do not generate content. What we really need is a message from the
1145 // renderer telling us that a new page was not created. The same message
1146 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511147 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541148 return false;
1149 }
1150
[email protected]3c9e1872010-11-18 16:17:491151 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251152 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041153 observers_,
[email protected]36fc0392011-12-25 03:59:511154 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541155
[email protected]09b29342011-06-24 19:18:481156 if (delegate_)
1157 delegate_->DidNavigateToPendingEntry(this);
1158
[email protected]d5f942ba2008-09-26 19:30:341159 return true;
1160}
1161
[email protected]b172aee2012-04-10 17:05:261162void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331163 const SiteInstance* site_instance,
1164 int history_length,
1165 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411166 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1167 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191168 if (render_manager_.pending_render_view_host()) {
1169 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141170 return;
[email protected]9e1ad4b2011-08-14 16:49:191171 }
[email protected]9f76c1e2012-03-05 15:15:581172 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191173 if (!rvh) {
1174 NOTREACHED();
1175 return;
1176 }
[email protected]9f76c1e2012-03-05 15:15:581177 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191178 NOTREACHED();
1179 return;
1180 }
[email protected]9f76c1e2012-03-05 15:15:581181 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191182 history_length,
1183 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141184}
1185
[email protected]b172aee2012-04-10 17:05:261186void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271187 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541188 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1189 return;
1190 }
[email protected]9f76c1e2012-03-05 15:15:581191 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541192}
1193
[email protected]b172aee2012-04-10 17:05:261194bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271195 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541196}
1197
[email protected]b172aee2012-04-10 17:05:261198InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271199 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221200}
1201
[email protected]b172aee2012-04-10 17:05:261202bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161203 // WebKit creates Document object when MIME type is application/xhtml+xml,
1204 // so we also support this MIME type.
1205 return contents_mime_type_ == "text/html" ||
1206 contents_mime_type_ == "text/xml" ||
1207 contents_mime_type_ == "application/xhtml+xml" ||
1208 contents_mime_type_ == "text/plain" ||
1209 contents_mime_type_ == "text/css" ||
1210 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1211}
1212
[email protected]b172aee2012-04-10 17:05:261213void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591214 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161215 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481216 download_stats::RecordDownloadSource(
1217 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461218 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141219 return;
[email protected]c7dd2f62011-07-18 15:57:591220 }
1221
1222 Stop();
1223
1224 // Create the save package and possibly prompt the user for the name to save
1225 // the page as. The user prompt is an asynchronous operation that runs on
1226 // another thread.
1227 save_package_ = new SavePackage(this);
1228 save_package_->GetSaveInfo();
1229}
1230
1231// Used in automated testing to bypass prompting the user for file names.
1232// Instead, the names and paths are hard coded rather than running them through
1233// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261234bool WebContentsImpl::SavePage(const FilePath& main_file,
1235 const FilePath& dir_path,
1236 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591237 // Stop the page from navigating.
1238 Stop();
1239
1240 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271241 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591242}
1243
[email protected]b172aee2012-04-10 17:05:261244void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121245 const FilePath& file,
1246 const base::Callback<void(const FilePath&, int64)>& callback) {
1247 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1248}
1249
[email protected]b172aee2012-04-10 17:05:261250bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231251 NavigationEntryImpl* active_entry =
1252 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321253 return (active_entry != NULL &&
1254 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511255 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321256}
1257
[email protected]b172aee2012-04-10 17:05:261258const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271259 return contents_mime_type_;
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271263 return notify_disconnection_;
1264}
1265
[email protected]b172aee2012-04-10 17:05:261266void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311267 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581268 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1269 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161270}
1271
[email protected]b172aee2012-04-10 17:05:261272void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311273 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581274 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1275 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161276}
1277
[email protected]b172aee2012-04-10 17:05:261278content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271279 return &renderer_preferences_;
1280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271283 new_tab_start_time_ = time;
1284}
1285
[email protected]b172aee2012-04-10 17:05:261286base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271287 return new_tab_start_time_;
1288}
1289
[email protected]b172aee2012-04-10 17:05:261290void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151291 if (close_start_time_.is_null())
1292 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011293}
1294
[email protected]b172aee2012-04-10 17:05:261295bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191296#if defined(OS_CHROMEOS)
1297 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1298 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511299 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201300 return false;
1301 return true;
[email protected]46624bf2010-06-09 16:04:191302#else
1303 return true;
1304#endif
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521308 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581309 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511310 if (delegate_)
1311 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341312}
1313
[email protected]b172aee2012-04-10 17:05:261314void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271315 closed_by_user_gesture_ = value;
1316}
1317
[email protected]b172aee2012-04-10 17:05:261318bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271319 return closed_by_user_gesture_;
1320}
1321
[email protected]b172aee2012-04-10 17:05:261322double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051323 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561324 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251325 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171326 return 0;
[email protected]b75b8292010-10-01 07:28:251327
1328 double zoom_level;
1329 if (temporary_zoom_settings_) {
1330 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581331 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251332 } else {
[email protected]2ae88d12011-10-14 09:11:191333 GURL url;
[email protected]10f417c52011-12-28 21:04:231334 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191335 // Since zoom map is updated using rewritten URL, use rewritten URL
1336 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511337 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191338 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251339 }
[email protected]d0b8d092010-10-25 04:05:171340 return zoom_level;
1341}
[email protected]b75b8292010-10-01 07:28:251342
[email protected]b172aee2012-04-10 17:05:261343int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1344 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171345 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011346 // Calculate the zoom percent from the factor. Round up to the nearest whole
1347 // number.
[email protected]b75b8292010-10-01 07:28:251348 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011349 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251350 *enable_decrement = percent > minimum_zoom_percent_;
1351 *enable_increment = percent < maximum_zoom_percent_;
1352 return percent;
1353}
1354
[email protected]b172aee2012-04-10 17:05:261355void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501356 if (!delegate_)
1357 return;
1358
[email protected]10f417c52011-12-28 21:04:231359 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501360 if (!active_entry)
1361 return;
1362
[email protected]36fc0392011-12-25 03:59:511363 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121364}
1365
[email protected]b172aee2012-04-10 17:05:261366void WebContentsImpl::ViewFrameSource(const GURL& url,
1367 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271368 if (!delegate_)
1369 return;
1370
1371 delegate_->ViewSourceForFrame(this, url, content_state);
1372}
1373
[email protected]b172aee2012-04-10 17:05:261374int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271375 return minimum_zoom_percent_;
1376}
1377
[email protected]b172aee2012-04-10 17:05:261378int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271379 return maximum_zoom_percent_;
1380}
1381
[email protected]b172aee2012-04-10 17:05:261382gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231383 return preferred_size_;
1384}
1385
[email protected]b172aee2012-04-10 17:05:261386int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271387 return content_restrictions_;
1388}
1389
[email protected]b172aee2012-04-10 17:05:261390WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501391 WebUIControllerFactory* factory =
1392 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1393 if (!factory)
1394 return WebUI::kNoWebUI;
1395 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271396}
1397
[email protected]b172aee2012-04-10 17:05:261398content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271399 // When there is a pending navigation entry, we want to use the pending WebUI
1400 // that goes along with it to control the basic flags. For example, we want to
1401 // show the pending URL in the URL bar, so we want the display_url flag to
1402 // be from the pending entry.
1403 //
1404 // The confusion comes because there are multiple possibilities for the
1405 // initial load in a tab as a side effect of the way the RenderViewHostManager
1406 // works.
1407 //
1408 // - For the very first tab the load looks "normal". The new tab Web UI is
1409 // the pending one, and we want it to apply here.
1410 //
1411 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1412 // get switched to the one previously associated with the new tab pages.
1413 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1414 // have a committed Web UI in this case.
1415 //
1416 // This condition handles all of these cases:
1417 //
1418 // - First load in first tab: no committed nav entry + pending nav entry +
1419 // pending dom ui:
1420 // -> Use pending Web UI if any.
1421 //
1422 // - First load in second tab: no committed nav entry + pending nav entry +
1423 // no pending Web UI:
1424 // -> Use the committed Web UI if any.
1425 //
1426 // - Second navigation in any tab: committed nav entry + pending nav entry:
1427 // -> Use pending Web UI if any.
1428 //
1429 // - Normal state with no load: committed nav entry + no pending nav entry:
1430 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251431 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271432 (controller_.GetLastCommittedEntry() ||
1433 render_manager_.pending_web_ui()))
1434 return render_manager_.pending_web_ui();
1435 return render_manager_.web_ui();
1436}
1437
[email protected]b172aee2012-04-10 17:05:261438bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271439 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581440 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271441}
1442
[email protected]b172aee2012-04-10 17:05:261443bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441444 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501445}
1446
[email protected]b172aee2012-04-10 17:05:261447void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321448 SkColor color) {
[email protected]da8543762012-03-20 08:52:201449 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1450 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1451}
1452
[email protected]b172aee2012-04-10 17:05:261453void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201454 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1455 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1456 if (delegate_)
1457 delegate_->DidEndColorChooser();
1458 color_chooser_ = NULL;
1459}
1460
[email protected]b172aee2012-04-10 17:05:261461bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471462 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271463 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221464 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231465 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411466 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271467}
1468
[email protected]b172aee2012-04-10 17:05:261469void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271470 if (delegate_)
1471 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211472}
1473
[email protected]b172aee2012-04-10 17:05:261474void WebContentsImpl::OnRegisterIntentService(const string16& action,
1475 const string16& type,
1476 const string16& href,
1477 const string16& title,
1478 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511479 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301480 this, action, type, href, title, disposition);
1481}
1482
[email protected]b172aee2012-04-10 17:05:261483void WebContentsImpl::OnWebIntentDispatch(
1484 const webkit_glue::WebIntentData& intent,
1485 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001486 WebIntentsDispatcherImpl* intents_dispatcher =
1487 new WebIntentsDispatcherImpl(this, intent, intent_id);
1488 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301489}
1490
[email protected]54047eb52012-05-08 21:45:571491void WebContentsImpl::DidStartProvisionalLoadForFrame(
1492 content::RenderViewHost* render_view_host,
1493 int64 frame_id,
1494 bool is_main_frame,
1495 const GURL& opener_url,
1496 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281497 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181498 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451499 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571500 RenderViewHostImpl* render_view_host_impl =
1501 static_cast<RenderViewHostImpl*>(render_view_host);
1502 content::RenderProcessHost* render_process_host =
1503 render_view_host->GetProcess();
1504 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581505 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571506 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451507 false,
[email protected]9f76c1e2012-03-05 15:15:581508 &validated_url);
[email protected]54047eb52012-05-08 21:45:571509 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451510 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571511 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451512 true,
1513 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181514
[email protected]0d60f0192011-04-14 12:40:101515 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101517 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571518 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101519
[email protected]724159a2010-12-30 01:11:181520 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591521 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251522 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451523 ProvisionalChangeToMainFrameUrl(validated_url,
1524 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181525 }
1526}
1527
[email protected]54047eb52012-05-08 21:45:571528void WebContentsImpl::DidRedirectProvisionalLoad(
1529 content::RenderViewHost* render_view_host,
1530 int32 page_id,
1531 const GURL& opener_url,
1532 const GURL& source_url,
1533 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491534 // TODO(creis): Remove this method and have the pre-rendering code listen to
1535 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1536 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451537 GURL validated_source_url(source_url);
1538 GURL validated_target_url(target_url);
1539 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571540 RenderViewHostImpl* render_view_host_impl =
1541 static_cast<RenderViewHostImpl*>(render_view_host);
1542 content::RenderProcessHost* render_process_host =
1543 render_view_host->GetProcess();
1544 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451545 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571546 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451547 false,
1548 &validated_source_url);
[email protected]54047eb52012-05-08 21:45:571549 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451550 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571551 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451552 false,
1553 &validated_target_url);
[email protected]54047eb52012-05-08 21:45:571554 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451555 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571556 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451557 true,
1558 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231559 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571560 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251561 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571562 } else {
1563 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1564 page_id);
1565 }
[email protected]6b7cd8f2012-03-21 21:02:451566 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181567 return;
[email protected]e7d50892011-01-19 21:47:381568
[email protected]4850a7f2011-03-08 23:36:591569 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451571 ProvisionalChangeToMainFrameUrl(validated_target_url,
1572 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181573}
1574
[email protected]54047eb52012-05-08 21:45:571575void WebContentsImpl::DidFailProvisionalLoadWithError(
1576 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581577 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1578 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1579 << ", error_code: " << params.error_code
1580 << ", error_description: " << params.error_description
1581 << ", is_main_frame: " << params.is_main_frame
1582 << ", showing_repost_interstitial: " <<
1583 params.showing_repost_interstitial
1584 << ", frame_id: " << params.frame_id;
1585 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571586 RenderViewHostImpl* render_view_host_impl =
1587 static_cast<RenderViewHostImpl*>(render_view_host);
1588 content::RenderProcessHost* render_process_host =
1589 render_view_host->GetProcess();
1590 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581591 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571592 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451593 false,
[email protected]9f76c1e2012-03-05 15:15:581594 &validated_url);
[email protected]724159a2010-12-30 01:11:181595
[email protected]d7b175e2011-10-11 15:31:581596 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181597 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1598 // This means that the interstitial won't be torn down properly, which is
1599 // bad. But if we have an interstitial, go back to another tab type, and
1600 // then load the same interstitial again, we could end up getting the first
1601 // interstitial's "failed" message (as a result of the cancel) when we're on
1602 // the second one.
1603 //
1604 // We can't tell this apart, so we think we're tearing down the current page
1605 // which will cause a crash later one. There is also some code in
1606 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1607 // out because of this problem.
1608 //
1609 // http://code.google.com/p/chromium/issues/detail?id=2855
1610 // Because this will not tear down the interstitial properly, if "back" is
1611 // back to another tab type, the interstitial will still be somewhat alive
1612 // in the previous tab type. If you navigate somewhere that activates the
1613 // tab with the interstitial again, you'll see a flash before the new load
1614 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271615 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181616 LOG(WARNING) << "Discarding message during interstitial.";
1617 return;
1618 }
1619
[email protected]02102f82011-06-13 20:37:021620 // Discard our pending entry if the load canceled (e.g. if we decided to
1621 // download the file instead of load it). We do not verify that the URL
1622 // being canceled matches the pending entry's URL because they will not
1623 // match if a redirect occurred (in which case we do not want to leave a
1624 // stale redirect URL showing). This means that we also cancel the pending
1625 // entry if the user started a new navigation. As a result, the navigation
1626 // controller may not remember that a load is in progress, but the
1627 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251628 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161629 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181630
[email protected]54047eb52012-05-08 21:45:571631 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181632 }
1633
[email protected]d8c660432011-12-22 20:51:251634 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581635 observers_,
1636 DidFailProvisionalLoad(params.frame_id,
1637 params.is_main_frame,
1638 validated_url,
1639 params.error_code,
1640 params.error_description));
[email protected]724159a2010-12-30 01:11:181641}
1642
[email protected]b172aee2012-04-10 17:05:261643void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181644 const GURL& url,
[email protected]70435962011-08-02 20:13:281645 const std::string& security_info,
1646 const std::string& http_method,
1647 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191648 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181649 cache.Increment();
1650
1651 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081652 int cert_id = 0;
1653 net::CertStatus cert_status = 0;
1654 int security_bits = -1;
1655 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511656 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1657 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301658 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161659 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181660
[email protected]ad50def52011-10-19 23:17:071661 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271662 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501663 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531664 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181665}
1666
[email protected]b172aee2012-04-10 17:05:261667void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381668 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181669 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201670 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181671}
1672
[email protected]b172aee2012-04-10 17:05:261673void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021674 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231675 LOG(INFO) << security_origin << " ran insecure content from "
1676 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381677 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411678 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1679 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181680 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411681 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201682 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181683}
1684
[email protected]b172aee2012-04-10 17:05:261685void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181686 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251687 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101688 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181689}
1690
[email protected]b172aee2012-04-10 17:05:261691void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311692 int64 frame_id,
1693 const GURL& validated_url,
1694 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251695 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311696 DidFinishLoad(frame_id, validated_url, is_main_frame));
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::OnDidFailLoadWithError(
1700 int64 frame_id,
1701 const GURL& validated_url,
1702 bool is_main_frame,
1703 int error_code,
1704 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251705 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311706 DidFailLoad(frame_id, validated_url, is_main_frame,
1707 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181708}
1709
[email protected]b172aee2012-04-10 17:05:261710void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271711 content_restrictions_ = restrictions;
1712 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171713}
1714
[email protected]b172aee2012-04-10 17:05:261715void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261716 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231717 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251718 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261719 if (!entry)
1720 return;
1721 // Note that we don't call NavigationController::GotToOffset() as we don't
1722 // want to create a pending navigation entry (it might end up lingering
1723 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251724 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581725 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511726 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581727 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471728 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571729
1730 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1731 // it in now that we know. This allows us to find the entry when it commits.
1732 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231733 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331734 entry->set_site_instance(
1735 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571736 }
[email protected]216813952011-05-19 22:21:261737 }
1738}
1739
[email protected]b172aee2012-04-10 17:05:261740void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1741 int maximum_percent,
1742 bool remember) {
[email protected]216813952011-05-19 22:21:261743 minimum_zoom_percent_ = minimum_percent;
1744 maximum_zoom_percent_ = maximum_percent;
1745 temporary_zoom_settings_ = !remember;
1746}
1747
[email protected]20b433a2012-05-15 21:23:461748void WebContentsImpl::OnSaveURL(const GURL& url,
1749 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:481750 download_stats::RecordDownloadSource(
1751 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261752 // Check if the URL to save matches the URL of the main frame. Since this
1753 // message originates from Pepper plugins, it may not be the case if the
1754 // plugin is an embedded element.
1755 GURL main_frame_url = GetURL();
1756 if (!main_frame_url.is_valid())
1757 return;
1758 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:461759 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271760}
1761
[email protected]b172aee2012-04-10 17:05:261762void WebContentsImpl::OnEnumerateDirectory(int request_id,
1763 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591764 ChildProcessSecurityPolicyImpl* policy =
1765 ChildProcessSecurityPolicyImpl::GetInstance();
1766 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1767 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211768}
1769
[email protected]b172aee2012-04-10 17:05:261770void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511771 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1775 const GURL& url,
1776 const string16& title) {
[email protected]b9535422012-02-09 01:47:591777 ChildProcessSecurityPolicyImpl* policy =
1778 ChildProcessSecurityPolicyImpl::GetInstance();
1779 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1780 return;
[email protected]6934a702011-12-20 00:04:511781 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201782}
1783
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::OnFindReply(int request_id,
1785 int number_of_matches,
1786 const gfx::Rect& selection_rect,
1787 int active_match_ordinal,
1788 bool final_update) {
[email protected]6934a702011-12-20 00:04:511789 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1790 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001791 // Send a notification to the renderer that we are ready to receive more
1792 // results from the scoping effort of the Find operation. The FindInPage
1793 // scoping is asynchronous and periodically sends results back up to the
1794 // browser using IPC. In an effort to not spam the browser we have the
1795 // browser send an ACK for each FindReply message and have the renderer
1796 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581797 GetRenderViewHostImpl()->Send(
1798 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161799}
1800
[email protected]b172aee2012-04-10 17:05:261801void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1803 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451804}
1805
[email protected]b172aee2012-04-10 17:05:261806void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1807 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101808 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251809 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101810 AppCacheAccessed(manifest_url, blocked_by_policy));
1811}
1812
[email protected]b172aee2012-04-10 17:05:261813void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321814 SkColor color) {
[email protected]da8543762012-03-20 08:52:201815 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1816}
1817
[email protected]b172aee2012-04-10 17:05:261818void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201819 if (color_chooser_ &&
1820 color_chooser_id == color_chooser_->identifier())
1821 color_chooser_->End();
1822}
1823
[email protected]b172aee2012-04-10 17:05:261824void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321825 SkColor color) {
[email protected]da8543762012-03-20 08:52:201826 if (color_chooser_ &&
1827 color_chooser_id == color_chooser_->identifier())
1828 color_chooser_->SetSelectedColor(color);
1829}
1830
[email protected]9f2a9d72012-04-16 16:02:221831void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1832 const FilePath& path,
1833 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441834 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1835 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291836}
1837
[email protected]d0759f492012-04-19 22:50:501838// This exists for render views that don't have a WebUI, but do have WebUI
1839// bindings enabled.
1840void WebContentsImpl::OnWebUISend(const GURL& source_url,
1841 const std::string& name,
1842 const base::ListValue& args) {
1843 if (delegate_)
1844 delegate_->WebUISend(this, source_url, name, args);
1845}
1846
[email protected]96d185d2009-04-24 03:28:541847// Notifies the RenderWidgetHost instance about the fact that the page is
1848// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261849void WebContentsImpl::SetIsLoading(bool is_loading,
1850 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541851 if (is_loading == is_loading_)
1852 return;
1853
1854 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211855 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541856 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561857 upload_size_ = 0;
1858 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541859 }
1860
1861 render_manager_.SetIsLoading(is_loading);
1862
1863 is_loading_ = is_loading;
1864 waiting_for_response_ = is_loading;
1865
[email protected]6ebdc9b2010-09-27 16:55:571866 if (delegate_)
1867 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461868 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541869
[email protected]432115822011-07-10 15:52:271870 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1871 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071872 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541873 if (details)
[email protected]6c2381d2011-10-19 02:52:531874 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071875 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501876 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541877 det);
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131881 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321882 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561883 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381884 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441885 // that opened the window, as long as both renderers have the same
1886 // privileges.
[email protected]1fd1a502011-03-30 16:55:561887 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561888 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581889 // web_ui might be NULL if the URL refers to a non-existent extension.
1890 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401891 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521892 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441893 }
1894 }
[email protected]1fd1a502011-03-30 16:55:561895 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441896 }
1897
[email protected]4e697b042011-07-08 06:44:561898 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321899 // Clear the status bubble. This is a workaround for a bug where WebKit
1900 // doesn't let us know that the cursor left an element during a
1901 // transition (this is also why the mouse cursor remains as a hand after
1902 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1903 // clear the bubble when a user navigates to a named anchor in the same
1904 // page.
[email protected]36fc0392011-12-25 03:59:511905 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321906 }
1907
[email protected]a6e82fc2010-02-24 22:28:141908 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471909 // Once the main frame is navigated, we're no longer considered to have
1910 // displayed insecure content.
1911 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171912 }
[email protected]ce5c4502009-05-06 16:46:111913
[email protected]3c9e1872010-11-18 16:17:491914 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041916 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321917}
1918
[email protected]b172aee2012-04-10 17:05:261919void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321920 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131921 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321922 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061923 // If we navigate off the page, reset JavaScript state. This does nothing
1924 // to prevent a malicious script from spamming messages, since the script
1925 // could just reload the page to stop blocking.
1926 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551927 dialog_creator_->ResetJavaScriptState(this);
1928 dialog_creator_ = NULL;
1929 }
[email protected]420ae012009-04-24 05:16:321930
[email protected]3c9e1872010-11-18 16:17:491931 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251932 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041933 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321934}
1935
[email protected]b172aee2012-04-10 17:05:261936void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461937 // If we are creating a RVH for a restored controller, then we need to make
1938 // sure the RenderView starts with a next_page_id_ larger than the number
1939 // of restored entries. This must be called before the RenderView starts
1940 // navigating (to avoid a race between the browser updating max_page_id and
1941 // the renderer updating next_page_id_). Because of this, we only call this
1942 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561943 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581944 if (max_restored_page_id >
1945 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1946 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1947 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321948}
1949
[email protected]b172aee2012-04-10 17:05:261950bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1951 const string16& title) {
[email protected]420ae012009-04-24 05:16:321952 // For file URLs without a title, use the pathname instead. In the case of a
1953 // synthesized title, we don't want the update to count toward the "one set
1954 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511955 string16 final_title;
[email protected]420ae012009-04-24 05:16:321956 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511957 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1958 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321959 explicit_set = false; // Don't count synthetic titles toward the set limit.
1960 } else {
[email protected]acafd272011-07-26 17:35:571961 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321962 explicit_set = true;
1963 }
1964
[email protected]987fc3a2011-05-26 14:18:091965 // If a page is created via window.open and never navigated,
1966 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551967 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091968 if (entry) {
[email protected]36fc0392011-12-25 03:59:511969 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091970 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321971
[email protected]36fc0392011-12-25 03:59:511972 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091973 } else {
1974 if (page_title_when_no_navigation_entry_ == final_title)
1975 return false; // Nothing changed, don't bother.
1976
1977 page_title_when_no_navigation_entry_ = final_title;
1978 }
[email protected]420ae012009-04-24 05:16:321979
[email protected]420ae012009-04-24 05:16:321980 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231981 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321982
[email protected]2bb171882012-03-07 02:09:461983 std::pair<content::NavigationEntry*, bool> details =
1984 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141985
[email protected]ad50def52011-10-19 23:17:071986 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441987 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1988 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461989 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041990
[email protected]420ae012009-04-24 05:16:321991 return true;
1992}
1993
[email protected]b172aee2012-04-10 17:05:261994void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321995 // After sending out a swap notification, we need to send a disconnect
1996 // notification so that clients that pick up a pointer to |this| can NULL the
1997 // pointer. See Bug 1230284.
1998 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071999 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202000 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2001 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072002 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322006 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072007 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122008 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2009 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072010 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322011}
2012
[email protected]b172aee2012-04-10 17:05:262013void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322014 if (!notify_disconnection_)
2015 return;
2016
2017 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072018 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322019 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2020 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072021 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322022}
2023
[email protected]b172aee2012-04-10 17:05:262024RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322025 return view_.get();
2026}
2027
[email protected]8d3347f2009-07-09 22:00:212028RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262029WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212030 return &render_manager_;
2031}
2032
[email protected]b172aee2012-04-10 17:05:262033content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372034 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462035 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512036}
2037
[email protected]b172aee2012-04-10 17:05:262038WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172039 return this;
2040}
2041
[email protected]b172aee2012-04-10 17:05:262042content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:432043 return view_type_;
[email protected]7b291f92009-08-14 05:43:532044}
2045
[email protected]b172aee2012-04-10 17:05:262046gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172047 if (delegate_)
2048 return delegate_->GetRootWindowResizerRect();
2049 return gfx::Rect();
2050}
2051
[email protected]b172aee2012-04-10 17:05:262052void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442053 // Don't send notifications if we are just creating a swapped-out RVH for
2054 // the opener chain. These won't be used for view-source or WebUI, so it's
2055 // ok to return early.
2056 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2057 return;
2058
[email protected]ad50def52011-10-19 23:17:072059 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272060 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322061 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532062 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232063 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322064 if (!entry)
2065 return;
2066
2067 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352068 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562069 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582070 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322071
2072 if (entry->IsViewSourceMode()) {
2073 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582074 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2075 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322076 }
[email protected]0666aef2009-05-13 19:48:082077
[email protected]d487beefe2011-12-21 05:41:212078 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262079
2080 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252081 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322082}
2083
[email protected]b172aee2012-04-10 17:05:262084void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522085 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322086 // Don't notify the world, since this came from a renderer in the
2087 // background.
2088 return;
2089 }
2090
2091 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312092 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232093 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302094
2095 // Restore the focus to the tab (otherwise the focus will be on the top
2096 // window).
[email protected]484ae5912010-09-29 19:16:142097 if (was_crashed && !FocusLocationBarByDefault() &&
2098 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302099 Focus();
[email protected]484ae5912010-09-29 19:16:142100 }
[email protected]32ded2212011-11-10 18:51:432101
[email protected]d8c660432011-12-22 20:51:252102 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322103}
2104
[email protected]b172aee2012-04-10 17:05:262105void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2106 base::TerminationStatus status,
2107 int error_code) {
[email protected]151a63d2011-12-20 22:32:522108 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322109 // The pending page's RenderViewHost is gone.
2110 return;
2111 }
2112
2113 SetIsLoading(false, NULL);
2114 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232115 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312116 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322117
[email protected]d8c660432011-12-22 20:51:252118 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272119 observers_,
[email protected]be1f56ab2011-12-22 06:55:312120 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322121}
2122
[email protected]b172aee2012-04-10 17:05:262123void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482124 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252125 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062126}
2127
[email protected]b172aee2012-04-10 17:05:262128void WebContentsImpl::DidNavigate(
2129 RenderViewHost* rvh,
2130 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582131 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322132 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372133
[email protected]434f69f2012-02-06 21:56:522134 // Update the site of the SiteInstance if it doesn't have one yet, unless
2135 // this is for about:blank. In that case, the SiteInstance can still be
2136 // considered unused until a navigation to a real page.
2137 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2138 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332139 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522140 }
[email protected]420ae012009-04-24 05:16:322141
2142 // Need to update MIME type here because it's referred to in
2143 // UpdateNavigationCommands() called by RendererDidNavigate() to
2144 // determine whether or not to enable the encoding menu.
2145 // It's updated only for the main frame. For a subframe,
2146 // RenderView::UpdateURL does not set params.contents_mime_type.
2147 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2148 // TODO(jungshik): Add a test for the encoding menu to avoid
2149 // regressing it again.
[email protected]2905f742011-10-13 03:51:582150 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322151 contents_mime_type_ = params.contents_mime_type;
2152
[email protected]8286f51a2011-05-31 17:39:132153 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002154 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392155
[email protected]a9c0bfe2010-09-17 08:35:222156 // Send notification about committed provisional loads. This notification is
2157 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2158 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082159 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072160 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2161 // that is not recorded in the navigation history. For the purpose of
2162 // tracking navigation events, we treat this event as a sub frame navigation
2163 // event.
2164 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582165 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222166 // Whether or not a page transition was triggered by going backward or
2167 // forward in the history is only stored in the navigation controller's
2168 // entry list.
2169 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512170 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582171 content::PAGE_TRANSITION_FORWARD_BACK)) {
2172 transition_type = content::PageTransitionFromInt(
2173 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222174 }
[email protected]0d60f0192011-04-14 12:40:102175 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102177 DidCommitProvisionalLoadForFrame(params.frame_id,
2178 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222179 }
2180
[email protected]76543b92009-08-31 17:27:452181 if (!did_navigate)
2182 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322183
2184 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2185 // for the appropriate notification (best) or you can add it to
2186 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2187 // necessary, please).
2188
2189 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002190 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322191 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512192 if (delegate_)
2193 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002194 }
[email protected]420ae012009-04-24 05:16:322195 DidNavigateAnyFramePostCommit(rvh, details, params);
2196}
2197
[email protected]b172aee2012-04-10 17:05:262198void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2199 int32 page_id,
2200 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152201 // Ensure that this state update comes from either the active RVH or one of
2202 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522203 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322204
2205 // We must be prepared to handle state updates for any page, these occur
2206 // when the user is scrolling and entering form data, as well as when we're
2207 // leaving a page, in which case our state may have already been moved to
2208 // the next page. The navigation controller will look up the appropriate
2209 // NavigationEntry and update it when it is notified via the delegate.
2210
2211 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582212 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322213 if (entry_index < 0)
2214 return;
[email protected]10f417c52011-12-28 21:04:232215 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322216
[email protected]36fc0392011-12-25 03:59:512217 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322218 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512219 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322220 controller_.NotifyEntryChanged(entry, entry_index);
2221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2224 int32 page_id,
2225 const string16& title,
2226 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322227 // If we have a title, that's a pretty good indication that we've started
2228 // getting useful data.
2229 SetNotWaitingForResponse();
2230
[email protected]73eb2602012-02-09 19:50:552231 // Try to find the navigation entry, which might not be the current one.
2232 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232233 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582234 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092235
[email protected]73eb2602012-02-09 19:50:552236 // We can handle title updates when we don't have an entry in
2237 // UpdateTitleForEntry, but only if the update is from the current RVH.
2238 if (!entry && rvh != GetRenderViewHost())
2239 return;
2240
[email protected]a49e10b2011-08-01 23:57:462241 // TODO(evan): make use of title_direction.
2242 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092243 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322244 return;
2245
2246 // Broadcast notifications when the UI should be updated.
2247 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462248 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322249}
2250
[email protected]b172aee2012-04-10 17:05:262251void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2252 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312253 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322254}
2255
[email protected]b172aee2012-04-10 17:05:262256void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512257 if (delegate_)
2258 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322259}
2260
[email protected]b172aee2012-04-10 17:05:262261void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292262 // The UI may be in an event-tracking loop, such as between the
2263 // mouse-down and mouse-up in text selection or a button click.
2264 // Defer the close until after tracking is complete, so that we
2265 // don't free objects out from under the UI.
2266 // TODO(shess): This could probably be integrated with the
2267 // IsDoingDrag() test below. Punting for now because I need more
2268 // research to understand how this impacts platforms other than Mac.
2269 // TODO(shess): This could get more fine-grained. For instance,
2270 // closing a tab in another window while selecting text in the
2271 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212272 if (GetView()->IsEventTracking()) {
2273 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292274 return;
2275 }
2276
[email protected]24a4d1062009-07-10 23:10:422277 // If we close the tab while we're in the middle of a drag, we'll crash.
2278 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212279 if (GetView()->IsDoingDrag()) {
2280 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422281 return;
2282 }
2283
[email protected]420ae012009-04-24 05:16:322284 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522285 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512286 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322287}
2288
[email protected]b172aee2012-04-10 17:05:262289void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522290 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512291 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572292}
2293
[email protected]b172aee2012-04-10 17:05:262294void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512295 if (delegate_ && delegate_->IsPopupOrPanel(this))
2296 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322297}
2298
[email protected]b172aee2012-04-10 17:05:262299void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322300 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492301
[email protected]82114f52012-03-20 22:53:412302 if (delegate_ && content_restrictions_)
2303 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492304
2305 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252306 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322307}
2308
[email protected]b172aee2012-04-10 17:05:262309void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322310 scoped_ptr<LoadNotificationDetails> details;
2311
[email protected]10f417c52011-12-28 21:04:232312 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322313 // An entry may not exist for a stop when loading an initial blank page or
2314 // if an iframe injected by script into a blank page finishes loading.
2315 if (entry) {
[email protected]420ae012009-04-24 05:16:322316 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2317
2318 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512319 entry->GetVirtualURL(),
2320 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322321 elapsed,
2322 &controller_,
2323 controller_.GetCurrentEntryIndex()));
2324 }
2325
[email protected]420ae012009-04-24 05:16:322326 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492327
2328 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252329 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162333 controller_.DiscardNonCommittedEntries();
2334
2335 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462336 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162337}
2338
[email protected]b172aee2012-04-10 17:05:262339void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512340 if (delegate_)
2341 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402342}
2343
[email protected]87717d0e2012-04-26 02:58:432344void WebContentsImpl::DocumentAvailableInMainFrame(
2345 RenderViewHost* render_view_host) {
2346 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2347 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102348}
2349
[email protected]b172aee2012-04-10 17:05:262350void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082351 RenderViewHost* render_view_host,
2352 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072353 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272354 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322355 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532356 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082357}
2358
[email protected]196159d2012-05-04 17:26:542359void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2360 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262361 const content::Referrer& referrer,
2362 WindowOpenDisposition disposition,
2363 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542364 // If this came from a swapped out RenderViewHost, we only allow the request
2365 // if we are still in the same BrowsingInstance.
2366 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2367 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2368 return;
2369 }
2370
[email protected]4ad5d77d2011-12-03 02:00:482371 // Delegate to RequestTransferURL because this is just the generic
2372 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582373 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482374 GlobalRequestID());
2375}
2376
[email protected]b172aee2012-04-10 17:05:262377void WebContentsImpl::RequestTransferURL(
2378 const GURL& url,
2379 const content::Referrer& referrer,
2380 WindowOpenDisposition disposition,
2381 int64 source_frame_id,
2382 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202383 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582384 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582385 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352386 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322387 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2388 // generated suggestions).
2389 //
[email protected]e0112912011-02-02 22:54:352390 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162391 // want web sites to see a referrer of "chrome://blah" (and some
2392 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322393 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432394 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222395 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482396 false /* is_renderer_initiated */);
2397 params.transferred_global_request_id = old_request_id;
2398 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222399 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322400 } else {
[email protected]6bf6a6b52012-02-03 15:41:432401 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482402 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2403 params.transferred_global_request_id = old_request_id;
2404 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582405 }
2406 if (new_contents) {
2407 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252408 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582409 DidOpenRequestedURL(new_contents,
2410 url,
2411 referrer,
2412 disposition,
2413 transition_type,
2414 source_frame_id));
[email protected]420ae012009-04-24 05:16:322415 }
2416}
2417
[email protected]e1c3a552012-05-04 20:51:322418void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2419 // Tell the active RenderViewHost to run unload handlers and close, as long
2420 // as the request came from a RenderViewHost in the same BrowsingInstance.
2421 // In most cases, we receive this from a swapped out RenderViewHost.
2422 // It is possible to receive it from one that has just been swapped in,
2423 // in which case we might as well deliver the message anyway.
2424 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2425 GetRenderViewHost()->ClosePage();
2426}
2427
[email protected]f546640b2012-05-15 00:03:492428void WebContentsImpl::RouteMessageEvent(
2429 RenderViewHost* rvh,
2430 const ViewMsg_PostMessage_Params& params) {
2431 // Only deliver the message to the active RenderViewHost if the request
2432 // came from a RenderViewHost in the same BrowsingInstance.
2433 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2434 return;
2435
2436 ViewMsg_PostMessage_Params new_params(params);
2437
2438 // If there is a source_routing_id, translate it to the routing ID for
2439 // the equivalent swapped out RVH in the target process. If we need
2440 // to create a swapped out RVH for the source tab, we create its opener
2441 // chain as well, since those will also be accessible to the target page.
2442 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2443 // Try to look up the WebContents for the source page.
2444 WebContentsImpl* source_contents = NULL;
2445 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2446 rvh->GetProcess()->GetID(), params.source_routing_id);
2447 if (source_rvh) {
2448 source_contents = static_cast<WebContentsImpl*>(
2449 source_rvh->GetDelegate()->GetAsWebContents());
2450 }
2451
2452 if (source_contents) {
2453 new_params.source_routing_id =
2454 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2455 } else {
2456 // We couldn't find it, so don't pass a source frame.
2457 new_params.source_routing_id = MSG_ROUTING_NONE;
2458 }
2459 }
2460
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 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2465 GetRenderViewHost()->GetRoutingID(), new_params));
2466}
2467
[email protected]b172aee2012-04-10 17:05:262468void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342469 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412470 const string16& message,
2471 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322472 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472473 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322474 IPC::Message* reply_msg,
2475 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072476 // Suppress JavaScript dialogs when requested. Also suppress messages when
2477 // showing an interstitial as it's shown over the previous page and we don't
2478 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502479 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582480 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272481 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072482 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522483 delegate_->ShouldSuppressDialogs() ||
2484 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322485
2486 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432487 std::string accept_lang = content::GetContentClient()->browser()->
2488 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552489 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522490 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432491 this,
2492 frame_url.GetOrigin(),
2493 accept_lang,
2494 javascript_message_type,
2495 message,
[email protected]51da7e32012-01-30 19:24:522496 default_prompt,
[email protected]b172aee2012-04-10 17:05:262497 base::Bind(&WebContentsImpl::OnDialogClosed,
2498 base::Unretained(this),
2499 rvh,
2500 reply_msg),
[email protected]51da7e32012-01-30 19:24:522501 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322502 }
[email protected]3ab9cb82011-06-03 18:02:072503
2504 if (suppress_this_message) {
2505 // If we are suppressing messages, just reply as if the user immediately
2506 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342507 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072508 }
2509
2510 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322511}
2512
[email protected]b172aee2012-04-10 17:05:262513void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2514 const string16& message,
2515 bool is_reload,
2516 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582517 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512518 if (delegate_)
2519 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072520
2521 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582522 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072523 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522524 delegate_->ShouldSuppressDialogs() ||
2525 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152526 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342527 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582528 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502529 return;
2530 }
[email protected]3ab9cb82011-06-03 18:02:072531
[email protected]7ab1e7d62009-10-14 23:32:012532 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552533 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522534 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322535 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262536 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522537 reply_msg));
[email protected]420ae012009-04-24 05:16:322538}
2539
[email protected]b172aee2012-04-10 17:05:262540WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332541 // We want to base the page config off of the real URL, rather than the
2542 // display URL.
2543 GURL url = controller_.GetActiveEntry()
2544 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2545 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322546}
2547
[email protected]b172aee2012-04-10 17:05:262548void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272549 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252550 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222551
[email protected]ea114722012-03-12 01:11:252552 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172553 if (rdh) // NULL in unittests.
2554 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252555}
2556
[email protected]b172aee2012-04-10 17:05:262557void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442558 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252559 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442560}
2561
[email protected]b172aee2012-04-10 17:05:262562void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2563 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152564 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522565 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152566 return;
2567
[email protected]9f76c1e2012-03-05 15:15:582568 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2569
[email protected]e5fc1632011-08-08 07:51:532570 // Ignore renderer unresponsive event if debugger is attached to the tab
2571 // since the event may be a result of the renderer sitting on a breakpoint.
2572 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442573 DevToolsAgentHost* agent =
2574 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2575 if (agent &&
2576 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532577 return;
2578
[email protected]420ae012009-04-24 05:16:322579 if (is_during_unload) {
2580 // Hang occurred while firing the beforeunload/unload handler.
2581 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582582 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322583
2584 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2585 return;
2586
2587 // If the tab hangs in the beforeunload/unload handler there's really
2588 // nothing we can do to recover. Pretend the unload listeners have
2589 // all fired and close the tab. If the hang is in the beforeunload handler
2590 // then the user will not have the option of cancelling the close.
2591 Close(rvh);
2592 return;
2593 }
2594
[email protected]9f76c1e2012-03-05 15:15:582595 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472596 return;
2597
[email protected]6934a702011-12-20 00:04:512598 if (delegate_)
2599 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322600}
2601
[email protected]b172aee2012-04-10 17:05:262602void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512603 if (delegate_)
2604 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322605}
2606
[email protected]b172aee2012-04-10 17:05:262607void WebContentsImpl::LoadStateChanged(
2608 const GURL& url,
2609 const net::LoadStateWithParam& load_state,
2610 uint64 upload_position,
2611 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322612 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562613 upload_position_ = upload_position;
2614 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502615 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202616 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302617 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212618 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322619 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462620 if (IsLoading()) {
2621 NotifyNavigationStateChanged(
2622 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2623 }
[email protected]420ae012009-04-24 05:16:322624}
2625
[email protected]b172aee2012-04-10 17:05:262626void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512627 if (delegate_)
2628 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252629}
2630
[email protected]b172aee2012-04-10 17:05:262631void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322632 bool proceed,
2633 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512634 if (delegate_)
2635 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322636}
2637
[email protected]b172aee2012-04-10 17:05:262638void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542639 RenderViewHost* render_view_host) {
2640 DidStartLoading();
2641}
2642
[email protected]b172aee2012-04-10 17:05:262643void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542644 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232645 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2646 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542647}
2648
[email protected]b172aee2012-04-10 17:05:262649void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102650 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262651 gfx::Size size = view_->GetContainerSize();
2652 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2653 // here during container initialization and normal window size will be set
2654 // later. In case of tab duplication this resizing to 0x0 prevents setting
2655 // normal size later so just ignore it.
2656 if (!size.IsEmpty())
2657 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322658}
2659
[email protected]b172aee2012-04-10 17:05:262660void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542661 NotifySwapped();
2662}
2663
[email protected]14392a52012-05-02 20:28:442664int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2665 SiteInstance* instance) {
2666 if (!opener_)
2667 return MSG_ROUTING_NONE;
2668
2669 // Recursively create RenderViews for anything else in the opener chain.
2670 return opener_->CreateOpenerRenderViews(instance);
2671}
2672
2673int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2674 int opener_route_id = MSG_ROUTING_NONE;
2675
2676 // If this tab has an opener, ensure it has a RenderView in the given
2677 // SiteInstance as well.
2678 if (opener_)
2679 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2680
2681 // Create a swapped out RenderView in the given SiteInstance if none exists,
2682 // setting its opener to the given route_id. Return the new view's route_id.
2683 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2684}
2685
[email protected]b172aee2012-04-10 17:05:262686NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202687 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542688}
2689
[email protected]b172aee2012-04-10 17:05:262690WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562691 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322692}
2693
[email protected]10f417c52011-12-28 21:04:232694NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262695 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322696 return controller_.GetLastCommittedEntry();
2697}
2698
[email protected]b172aee2012-04-10 17:05:262699bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442700 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442701 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322702 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522703
[email protected]420ae012009-04-24 05:16:322704 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442705 if (rwh_view)
2706 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322707
[email protected]74ce1ad2011-12-16 21:51:462708 // Make sure we use the correct starting page_id in the new RenderView.
2709 UpdateMaxPageIDIfNecessary(render_view_host);
2710 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582711 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462712
[email protected]9f76c1e2012-03-05 15:15:582713 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492714 render_view_host)->CreateRenderView(string16(),
2715 opener_route_id,
2716 max_page_id,
2717 -1)) {
[email protected]a4127722011-04-27 23:13:522718 return false;
[email protected]14392a52012-05-02 20:28:442719 }
[email protected]a4127722011-04-27 23:13:522720
[email protected]e60c0232011-11-11 19:56:352721#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502722 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2723 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442724 if (rwh_view) {
2725 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2726 render_widget_host->WasResized();
2727 }
[email protected]f8233cc2011-05-31 20:24:502728#endif
2729
[email protected]420ae012009-04-24 05:16:322730 return true;
2731}
2732
[email protected]b172aee2012-04-10 17:05:262733void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2734 IPC::Message* reply_msg,
2735 bool success,
2736 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542737 if (is_showing_before_unload_dialog_ && !success) {
2738 // If a beforeunload dialog is canceled, we need to stop the throbber from
2739 // spinning, since we forced it to start spinning in Navigate.
2740 DidStopLoading();
2741
[email protected]3bbacc5b2012-04-17 17:46:152742 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542743 }
2744 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582745 static_cast<RenderViewHostImpl*>(
2746 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542747}
2748
[email protected]b172aee2012-04-10 17:05:262749void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122750 encoding_ = content::GetContentClient()->browser()->
2751 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102752}
[email protected]f45d2a72010-03-08 23:28:352753
[email protected]b172aee2012-04-10 17:05:262754void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:462755 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262756 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142757 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2758 if (!dlm)
2759 return;
2760 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262761 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142762 const NavigationEntry* entry = controller_.GetActiveEntry();
2763 if (entry)
2764 post_id = entry->GetPostID();
2765 }
[email protected]29a5ffc82012-03-13 19:35:582766 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142767 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:142768 scoped_ptr<DownloadUrlParameters> params(
2769 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]20b433a2012-05-15 21:23:462770 // TODO(jochen): Pass in the referrer policy as well.
2771 params->set_referrer(referrer.url);
[email protected]c5a5c0842012-05-04 20:05:142772 params->set_post_id(post_id);
2773 params->set_prefer_cache(true);
2774 if (post_id >= 0)
2775 params->set_method("POST");
2776 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:142777}
2778
[email protected]b172aee2012-04-10 17:05:262779void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212780 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442781 // Can be NULL during tests.
2782 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212783 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362784}
[email protected]9f76c1e2012-03-05 15:15:582785
[email protected]b172aee2012-04-10 17:05:262786RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582787 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2788}