blob: 4164a988384f250cbf3306aea89ff7245507920d [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]8dd709fb2012-04-06 00:49:0617#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2531#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3733#include "content/browser/web_contents/interstitial_page_impl.h"
34#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5635#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5137#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0238#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5839#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2041#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]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]e5d549d2011-12-28 01:29:20132using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56133using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13134using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27135using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50136using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23137using content::NavigationEntry;
138using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20139using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11140using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57141using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27142using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11143using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58144using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04145using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25146using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43147using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33148using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17149using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38150using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09151using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25152using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56153using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22154using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50155using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44156
[email protected]420ae012009-04-24 05:16:32157namespace {
158
159// Amount of time we wait between when a key event is received and the renderer
160// is queried for its state and pushed to the NavigationEntry.
161const int kQueryStateDelay = 5000;
162
[email protected]6ebdc9b2010-09-27 16:55:57163const int kSyncWaitDelay = 40;
164
[email protected]82114f52012-03-20 22:53:41165const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05166
[email protected]420ae012009-04-24 05:16:32167#if defined(OS_WIN)
168
169BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
170 // Note: erase is required to properly paint some widgets borders. This can
171 // be seen with textfields.
172 InvalidateRect(hwnd, NULL, TRUE);
173 return TRUE;
174}
175#endif
176
[email protected]2c5569662011-03-22 20:45:02177ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23178 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50179 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16180 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47181 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02182 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47185 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16186 break; // Fall through to rest of function.
187 }
[email protected]5e369672009-11-03 23:48:30188
[email protected]59246c572012-02-10 13:32:13189 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
190 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23191 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13192 browser_context->DidLastSessionExitCleanly()) {
193 if (entry.GetHasPostData())
194 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13196 }
[email protected]5e369672009-11-03 23:48:30197
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30199}
200
[email protected]10f417c52011-12-28 21:04:23201void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47202 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42203 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50204 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16205 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51206 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54207 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55208 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
209 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51210 params->url = entry.GetURL();
211 params->referrer = entry.GetReferrer();
212 params->transition = entry.GetTransitionType();
213 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00214 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55215 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34216 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47217 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48218 params->transferred_request_child_id =
219 entry.transferred_global_request_id().child_id;
220 params->transferred_request_request_id =
221 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00222 // Avoid downloading when in view-source mode.
223 params->allow_download = !entry.IsViewSourceMode();
[email protected]6c6b02d2011-09-02 03:36:47224
225 if (delegate)
226 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34227}
228
[email protected]420ae012009-04-24 05:16:32229} // namespace
230
[email protected]a81343d232011-12-27 07:39:20231namespace content {
232
233WebContents* WebContents::Create(
234 BrowserContext* browser_context,
235 SiteInstance* site_instance,
236 int routing_id,
[email protected]b172aee2012-04-10 17:05:26237 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20238 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26239 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43240 browser_context,
241 site_instance,
242 routing_id,
[email protected]b172aee2012-04-10 17:05:26243 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44244 NULL,
[email protected]adbfb8df2012-02-24 01:19:43245 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20246}
247}
[email protected]f4f50ef2011-01-21 19:01:19248
[email protected]b172aee2012-04-10 17:05:26249// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32250
[email protected]b172aee2012-04-10 17:05:26251WebContentsImpl::WebContentsImpl(
252 content::BrowserContext* browser_context,
253 SiteInstance* site_instance,
254 int routing_id,
255 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44256 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26257 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42258 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07259 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37260 this, browser_context, session_storage_namespace)),
[email protected]14392a52012-05-02 20:28:44261 opener_(opener),
[email protected]d82ed61e2009-06-16 02:46:22262 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34263 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23264 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
265 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34266 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21267 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56268 upload_size_(0),
269 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47270 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57271 capturing_contents_(false),
272 is_being_destroyed_(false),
273 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55274 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57275#if defined(OS_WIN)
276 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
277#endif
[email protected]7ab1e7d62009-10-14 23:32:01278 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56279 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38280 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25281 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01282 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25283 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01284 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00285 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43286 content_restrictions_(0),
[email protected]e018d3b2012-04-17 13:24:15287 view_type_(content::VIEW_TYPE_WEB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20288 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37289 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32290
[email protected]38b098f2012-03-14 21:11:57291 view_.reset(content::GetContentClient()->browser()->
292 OverrideCreateWebContentsView(this));
293 if (!view_.get()) {
294 content::WebContentsViewDelegate* delegate =
295 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
296 this);
[email protected]68b52252012-04-04 19:26:13297#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:35298 view_.reset(new WebContentsViewAura(this, delegate));
[email protected]68b52252012-04-04 19:26:13299#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:35300 view_.reset(new WebContentsViewWin(this, delegate));
[email protected]38b098f2012-03-14 21:11:57301#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:35302 view_.reset(new content::WebContentsViewGtk(this, delegate));
[email protected]38b098f2012-03-14 21:11:57303#elif defined(OS_MACOSX)
304 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
305#elif defined(OS_ANDROID)
306 view_.reset(new WebContentsViewAndroid(this));
307#endif
[email protected]dbd407f2012-03-14 21:30:37308 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57309 }
310 CHECK(view_.get());
311
[email protected]ca13a442012-04-17 14:00:12312 // We have the initial size of the view be based on the size of the view of
313 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26314 view_->CreateView(base_web_contents ?
315 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00316
[email protected]14392a52012-05-02 20:28:44317 // Listen for whether our opener gets destroyed.
318 if (opener_) {
319 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
320 content::Source<WebContents>(opener_));
321 }
322
[email protected]483623eb2011-10-25 09:30:00323#if defined(ENABLE_JAVA_BRIDGE)
324 java_bridge_dispatcher_host_manager_.reset(
325 new JavaBridgeDispatcherHostManager(this));
326#endif
[email protected]8dd709fb2012-04-06 00:49:06327
328 browser_plugin_web_contents_observer_.reset(
329 new content::BrowserPluginWebContentsObserver(this));
[email protected]332af7732009-03-11 13:21:35330}
initial.commit09911bf2008-07-26 23:55:29331
[email protected]b172aee2012-04-10 17:05:26332WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32333 is_being_destroyed_ = true;
334
[email protected]3ab9cb82011-06-03 18:02:07335 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55336 if (dialog_creator_)
337 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07338
[email protected]da8543762012-03-20 08:52:20339 if (color_chooser_)
340 color_chooser_->End();
341
[email protected]420ae012009-04-24 05:16:32342 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32343
[email protected]ca13a442012-04-17 14:00:12344 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07345 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09346 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
347 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07348 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32349
350 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07351#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32352 // If we still have a window handle, destroy it. GetNativeView can return
353 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42354 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52355 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58356 if (host && host->GetView())
357 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42358 }
[email protected]420ae012009-04-24 05:16:32359#endif
[email protected]7ab1e7d62009-10-14 23:32:01360
361 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15362 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01363 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15364 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01365 }
[email protected]b5a1d11c2011-02-17 03:09:42366
[email protected]2db9bd72012-04-13 20:20:56367 FOR_EACH_OBSERVER(WebContentsObserver,
368 observers_,
369 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08370
[email protected]6934a702011-12-20 00:04:51371 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42372}
373
[email protected]b172aee2012-04-10 17:05:26374WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
375 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54376 WebPreferences prefs;
377
378 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
379
380 prefs.developer_extras_enabled = true;
381 prefs.javascript_enabled =
382 !command_line.HasSwitch(switches::kDisableJavaScript);
383 prefs.web_security_enabled =
384 !command_line.HasSwitch(switches::kDisableWebSecurity);
385 prefs.plugins_enabled =
386 !command_line.HasSwitch(switches::kDisablePlugins);
387 prefs.java_enabled =
388 !command_line.HasSwitch(switches::kDisableJava);
389
390 prefs.uses_page_cache =
391 command_line.HasSwitch(switches::kEnableFastback);
392 prefs.remote_fonts_enabled =
393 !command_line.HasSwitch(switches::kDisableRemoteFonts);
394 prefs.xss_auditor_enabled =
395 !command_line.HasSwitch(switches::kDisableXSSAuditor);
396 prefs.application_cache_enabled =
397 !command_line.HasSwitch(switches::kDisableApplicationCache);
398
399 prefs.local_storage_enabled =
400 !command_line.HasSwitch(switches::kDisableLocalStorage);
401 prefs.databases_enabled =
402 !command_line.HasSwitch(switches::kDisableDatabases);
403 prefs.webaudio_enabled =
404 !command_line.HasSwitch(switches::kDisableWebAudio);
405
406 prefs.experimental_webgl_enabled =
407 GpuProcessHost::gpu_enabled() &&
408 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
409 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
410
411 prefs.gl_multisampling_enabled =
412 !command_line.HasSwitch(switches::kDisableGLMultisampling);
413 prefs.privileged_webgl_extensions_enabled =
414 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
415 prefs.site_specific_quirks_enabled =
416 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
417 prefs.allow_file_access_from_file_urls =
418 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
419 prefs.show_composited_layer_borders =
420 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
421 prefs.show_composited_layer_tree =
422 command_line.HasSwitch(switches::kShowCompositedLayerTree);
423 prefs.show_fps_counter =
424 command_line.HasSwitch(switches::kShowFPSCounter);
425 prefs.accelerated_compositing_enabled =
426 GpuProcessHost::gpu_enabled() &&
427 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54428 prefs.force_compositing_mode =
429 command_line.HasSwitch(switches::kForceCompositingMode);
430 prefs.fixed_position_compositing_enabled =
431 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
432 prefs.accelerated_2d_canvas_enabled =
433 GpuProcessHost::gpu_enabled() &&
434 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58435 prefs.deferred_2d_canvas_enabled =
436 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36437 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31438 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54439 prefs.accelerated_painting_enabled =
440 GpuProcessHost::gpu_enabled() &&
441 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
442 prefs.accelerated_filters_enabled =
443 GpuProcessHost::gpu_enabled() &&
444 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
445 prefs.accelerated_layers_enabled =
446 prefs.accelerated_animation_enabled =
447 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54448 prefs.accelerated_plugins_enabled =
449 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
450 prefs.accelerated_video_enabled =
451 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
452 prefs.partial_swap_enabled =
453 command_line.HasSwitch(switches::kEnablePartialSwap);
454 prefs.interactive_form_validation_enabled =
455 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
456 prefs.fullscreen_enabled =
457 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16458 prefs.css_regions_enabled =
459 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29460 prefs.css_shaders_enabled =
461 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54462
463#if defined(OS_MACOSX)
464 bool default_enable_scroll_animator = true;
465#else
466 // On CrOS, the launcher always passes in the --enable flag.
467 bool default_enable_scroll_animator = false;
468#endif
469 prefs.enable_scroll_animator = default_enable_scroll_animator;
470 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
471 prefs.enable_scroll_animator = true;
472 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
473 prefs.enable_scroll_animator = false;
474
475 prefs.visual_word_movement_enabled =
476 command_line.HasSwitch(switches::kEnableVisualWordMovement);
477 prefs.per_tile_painting_enabled =
478 command_line.HasSwitch(switches::kEnablePerTilePainting);
479
480 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32481 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54482 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11483 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
484 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54485 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11486 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54487 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11488 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54489 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11490 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54491 prefs.gl_multisampling_enabled = false;
492
493 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45494 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32495 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54496 prefs.accelerated_video_enabled = false;
497 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45498 prefs.accelerated_layers_enabled = false;
[email protected]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_DidStartProvisionalLoadForFrame,
570 OnDidStartProvisionalLoadForFrame)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
572 OnDidRedirectProvisionalLoad)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
574 OnDidFailProvisionalLoadWithError)
575 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
576 OnDidLoadResourceFromMemoryCache)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
578 OnDidDisplayInsecureContent)
579 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
580 OnDidRunInsecureContent)
581 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
582 OnDocumentLoadedInFrame)
583 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26584 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
585 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17586 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
587 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25588 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26589 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59590 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21591 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20592 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
593 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
594 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16595 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45596 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10597 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20598 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
599 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
600 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
601 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29602 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50603 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18604 IPC_MESSAGE_UNHANDLED(handled = false)
605 IPC_END_MESSAGE_MAP_EX()
606
607 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38608 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18609 GetRenderProcessHost()->ReceivedBadMessage();
610 }
611
612 return handled;
613}
614
[email protected]b172aee2012-04-10 17:05:26615void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18616 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23617 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51618 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18619}
620
[email protected]b172aee2012-04-10 17:05:26621NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56622 return controller_;
623}
624
[email protected]b172aee2012-04-10 17:05:26625const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56626 return controller_;
627}
628
[email protected]b172aee2012-04-10 17:05:26629content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55630 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30631}
632
[email protected]b172aee2012-04-10 17:05:26633void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56634 view_type_ = type;
635}
636
[email protected]b172aee2012-04-10 17:05:26637content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09638 return view_type_;
639}
640
[email protected]b172aee2012-04-10 17:05:26641const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31642 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23643 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51644 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31645}
646
647
[email protected]b172aee2012-04-10 17:05:26648const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31649 return &property_bag_;
650}
651
[email protected]b172aee2012-04-10 17:05:26652base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31653 return &property_bag_;
654}
655
[email protected]b172aee2012-04-10 17:05:26656content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31657 return delegate_;
658}
659
[email protected]b172aee2012-04-10 17:05:26660void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31661 // TODO(cbentzel): remove this debugging code?
662 if (delegate == delegate_)
663 return;
664 if (delegate_)
665 delegate_->Detach(this);
666 delegate_ = delegate;
667 if (delegate_)
668 delegate_->Attach(this);
669}
670
[email protected]b172aee2012-04-10 17:05:26671content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41672 RenderViewHostImpl* host = render_manager_.current_host();
673 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16674}
675
[email protected]b172aee2012-04-10 17:05:26676RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31677 return render_manager_.current_host();
678}
679
[email protected]b172aee2012-04-10 17:05:26680RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31681 return render_manager_.GetRenderWidgetHostView();
682}
683
[email protected]b172aee2012-04-10 17:05:26684content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31685 return view_.get();
686}
687
[email protected]b172aee2012-04-10 17:05:26688content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50689 WebUIControllerFactory* factory =
690 content::GetContentClient()->browser()->GetWebUIControllerFactory();
691 if (!factory)
692 return NULL;
[email protected]d2353452012-01-19 19:53:56693 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22694 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50695 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22696 if (controller) {
697 web_ui->SetController(controller);
698 return web_ui;
699 }
700
701 delete web_ui;
702 return NULL;
703}
704
[email protected]b172aee2012-04-10 17:05:26705content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31706 return render_manager_.web_ui() ? render_manager_.web_ui()
707 : render_manager_.pending_web_ui();
708}
709
[email protected]b172aee2012-04-10 17:05:26710content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31711 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34712}
713
[email protected]b172aee2012-04-10 17:05:26714const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55715 // Transient entries take precedence. They are used for interstitial pages
716 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23717 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08718 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20719 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30720 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23721 if (entry) {
[email protected]b5cca982011-05-26 04:42:08722 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23723 }
[email protected]7ade2732011-02-10 00:13:58724 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
725 render_manager_.pending_web_ui() : render_manager_.web_ui();
726 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54727 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55728 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54729 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35730 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22731 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54732 if (!title.empty())
733 return title;
734 }
735 }
736
737 // We use the title for the last committed entry rather than a pending
738 // navigation entry. For example, when the user types in a URL, we want to
739 // keep the old page's title until the new load has committed and we get a new
740 // title.
[email protected]96d185d2009-04-24 03:28:54741 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23742 if (entry) {
[email protected]b5cca982011-05-26 04:42:08743 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23744 }
[email protected]987fc3a2011-05-26 14:18:09745
746 // |page_title_when_no_navigation_entry_| is finally used
747 // if no title cannot be retrieved.
748 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54749}
750
[email protected]b172aee2012-04-10 17:05:26751int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46752 return GetMaxPageIDForSiteInstance(GetSiteInstance());
753}
754
[email protected]b172aee2012-04-10 17:05:26755int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
756 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33757 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
758 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46759
[email protected]b6583592012-01-25 19:52:33760 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34761}
762
[email protected]b172aee2012-04-10 17:05:26763void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46764 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
765}
766
[email protected]b172aee2012-04-10 17:05:26767void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33768 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46769 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33770 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34771}
772
[email protected]b172aee2012-04-10 17:05:26773void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
774 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57775}
776
[email protected]b172aee2012-04-10 17:05:26777SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58778 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54779}
780
[email protected]b172aee2012-04-10 17:05:26781SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38782 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
783 render_manager_.pending_render_view_host() :
784 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58785 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38786}
787
[email protected]b172aee2012-04-10 17:05:26788bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31789 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49790}
791
[email protected]b172aee2012-04-10 17:05:26792bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31793 return waiting_for_response_;
794}
795
[email protected]b172aee2012-04-10 17:05:26796const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31797 return load_state_;
798}
799
[email protected]b172aee2012-04-10 17:05:26800const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31801 return load_state_host_;
802}
803
[email protected]b172aee2012-04-10 17:05:26804uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31805 return upload_size_;
806}
807
[email protected]b172aee2012-04-10 17:05:26808uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31809 return upload_position_;
810}
811
[email protected]b172aee2012-04-10 17:05:26812const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31813 return encoding_;
814}
815
[email protected]b172aee2012-04-10 17:05:26816bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31817 return displayed_insecure_content_;
818}
819
[email protected]b172aee2012-04-10 17:05:26820void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31821 capturing_contents_ = cap;
822}
823
[email protected]b172aee2012-04-10 17:05:26824bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
826 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
827 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49828}
829
[email protected]b172aee2012-04-10 17:05:26830void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
831 int error_code) {
[email protected]443b80e2010-12-14 00:42:23832 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34833 return;
834
[email protected]443b80e2010-12-14 00:42:23835 crashed_status_ = status;
836 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46837 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34838}
839
[email protected]b172aee2012-04-10 17:05:26840base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return crashed_status_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return is_being_destroyed_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34849 if (delegate_)
850 delegate_->NavigationStateChanged(this, changed_flags);
851}
852
[email protected]b172aee2012-04-10 17:05:26853void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54854 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04855 RenderWidgetHostViewPort* rwhv =
856 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16857 if (rwhv) {
858 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43859#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16860 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43861#endif
862 }
[email protected]96d185d2009-04-24 03:28:54863
[email protected]5ac20162010-11-24 23:33:11864 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38865
[email protected]d8c660432011-12-22 20:51:25866 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59867
868 // The resize rect might have changed while this was inactive -- send the new
869 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58870 RenderViewHostImpl* rvh =
871 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59872 if (rvh) {
873 rvh->ResizeRectChanged(GetRootWindowResizerRect());
874 }
[email protected]96d185d2009-04-24 03:28:54875}
876
[email protected]be1f56ab2011-12-22 06:55:31877
[email protected]b172aee2012-04-10 17:05:26878base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return last_selected_time_;
880}
881
[email protected]b172aee2012-04-10 17:05:26882void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31883 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52884 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
885 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26886 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52887 // removes the |GetRenderViewHost()|; then when we actually destroy the
888 // window, OnWindowPosChanged() notices and calls HideContents() (which
889 // calls us).
[email protected]c30585c2012-02-16 15:02:04890 RenderWidgetHostViewPort* rwhv =
891 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16892 if (rwhv)
893 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54894 }
895
[email protected]ad50def52011-10-19 23:17:07896 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09897 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
898 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07899 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54900}
901
[email protected]b172aee2012-04-10 17:05:26902void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04903 RenderWidgetHostViewPort* rwhv =
904 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31905 if (rwhv)
906 rwhv->DidBecomeSelected();
907}
908
[email protected]b172aee2012-04-10 17:05:26909void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31910 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
911 // our superclass HideContents(), because some callers want to be very picky
912 // about the order in which these get called. In addition to making the code
913 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26914 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
915 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31916 WasHidden();
917}
918
[email protected]b172aee2012-04-10 17:05:26919bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31920 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27921 return WillNotifyDisconnection() &&
922 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58923 !static_cast<RenderViewHostImpl*>(
924 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31925}
926
[email protected]b172aee2012-04-10 17:05:26927void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27928 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25929 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27930}
931
[email protected]b172aee2012-04-10 17:05:26932WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44933 // We use our current SiteInstance since the cloned entry will use it anyway.
934 // We pass |this| for the |base_web_contents| to size the view correctly, and
935 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26936 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44937 GetBrowserContext(), GetSiteInstance(),
938 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20939 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27940 return tc;
941}
942
[email protected]b172aee2012-04-10 17:05:26943void WebContentsImpl::AddNewContents(WebContents* new_contents,
944 WindowOpenDisposition disposition,
945 const gfx::Rect& initial_pos,
946 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27947 if (!delegate_)
948 return;
949
950 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
951 user_gesture);
952}
953
[email protected]b172aee2012-04-10 17:05:26954gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27955 return view_->GetContentNativeView();
956}
957
[email protected]b172aee2012-04-10 17:05:26958gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27959 return view_->GetNativeView();
960}
961
[email protected]b172aee2012-04-10 17:05:26962void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27963 view_->GetContainerBounds(out);
964}
965
[email protected]b172aee2012-04-10 17:05:26966void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27967 view_->Focus();
968}
969
[email protected]14392a52012-05-02 20:28:44970void WebContentsImpl::Observe(int type,
971 const content::NotificationSource& source,
972 const content::NotificationDetails& details) {
973 switch (type) {
974 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
975 OnWebContentsDestroyed(
976 content::Source<content::WebContents>(source).ptr());
977 break;
978 default:
979 NOTREACHED();
980 }
981}
982
983void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
984 // Clear the opener if it has been closed.
985 if (web_contents == opener_) {
986 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
987 content::Source<WebContents>(opener_));
988 opener_ = NULL;
989 }
990}
991
[email protected]b172aee2012-04-10 17:05:26992void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31993 observers_.AddObserver(observer);
994}
995
[email protected]b172aee2012-04-10 17:05:26996void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31997 observers_.RemoveObserver(observer);
998}
999
[email protected]b172aee2012-04-10 17:05:261000void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341001 if (delegate_)
1002 delegate_->ActivateContents(this);
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121006 if (delegate_)
1007 delegate_->DeactivateContents(this);
1008}
1009
[email protected]b172aee2012-04-10 17:05:261010void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481011 if (delegate_)
1012 delegate_->LostCapture();
1013}
1014
[email protected]b172aee2012-04-10 17:05:261015bool WebContentsImpl::PreHandleKeyboardEvent(
1016 const NativeWebKeyboardEvent& event,
1017 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481018 return delegate_ &&
1019 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1020}
1021
[email protected]b172aee2012-04-10 17:05:261022void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481023 if (delegate_)
1024 delegate_->HandleKeyboardEvent(event);
1025}
1026
[email protected]b172aee2012-04-10 17:05:261027void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431028 if (delegate_)
1029 delegate_->HandleMouseDown();
1030}
1031
[email protected]b172aee2012-04-10 17:05:261032void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481033 if (delegate_)
1034 delegate_->HandleMouseUp();
1035}
1036
[email protected]b172aee2012-04-10 17:05:261037void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481038 if (delegate_)
1039 delegate_->HandleMouseActivate();
1040}
1041
[email protected]b172aee2012-04-10 17:05:261042void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471043 if (delegate_)
1044 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1045}
1046
[email protected]b172aee2012-04-10 17:05:261047bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381048 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121049}
1050
[email protected]42252e02012-04-26 16:29:391051void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371052 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391053 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371054 } else {
1055 GotResponseToLockMouseRequest(false);
1056 }
1057}
1058
[email protected]b172aee2012-04-10 17:05:261059void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371060 if (delegate_)
1061 delegate_->LostMouseLock();
1062}
1063
[email protected]b172aee2012-04-10 17:05:261064void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231065 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331066 if (delegate_)
1067 delegate_->UpdatePreferredSize(this, pref_size);
1068}
1069
[email protected]b172aee2012-04-10 17:05:261070void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341071 if (delegate_)
1072 delegate_->ResizeDueToAutoResize(this, new_size);
1073}
1074
[email protected]b172aee2012-04-10 17:05:261075WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201076 if (!delegate_)
1077 return NULL;
[email protected]00c37fc2011-08-02 00:22:501078
[email protected]e5d549d2011-12-28 01:29:201079 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1080 // Notify observers.
1081 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1082 DidOpenURL(params.url, params.referrer,
1083 params.disposition, params.transition));
1084 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341085}
1086
[email protected]b172aee2012-04-10 17:05:261087bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501088 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251089 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231090 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251091 reload_type);
[email protected]876bc832010-09-07 16:29:541092}
[email protected]96d185d2009-04-24 03:28:541093
[email protected]b172aee2012-04-10 17:05:261094bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231095 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501096 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401097 // The renderer will reject IPC messages with URLs longer than
1098 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511099 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401100 return false;
1101
[email protected]9f76c1e2012-03-05 15:15:581102 RenderViewHostImpl* dest_render_view_host =
1103 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401104 if (!dest_render_view_host)
1105 return false; // Unable to create the desired render view host.
1106
[email protected]80a8fad2011-01-29 04:02:381107 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071108 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581109 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501110 WebUIControllerFactory* factory =
1111 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271112 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501113 bool is_allowed_in_web_ui_renderer =
1114 factory &&
[email protected]24e18252012-04-16 21:26:271115 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1116 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231117 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1118 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271119 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231120 content::GetContentClient()->SetActiveURL(entry.GetURL());
1121 CHECK(0);
1122 }
[email protected]54ec6472010-04-09 19:39:581123
[email protected]96d185d2009-04-24 03:28:541124 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441125 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521126 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441127 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511128 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541129
1130 // Used for page load time metrics.
1131 current_load_start_ = base::TimeTicks::Now();
1132
1133 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341134 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271135 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471136 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341137 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541138
[email protected]36fc0392011-12-25 03:59:511139 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541140 // HACK!! This code suppresses javascript: URLs from being added to
1141 // session history, which is what we want to do for javascript: URLs that
1142 // do not generate content. What we really need is a message from the
1143 // renderer telling us that a new page was not created. The same message
1144 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511145 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541146 return false;
1147 }
1148
[email protected]3c9e1872010-11-18 16:17:491149 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251150 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041151 observers_,
[email protected]36fc0392011-12-25 03:59:511152 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541153
[email protected]09b29342011-06-24 19:18:481154 if (delegate_)
1155 delegate_->DidNavigateToPendingEntry(this);
1156
[email protected]d5f942ba2008-09-26 19:30:341157 return true;
1158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331161 const SiteInstance* site_instance,
1162 int history_length,
1163 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411164 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1165 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191166 if (render_manager_.pending_render_view_host()) {
1167 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141168 return;
[email protected]9e1ad4b2011-08-14 16:49:191169 }
[email protected]9f76c1e2012-03-05 15:15:581170 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191171 if (!rvh) {
1172 NOTREACHED();
1173 return;
1174 }
[email protected]9f76c1e2012-03-05 15:15:581175 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191176 NOTREACHED();
1177 return;
1178 }
[email protected]9f76c1e2012-03-05 15:15:581179 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191180 history_length,
1181 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141182}
1183
[email protected]b172aee2012-04-10 17:05:261184void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271185 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541186 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1187 return;
1188 }
[email protected]9f76c1e2012-03-05 15:15:581189 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541190}
1191
[email protected]b172aee2012-04-10 17:05:261192bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271193 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541194}
1195
[email protected]b172aee2012-04-10 17:05:261196InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271197 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221198}
1199
[email protected]b172aee2012-04-10 17:05:261200bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161201 // WebKit creates Document object when MIME type is application/xhtml+xml,
1202 // so we also support this MIME type.
1203 return contents_mime_type_ == "text/html" ||
1204 contents_mime_type_ == "text/xml" ||
1205 contents_mime_type_ == "application/xhtml+xml" ||
1206 contents_mime_type_ == "text/plain" ||
1207 contents_mime_type_ == "text/css" ||
1208 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1209}
1210
[email protected]b172aee2012-04-10 17:05:261211void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591212 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161213 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481214 download_stats::RecordDownloadSource(
1215 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261216 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141217 return;
[email protected]c7dd2f62011-07-18 15:57:591218 }
1219
1220 Stop();
1221
1222 // Create the save package and possibly prompt the user for the name to save
1223 // the page as. The user prompt is an asynchronous operation that runs on
1224 // another thread.
1225 save_package_ = new SavePackage(this);
1226 save_package_->GetSaveInfo();
1227}
1228
1229// Used in automated testing to bypass prompting the user for file names.
1230// Instead, the names and paths are hard coded rather than running them through
1231// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261232bool WebContentsImpl::SavePage(const FilePath& main_file,
1233 const FilePath& dir_path,
1234 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591235 // Stop the page from navigating.
1236 Stop();
1237
1238 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1239 return save_package_->Init();
1240}
1241
[email protected]b172aee2012-04-10 17:05:261242void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121243 const FilePath& file,
1244 const base::Callback<void(const FilePath&, int64)>& callback) {
1245 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1246}
1247
[email protected]b172aee2012-04-10 17:05:261248bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231249 NavigationEntryImpl* active_entry =
1250 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321251 return (active_entry != NULL &&
1252 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511253 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321254}
1255
[email protected]b172aee2012-04-10 17:05:261256const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271257 return contents_mime_type_;
1258}
1259
[email protected]b172aee2012-04-10 17:05:261260bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271261 return notify_disconnection_;
1262}
1263
[email protected]b172aee2012-04-10 17:05:261264void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311265 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581266 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1267 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311271 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581272 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1273 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161274}
1275
[email protected]b172aee2012-04-10 17:05:261276content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271277 return &renderer_preferences_;
1278}
1279
[email protected]b172aee2012-04-10 17:05:261280void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271281 new_tab_start_time_ = time;
1282}
1283
[email protected]b172aee2012-04-10 17:05:261284base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271285 return new_tab_start_time_;
1286}
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151289 if (close_start_time_.is_null())
1290 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011291}
1292
[email protected]b172aee2012-04-10 17:05:261293bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191294#if defined(OS_CHROMEOS)
1295 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1296 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511297 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201298 return false;
1299 return true;
[email protected]46624bf2010-06-09 16:04:191300#else
1301 return true;
1302#endif
1303}
1304
[email protected]b172aee2012-04-10 17:05:261305void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521306 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581307 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511308 if (delegate_)
1309 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341310}
1311
[email protected]b172aee2012-04-10 17:05:261312void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271313 closed_by_user_gesture_ = value;
1314}
1315
[email protected]b172aee2012-04-10 17:05:261316bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271317 return closed_by_user_gesture_;
1318}
1319
[email protected]b172aee2012-04-10 17:05:261320double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051321 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561322 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251323 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171324 return 0;
[email protected]b75b8292010-10-01 07:28:251325
1326 double zoom_level;
1327 if (temporary_zoom_settings_) {
1328 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581329 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251330 } else {
[email protected]2ae88d12011-10-14 09:11:191331 GURL url;
[email protected]10f417c52011-12-28 21:04:231332 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191333 // Since zoom map is updated using rewritten URL, use rewritten URL
1334 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511335 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191336 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251337 }
[email protected]d0b8d092010-10-25 04:05:171338 return zoom_level;
1339}
[email protected]b75b8292010-10-01 07:28:251340
[email protected]b172aee2012-04-10 17:05:261341int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1342 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171343 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011344 // Calculate the zoom percent from the factor. Round up to the nearest whole
1345 // number.
[email protected]b75b8292010-10-01 07:28:251346 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011347 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251348 *enable_decrement = percent > minimum_zoom_percent_;
1349 *enable_increment = percent < maximum_zoom_percent_;
1350 return percent;
1351}
1352
[email protected]b172aee2012-04-10 17:05:261353void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501354 if (!delegate_)
1355 return;
1356
[email protected]10f417c52011-12-28 21:04:231357 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501358 if (!active_entry)
1359 return;
1360
[email protected]36fc0392011-12-25 03:59:511361 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121362}
1363
[email protected]b172aee2012-04-10 17:05:261364void WebContentsImpl::ViewFrameSource(const GURL& url,
1365 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271366 if (!delegate_)
1367 return;
1368
1369 delegate_->ViewSourceForFrame(this, url, content_state);
1370}
1371
[email protected]b172aee2012-04-10 17:05:261372int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271373 return minimum_zoom_percent_;
1374}
1375
[email protected]b172aee2012-04-10 17:05:261376int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271377 return maximum_zoom_percent_;
1378}
1379
[email protected]b172aee2012-04-10 17:05:261380gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231381 return preferred_size_;
1382}
1383
[email protected]b172aee2012-04-10 17:05:261384int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271385 return content_restrictions_;
1386}
1387
[email protected]b172aee2012-04-10 17:05:261388WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501389 WebUIControllerFactory* factory =
1390 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1391 if (!factory)
1392 return WebUI::kNoWebUI;
1393 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271394}
1395
[email protected]b172aee2012-04-10 17:05:261396content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271397 // When there is a pending navigation entry, we want to use the pending WebUI
1398 // that goes along with it to control the basic flags. For example, we want to
1399 // show the pending URL in the URL bar, so we want the display_url flag to
1400 // be from the pending entry.
1401 //
1402 // The confusion comes because there are multiple possibilities for the
1403 // initial load in a tab as a side effect of the way the RenderViewHostManager
1404 // works.
1405 //
1406 // - For the very first tab the load looks "normal". The new tab Web UI is
1407 // the pending one, and we want it to apply here.
1408 //
1409 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1410 // get switched to the one previously associated with the new tab pages.
1411 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1412 // have a committed Web UI in this case.
1413 //
1414 // This condition handles all of these cases:
1415 //
1416 // - First load in first tab: no committed nav entry + pending nav entry +
1417 // pending dom ui:
1418 // -> Use pending Web UI if any.
1419 //
1420 // - First load in second tab: no committed nav entry + pending nav entry +
1421 // no pending Web UI:
1422 // -> Use the committed Web UI if any.
1423 //
1424 // - Second navigation in any tab: committed nav entry + pending nav entry:
1425 // -> Use pending Web UI if any.
1426 //
1427 // - Normal state with no load: committed nav entry + no pending nav entry:
1428 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251429 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271430 (controller_.GetLastCommittedEntry() ||
1431 render_manager_.pending_web_ui()))
1432 return render_manager_.pending_web_ui();
1433 return render_manager_.web_ui();
1434}
1435
[email protected]b172aee2012-04-10 17:05:261436bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271437 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581438 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271439}
1440
[email protected]b172aee2012-04-10 17:05:261441bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441442 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501443}
1444
[email protected]b172aee2012-04-10 17:05:261445void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321446 SkColor color) {
[email protected]da8543762012-03-20 08:52:201447 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1448 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1449}
1450
[email protected]b172aee2012-04-10 17:05:261451void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201452 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1453 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1454 if (delegate_)
1455 delegate_->DidEndColorChooser();
1456 color_chooser_ = NULL;
1457}
1458
[email protected]b172aee2012-04-10 17:05:261459bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471460 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271461 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221462 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231463 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411464 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271465}
1466
[email protected]b172aee2012-04-10 17:05:261467void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271468 if (delegate_)
1469 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211470}
1471
[email protected]b172aee2012-04-10 17:05:261472void WebContentsImpl::OnRegisterIntentService(const string16& action,
1473 const string16& type,
1474 const string16& href,
1475 const string16& title,
1476 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511477 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301478 this, action, type, href, title, disposition);
1479}
1480
[email protected]b172aee2012-04-10 17:05:261481void WebContentsImpl::OnWebIntentDispatch(
1482 const webkit_glue::WebIntentData& intent,
1483 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001484 WebIntentsDispatcherImpl* intents_dispatcher =
1485 new WebIntentsDispatcherImpl(this, intent, intent_id);
1486 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301487}
1488
[email protected]b172aee2012-04-10 17:05:261489void WebContentsImpl::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1490 bool is_main_frame,
1491 const GURL& opener_url,
1492 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281493 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181494 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451495 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581496 GetRenderViewHostImpl()->FilterURL(
1497 ChildProcessSecurityPolicyImpl::GetInstance(),
1498 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451499 false,
[email protected]9f76c1e2012-03-05 15:15:581500 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451501 GetRenderViewHostImpl()->FilterURL(
1502 ChildProcessSecurityPolicyImpl::GetInstance(),
1503 GetRenderProcessHost()->GetID(),
1504 true,
1505 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181506
[email protected]8093a542011-05-13 07:29:321507 RenderViewHost* rvh =
1508 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521509 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101510 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101512 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321513 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101514
[email protected]724159a2010-12-30 01:11:181515 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591516 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251517 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451518 ProvisionalChangeToMainFrameUrl(validated_url,
1519 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181520 }
1521}
1522
[email protected]b172aee2012-04-10 17:05:261523void WebContentsImpl::OnDidRedirectProvisionalLoad(int32 page_id,
1524 const GURL& opener_url,
1525 const GURL& source_url,
1526 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491527 // TODO(creis): Remove this method and have the pre-rendering code listen to
1528 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1529 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451530 GURL validated_source_url(source_url);
1531 GURL validated_target_url(target_url);
1532 GURL validated_opener_url(opener_url);
1533 GetRenderViewHostImpl()->FilterURL(
1534 ChildProcessSecurityPolicyImpl::GetInstance(),
1535 GetRenderProcessHost()->GetID(),
1536 false,
1537 &validated_source_url);
1538 GetRenderViewHostImpl()->FilterURL(
1539 ChildProcessSecurityPolicyImpl::GetInstance(),
1540 GetRenderProcessHost()->GetID(),
1541 false,
1542 &validated_target_url);
1543 GetRenderViewHostImpl()->FilterURL(
1544 ChildProcessSecurityPolicyImpl::GetInstance(),
1545 GetRenderProcessHost()->GetID(),
1546 true,
1547 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231548 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181549 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251550 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181551 else
1552 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451553 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181554 return;
[email protected]e7d50892011-01-19 21:47:381555
[email protected]4850a7f2011-03-08 23:36:591556 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251557 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451558 ProvisionalChangeToMainFrameUrl(validated_target_url,
1559 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181560}
1561
[email protected]b172aee2012-04-10 17:05:261562void WebContentsImpl::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581563 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1564 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1565 << ", error_code: " << params.error_code
1566 << ", error_description: " << params.error_description
1567 << ", is_main_frame: " << params.is_main_frame
1568 << ", showing_repost_interstitial: " <<
1569 params.showing_repost_interstitial
1570 << ", frame_id: " << params.frame_id;
1571 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581572 GetRenderViewHostImpl()->FilterURL(
1573 ChildProcessSecurityPolicyImpl::GetInstance(),
1574 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451575 false,
[email protected]9f76c1e2012-03-05 15:15:581576 &validated_url);
[email protected]724159a2010-12-30 01:11:181577
[email protected]d7b175e2011-10-11 15:31:581578 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181579 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1580 // This means that the interstitial won't be torn down properly, which is
1581 // bad. But if we have an interstitial, go back to another tab type, and
1582 // then load the same interstitial again, we could end up getting the first
1583 // interstitial's "failed" message (as a result of the cancel) when we're on
1584 // the second one.
1585 //
1586 // We can't tell this apart, so we think we're tearing down the current page
1587 // which will cause a crash later one. There is also some code in
1588 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1589 // out because of this problem.
1590 //
1591 // http://code.google.com/p/chromium/issues/detail?id=2855
1592 // Because this will not tear down the interstitial properly, if "back" is
1593 // back to another tab type, the interstitial will still be somewhat alive
1594 // in the previous tab type. If you navigate somewhere that activates the
1595 // tab with the interstitial again, you'll see a flash before the new load
1596 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271597 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181598 LOG(WARNING) << "Discarding message during interstitial.";
1599 return;
1600 }
1601
[email protected]02102f82011-06-13 20:37:021602 // Discard our pending entry if the load canceled (e.g. if we decided to
1603 // download the file instead of load it). We do not verify that the URL
1604 // being canceled matches the pending entry's URL because they will not
1605 // match if a redirect occurred (in which case we do not want to leave a
1606 // stale redirect URL showing). This means that we also cancel the pending
1607 // entry if the user started a new navigation. As a result, the navigation
1608 // controller may not remember that a load is in progress, but the
1609 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251610 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161611 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181612
[email protected]151a63d2011-12-20 22:32:521613 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181614 }
1615
[email protected]d8c660432011-12-22 20:51:251616 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581617 observers_,
1618 DidFailProvisionalLoad(params.frame_id,
1619 params.is_main_frame,
1620 validated_url,
1621 params.error_code,
1622 params.error_description));
[email protected]724159a2010-12-30 01:11:181623}
1624
[email protected]b172aee2012-04-10 17:05:261625void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181626 const GURL& url,
[email protected]70435962011-08-02 20:13:281627 const std::string& security_info,
1628 const std::string& http_method,
1629 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191630 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181631 cache.Increment();
1632
1633 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081634 int cert_id = 0;
1635 net::CertStatus cert_status = 0;
1636 int security_bits = -1;
1637 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511638 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1639 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301640 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161641 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181642
[email protected]ad50def52011-10-19 23:17:071643 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271644 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501645 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531646 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181647}
1648
[email protected]b172aee2012-04-10 17:05:261649void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381650 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181651 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201652 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181653}
1654
[email protected]b172aee2012-04-10 17:05:261655void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021656 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231657 LOG(INFO) << security_origin << " ran insecure content from "
1658 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381659 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411660 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1661 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181662 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411663 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201664 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181665}
1666
[email protected]b172aee2012-04-10 17:05:261667void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181668 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251669 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101670 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181671}
1672
[email protected]b172aee2012-04-10 17:05:261673void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311674 int64 frame_id,
1675 const GURL& validated_url,
1676 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251677 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311678 DidFinishLoad(frame_id, validated_url, is_main_frame));
1679}
1680
[email protected]b172aee2012-04-10 17:05:261681void WebContentsImpl::OnDidFailLoadWithError(
1682 int64 frame_id,
1683 const GURL& validated_url,
1684 bool is_main_frame,
1685 int error_code,
1686 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251687 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311688 DidFailLoad(frame_id, validated_url, is_main_frame,
1689 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181690}
1691
[email protected]b172aee2012-04-10 17:05:261692void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271693 content_restrictions_ = restrictions;
1694 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171695}
1696
[email protected]b172aee2012-04-10 17:05:261697void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261698 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231699 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251700 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261701 if (!entry)
1702 return;
1703 // Note that we don't call NavigationController::GotToOffset() as we don't
1704 // want to create a pending navigation entry (it might end up lingering
1705 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251706 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581707 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511708 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581709 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471710 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571711
1712 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1713 // it in now that we know. This allows us to find the entry when it commits.
1714 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231715 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331716 entry->set_site_instance(
1717 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571718 }
[email protected]216813952011-05-19 22:21:261719 }
1720}
1721
[email protected]b172aee2012-04-10 17:05:261722void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1723 int maximum_percent,
1724 bool remember) {
[email protected]216813952011-05-19 22:21:261725 minimum_zoom_percent_ = minimum_percent;
1726 maximum_zoom_percent_ = maximum_percent;
1727 temporary_zoom_settings_ = !remember;
1728}
1729
[email protected]b172aee2012-04-10 17:05:261730void WebContentsImpl::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481731 download_stats::RecordDownloadSource(
1732 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261733 // Check if the URL to save matches the URL of the main frame. Since this
1734 // message originates from Pepper plugins, it may not be the case if the
1735 // plugin is an embedded element.
1736 GURL main_frame_url = GetURL();
1737 if (!main_frame_url.is_valid())
1738 return;
1739 bool is_main_frame = (url == main_frame_url);
1740 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271741}
1742
[email protected]b172aee2012-04-10 17:05:261743void WebContentsImpl::OnEnumerateDirectory(int request_id,
1744 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591745 ChildProcessSecurityPolicyImpl* policy =
1746 ChildProcessSecurityPolicyImpl::GetInstance();
1747 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1748 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211749}
1750
[email protected]b172aee2012-04-10 17:05:261751void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511752 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201753}
1754
[email protected]b172aee2012-04-10 17:05:261755void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1756 const GURL& url,
1757 const string16& title) {
[email protected]b9535422012-02-09 01:47:591758 ChildProcessSecurityPolicyImpl* policy =
1759 ChildProcessSecurityPolicyImpl::GetInstance();
1760 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1761 return;
[email protected]6934a702011-12-20 00:04:511762 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201763}
1764
[email protected]b172aee2012-04-10 17:05:261765void WebContentsImpl::OnFindReply(int request_id,
1766 int number_of_matches,
1767 const gfx::Rect& selection_rect,
1768 int active_match_ordinal,
1769 bool final_update) {
[email protected]6934a702011-12-20 00:04:511770 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1771 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001772 // Send a notification to the renderer that we are ready to receive more
1773 // results from the scoping effort of the Find operation. The FindInPage
1774 // scoping is asynchronous and periodically sends results back up to the
1775 // browser using IPC. In an effort to not spam the browser we have the
1776 // browser send an ACK for each FindReply message and have the renderer
1777 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581778 GetRenderViewHostImpl()->Send(
1779 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161780}
1781
[email protected]b172aee2012-04-10 17:05:261782void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441783 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1784 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451785}
1786
[email protected]b172aee2012-04-10 17:05:261787void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1788 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101789 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101791 AppCacheAccessed(manifest_url, blocked_by_policy));
1792}
1793
[email protected]b172aee2012-04-10 17:05:261794void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321795 SkColor color) {
[email protected]da8543762012-03-20 08:52:201796 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1797}
1798
[email protected]b172aee2012-04-10 17:05:261799void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201800 if (color_chooser_ &&
1801 color_chooser_id == color_chooser_->identifier())
1802 color_chooser_->End();
1803}
1804
[email protected]b172aee2012-04-10 17:05:261805void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321806 SkColor color) {
[email protected]da8543762012-03-20 08:52:201807 if (color_chooser_ &&
1808 color_chooser_id == color_chooser_->identifier())
1809 color_chooser_->SetSelectedColor(color);
1810}
1811
[email protected]9f2a9d72012-04-16 16:02:221812void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1813 const FilePath& path,
1814 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441815 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1816 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291817}
1818
[email protected]d0759f492012-04-19 22:50:501819// This exists for render views that don't have a WebUI, but do have WebUI
1820// bindings enabled.
1821void WebContentsImpl::OnWebUISend(const GURL& source_url,
1822 const std::string& name,
1823 const base::ListValue& args) {
1824 if (delegate_)
1825 delegate_->WebUISend(this, source_url, name, args);
1826}
1827
[email protected]96d185d2009-04-24 03:28:541828// Notifies the RenderWidgetHost instance about the fact that the page is
1829// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261830void WebContentsImpl::SetIsLoading(bool is_loading,
1831 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541832 if (is_loading == is_loading_)
1833 return;
1834
1835 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211836 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541837 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561838 upload_size_ = 0;
1839 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541840 }
1841
1842 render_manager_.SetIsLoading(is_loading);
1843
1844 is_loading_ = is_loading;
1845 waiting_for_response_ = is_loading;
1846
[email protected]6ebdc9b2010-09-27 16:55:571847 if (delegate_)
1848 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461849 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541850
[email protected]432115822011-07-10 15:52:271851 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1852 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071853 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541854 if (details)
[email protected]6c2381d2011-10-19 02:52:531855 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071856 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501857 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541858 det);
1859}
1860
[email protected]b172aee2012-04-10 17:05:261861void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131862 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321863 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561864 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381865 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441866 // that opened the window, as long as both renderers have the same
1867 // privileges.
[email protected]1fd1a502011-03-30 16:55:561868 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561869 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581870 // web_ui might be NULL if the URL refers to a non-existent extension.
1871 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401872 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521873 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441874 }
1875 }
[email protected]1fd1a502011-03-30 16:55:561876 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441877 }
1878
[email protected]4e697b042011-07-08 06:44:561879 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321880 // Clear the status bubble. This is a workaround for a bug where WebKit
1881 // doesn't let us know that the cursor left an element during a
1882 // transition (this is also why the mouse cursor remains as a hand after
1883 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1884 // clear the bubble when a user navigates to a named anchor in the same
1885 // page.
[email protected]36fc0392011-12-25 03:59:511886 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321887 }
1888
[email protected]a6e82fc2010-02-24 22:28:141889 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471890 // Once the main frame is navigated, we're no longer considered to have
1891 // displayed insecure content.
1892 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171893 }
[email protected]ce5c4502009-05-06 16:46:111894
[email protected]3c9e1872010-11-18 16:17:491895 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251896 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041897 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321898}
1899
[email protected]b172aee2012-04-10 17:05:261900void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321901 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131902 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321903 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061904 // If we navigate off the page, reset JavaScript state. This does nothing
1905 // to prevent a malicious script from spamming messages, since the script
1906 // could just reload the page to stop blocking.
1907 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551908 dialog_creator_->ResetJavaScriptState(this);
1909 dialog_creator_ = NULL;
1910 }
[email protected]420ae012009-04-24 05:16:321911
[email protected]3c9e1872010-11-18 16:17:491912 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251913 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041914 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321915}
1916
[email protected]b172aee2012-04-10 17:05:261917void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461918 // If we are creating a RVH for a restored controller, then we need to make
1919 // sure the RenderView starts with a next_page_id_ larger than the number
1920 // of restored entries. This must be called before the RenderView starts
1921 // navigating (to avoid a race between the browser updating max_page_id and
1922 // the renderer updating next_page_id_). Because of this, we only call this
1923 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561924 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581925 if (max_restored_page_id >
1926 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1927 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1928 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321929}
1930
[email protected]b172aee2012-04-10 17:05:261931bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1932 const string16& title) {
[email protected]420ae012009-04-24 05:16:321933 // For file URLs without a title, use the pathname instead. In the case of a
1934 // synthesized title, we don't want the update to count toward the "one set
1935 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511936 string16 final_title;
[email protected]420ae012009-04-24 05:16:321937 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511938 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1939 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321940 explicit_set = false; // Don't count synthetic titles toward the set limit.
1941 } else {
[email protected]acafd272011-07-26 17:35:571942 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321943 explicit_set = true;
1944 }
1945
[email protected]987fc3a2011-05-26 14:18:091946 // If a page is created via window.open and never navigated,
1947 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551948 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091949 if (entry) {
[email protected]36fc0392011-12-25 03:59:511950 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091951 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321952
[email protected]36fc0392011-12-25 03:59:511953 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091954 } else {
1955 if (page_title_when_no_navigation_entry_ == final_title)
1956 return false; // Nothing changed, don't bother.
1957
1958 page_title_when_no_navigation_entry_ = final_title;
1959 }
[email protected]420ae012009-04-24 05:16:321960
[email protected]420ae012009-04-24 05:16:321961 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231962 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321963
[email protected]2bb171882012-03-07 02:09:461964 std::pair<content::NavigationEntry*, bool> details =
1965 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141966
[email protected]ad50def52011-10-19 23:17:071967 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441968 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1969 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461970 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041971
[email protected]420ae012009-04-24 05:16:321972 return true;
1973}
1974
[email protected]b172aee2012-04-10 17:05:261975void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321976 // After sending out a swap notification, we need to send a disconnect
1977 // notification so that clients that pick up a pointer to |this| can NULL the
1978 // pointer. See Bug 1230284.
1979 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071980 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201981 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1982 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071983 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321984}
1985
[email protected]b172aee2012-04-10 17:05:261986void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:321987 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071988 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121989 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1990 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071991 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321992}
1993
[email protected]b172aee2012-04-10 17:05:261994void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:321995 if (!notify_disconnection_)
1996 return;
1997
1998 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071999 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322000 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
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:262005RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322006 return view_.get();
2007}
2008
[email protected]8d3347f2009-07-09 22:00:212009RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262010WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212011 return &render_manager_;
2012}
2013
[email protected]b172aee2012-04-10 17:05:262014content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372015 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462016 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512017}
2018
[email protected]b172aee2012-04-10 17:05:262019WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172020 return this;
2021}
2022
[email protected]b172aee2012-04-10 17:05:262023content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:432024 return view_type_;
[email protected]7b291f92009-08-14 05:43:532025}
2026
[email protected]b172aee2012-04-10 17:05:262027gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172028 if (delegate_)
2029 return delegate_->GetRootWindowResizerRect();
2030 return gfx::Rect();
2031}
2032
[email protected]b172aee2012-04-10 17:05:262033void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442034 // Don't send notifications if we are just creating a swapped-out RVH for
2035 // the opener chain. These won't be used for view-source or WebUI, so it's
2036 // ok to return early.
2037 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2038 return;
2039
[email protected]ad50def52011-10-19 23:17:072040 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272041 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322042 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532043 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232044 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322045 if (!entry)
2046 return;
2047
2048 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352049 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562050 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582051 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322052
2053 if (entry->IsViewSourceMode()) {
2054 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582055 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2056 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322057 }
[email protected]0666aef2009-05-13 19:48:082058
[email protected]d487beefe2011-12-21 05:41:212059 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262060
2061 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252062 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322063}
2064
[email protected]b172aee2012-04-10 17:05:262065void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522066 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322067 // Don't notify the world, since this came from a renderer in the
2068 // background.
2069 return;
2070 }
2071
2072 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312073 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232074 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302075
2076 // Restore the focus to the tab (otherwise the focus will be on the top
2077 // window).
[email protected]484ae5912010-09-29 19:16:142078 if (was_crashed && !FocusLocationBarByDefault() &&
2079 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302080 Focus();
[email protected]484ae5912010-09-29 19:16:142081 }
[email protected]32ded2212011-11-10 18:51:432082
[email protected]d8c660432011-12-22 20:51:252083 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322084}
2085
[email protected]b172aee2012-04-10 17:05:262086void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2087 base::TerminationStatus status,
2088 int error_code) {
[email protected]151a63d2011-12-20 22:32:522089 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322090 // The pending page's RenderViewHost is gone.
2091 return;
2092 }
2093
2094 SetIsLoading(false, NULL);
2095 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232096 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312097 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322098
[email protected]d8c660432011-12-22 20:51:252099 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272100 observers_,
[email protected]be1f56ab2011-12-22 06:55:312101 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482105 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252106 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::DidNavigate(
2110 RenderViewHost* rvh,
2111 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582112 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322113 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372114
[email protected]434f69f2012-02-06 21:56:522115 // Update the site of the SiteInstance if it doesn't have one yet, unless
2116 // this is for about:blank. In that case, the SiteInstance can still be
2117 // considered unused until a navigation to a real page.
2118 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2119 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332120 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522121 }
[email protected]420ae012009-04-24 05:16:322122
2123 // Need to update MIME type here because it's referred to in
2124 // UpdateNavigationCommands() called by RendererDidNavigate() to
2125 // determine whether or not to enable the encoding menu.
2126 // It's updated only for the main frame. For a subframe,
2127 // RenderView::UpdateURL does not set params.contents_mime_type.
2128 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2129 // TODO(jungshik): Add a test for the encoding menu to avoid
2130 // regressing it again.
[email protected]2905f742011-10-13 03:51:582131 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322132 contents_mime_type_ = params.contents_mime_type;
2133
[email protected]8286f51a2011-05-31 17:39:132134 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002135 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392136
[email protected]a9c0bfe2010-09-17 08:35:222137 // Send notification about committed provisional loads. This notification is
2138 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2139 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082140 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072141 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2142 // that is not recorded in the navigation history. For the purpose of
2143 // tracking navigation events, we treat this event as a sub frame navigation
2144 // event.
2145 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582146 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222147 // Whether or not a page transition was triggered by going backward or
2148 // forward in the history is only stored in the navigation controller's
2149 // entry list.
2150 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512151 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582152 content::PAGE_TRANSITION_FORWARD_BACK)) {
2153 transition_type = content::PageTransitionFromInt(
2154 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222155 }
[email protected]0d60f0192011-04-14 12:40:102156 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252157 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102158 DidCommitProvisionalLoadForFrame(params.frame_id,
2159 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222160 }
2161
[email protected]76543b92009-08-31 17:27:452162 if (!did_navigate)
2163 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322164
2165 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2166 // for the appropriate notification (best) or you can add it to
2167 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2168 // necessary, please).
2169
2170 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002171 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322172 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512173 if (delegate_)
2174 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002175 }
[email protected]420ae012009-04-24 05:16:322176 DidNavigateAnyFramePostCommit(rvh, details, params);
2177}
2178
[email protected]b172aee2012-04-10 17:05:262179void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2180 int32 page_id,
2181 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152182 // Ensure that this state update comes from either the active RVH or one of
2183 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522184 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322185
2186 // We must be prepared to handle state updates for any page, these occur
2187 // when the user is scrolling and entering form data, as well as when we're
2188 // leaving a page, in which case our state may have already been moved to
2189 // the next page. The navigation controller will look up the appropriate
2190 // NavigationEntry and update it when it is notified via the delegate.
2191
2192 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582193 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322194 if (entry_index < 0)
2195 return;
[email protected]10f417c52011-12-28 21:04:232196 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322197
[email protected]36fc0392011-12-25 03:59:512198 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322199 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512200 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322201 controller_.NotifyEntryChanged(entry, entry_index);
2202}
2203
[email protected]b172aee2012-04-10 17:05:262204void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2205 int32 page_id,
2206 const string16& title,
2207 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322208 // If we have a title, that's a pretty good indication that we've started
2209 // getting useful data.
2210 SetNotWaitingForResponse();
2211
[email protected]73eb2602012-02-09 19:50:552212 // Try to find the navigation entry, which might not be the current one.
2213 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232214 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582215 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092216
[email protected]73eb2602012-02-09 19:50:552217 // We can handle title updates when we don't have an entry in
2218 // UpdateTitleForEntry, but only if the update is from the current RVH.
2219 if (!entry && rvh != GetRenderViewHost())
2220 return;
2221
[email protected]a49e10b2011-08-01 23:57:462222 // TODO(evan): make use of title_direction.
2223 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092224 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322225 return;
2226
2227 // Broadcast notifications when the UI should be updated.
2228 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462229 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322230}
2231
[email protected]b172aee2012-04-10 17:05:262232void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2233 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312234 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322235}
2236
[email protected]b172aee2012-04-10 17:05:262237void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512238 if (delegate_)
2239 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322240}
2241
[email protected]b172aee2012-04-10 17:05:262242void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292243 // The UI may be in an event-tracking loop, such as between the
2244 // mouse-down and mouse-up in text selection or a button click.
2245 // Defer the close until after tracking is complete, so that we
2246 // don't free objects out from under the UI.
2247 // TODO(shess): This could probably be integrated with the
2248 // IsDoingDrag() test below. Punting for now because I need more
2249 // research to understand how this impacts platforms other than Mac.
2250 // TODO(shess): This could get more fine-grained. For instance,
2251 // closing a tab in another window while selecting text in the
2252 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212253 if (GetView()->IsEventTracking()) {
2254 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292255 return;
2256 }
2257
[email protected]24a4d1062009-07-10 23:10:422258 // If we close the tab while we're in the middle of a drag, we'll crash.
2259 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212260 if (GetView()->IsDoingDrag()) {
2261 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422262 return;
2263 }
2264
[email protected]420ae012009-04-24 05:16:322265 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522266 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512267 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322268}
2269
[email protected]b172aee2012-04-10 17:05:262270void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522271 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512272 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512276 if (delegate_ && delegate_->IsPopupOrPanel(this))
2277 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322278}
2279
[email protected]b172aee2012-04-10 17:05:262280void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322281 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492282
[email protected]82114f52012-03-20 22:53:412283 if (delegate_ && content_restrictions_)
2284 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492285
2286 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252287 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322288}
2289
[email protected]b172aee2012-04-10 17:05:262290void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322291 scoped_ptr<LoadNotificationDetails> details;
2292
[email protected]10f417c52011-12-28 21:04:232293 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322294 // An entry may not exist for a stop when loading an initial blank page or
2295 // if an iframe injected by script into a blank page finishes loading.
2296 if (entry) {
[email protected]420ae012009-04-24 05:16:322297 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2298
2299 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512300 entry->GetVirtualURL(),
2301 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322302 elapsed,
2303 &controller_,
2304 controller_.GetCurrentEntryIndex()));
2305 }
2306
[email protected]420ae012009-04-24 05:16:322307 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492308
2309 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252310 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162314 controller_.DiscardNonCommittedEntries();
2315
2316 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462317 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162318}
2319
[email protected]b172aee2012-04-10 17:05:262320void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512321 if (delegate_)
2322 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402323}
2324
[email protected]87717d0e2012-04-26 02:58:432325void WebContentsImpl::DocumentAvailableInMainFrame(
2326 RenderViewHost* render_view_host) {
2327 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2328 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102329}
2330
[email protected]b172aee2012-04-10 17:05:262331void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082332 RenderViewHost* render_view_host,
2333 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072334 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272335 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322336 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532337 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082338}
2339
[email protected]196159d2012-05-04 17:26:542340void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2341 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262342 const content::Referrer& referrer,
2343 WindowOpenDisposition disposition,
2344 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542345 // If this came from a swapped out RenderViewHost, we only allow the request
2346 // if we are still in the same BrowsingInstance.
2347 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2348 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2349 return;
2350 }
2351
[email protected]4ad5d77d2011-12-03 02:00:482352 // Delegate to RequestTransferURL because this is just the generic
2353 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582354 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482355 GlobalRequestID());
2356}
2357
[email protected]b172aee2012-04-10 17:05:262358void WebContentsImpl::RequestTransferURL(
2359 const GURL& url,
2360 const content::Referrer& referrer,
2361 WindowOpenDisposition disposition,
2362 int64 source_frame_id,
2363 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202364 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582365 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582366 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352367 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322368 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2369 // generated suggestions).
2370 //
[email protected]e0112912011-02-02 22:54:352371 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162372 // want web sites to see a referrer of "chrome://blah" (and some
2373 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322374 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432375 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222376 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482377 false /* is_renderer_initiated */);
2378 params.transferred_global_request_id = old_request_id;
2379 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222380 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322381 } else {
[email protected]6bf6a6b52012-02-03 15:41:432382 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482383 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2384 params.transferred_global_request_id = old_request_id;
2385 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582386 }
2387 if (new_contents) {
2388 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252389 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582390 DidOpenRequestedURL(new_contents,
2391 url,
2392 referrer,
2393 disposition,
2394 transition_type,
2395 source_frame_id));
[email protected]420ae012009-04-24 05:16:322396 }
2397}
2398
[email protected]b172aee2012-04-10 17:05:262399void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342400 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412401 const string16& message,
2402 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322403 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472404 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322405 IPC::Message* reply_msg,
2406 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072407 // Suppress JavaScript dialogs when requested. Also suppress messages when
2408 // showing an interstitial as it's shown over the previous page and we don't
2409 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502410 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582411 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272412 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072413 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522414 delegate_->ShouldSuppressDialogs() ||
2415 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322416
2417 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432418 std::string accept_lang = content::GetContentClient()->browser()->
2419 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552420 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522421 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432422 this,
2423 frame_url.GetOrigin(),
2424 accept_lang,
2425 javascript_message_type,
2426 message,
[email protected]51da7e32012-01-30 19:24:522427 default_prompt,
[email protected]b172aee2012-04-10 17:05:262428 base::Bind(&WebContentsImpl::OnDialogClosed,
2429 base::Unretained(this),
2430 rvh,
2431 reply_msg),
[email protected]51da7e32012-01-30 19:24:522432 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322433 }
[email protected]3ab9cb82011-06-03 18:02:072434
2435 if (suppress_this_message) {
2436 // If we are suppressing messages, just reply as if the user immediately
2437 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342438 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072439 }
2440
2441 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322442}
2443
[email protected]b172aee2012-04-10 17:05:262444void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2445 const string16& message,
2446 bool is_reload,
2447 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582448 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512449 if (delegate_)
2450 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072451
2452 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582453 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072454 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522455 delegate_->ShouldSuppressDialogs() ||
2456 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152457 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342458 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582459 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502460 return;
2461 }
[email protected]3ab9cb82011-06-03 18:02:072462
[email protected]7ab1e7d62009-10-14 23:32:012463 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552464 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522465 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322466 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262467 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522468 reply_msg));
[email protected]420ae012009-04-24 05:16:322469}
2470
[email protected]b172aee2012-04-10 17:05:262471WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332472 // We want to base the page config off of the real URL, rather than the
2473 // display URL.
2474 GURL url = controller_.GetActiveEntry()
2475 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2476 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322477}
2478
[email protected]b172aee2012-04-10 17:05:262479void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272480 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252481 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222482
[email protected]ea114722012-03-12 01:11:252483 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172484 if (rdh) // NULL in unittests.
2485 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252486}
2487
[email protected]b172aee2012-04-10 17:05:262488void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442489 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252490 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442491}
2492
[email protected]b172aee2012-04-10 17:05:262493void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2494 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152495 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522496 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152497 return;
2498
[email protected]9f76c1e2012-03-05 15:15:582499 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2500
[email protected]e5fc1632011-08-08 07:51:532501 // Ignore renderer unresponsive event if debugger is attached to the tab
2502 // since the event may be a result of the renderer sitting on a breakpoint.
2503 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442504 DevToolsAgentHost* agent =
2505 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2506 if (agent &&
2507 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532508 return;
2509
[email protected]420ae012009-04-24 05:16:322510 if (is_during_unload) {
2511 // Hang occurred while firing the beforeunload/unload handler.
2512 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582513 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322514
2515 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2516 return;
2517
2518 // If the tab hangs in the beforeunload/unload handler there's really
2519 // nothing we can do to recover. Pretend the unload listeners have
2520 // all fired and close the tab. If the hang is in the beforeunload handler
2521 // then the user will not have the option of cancelling the close.
2522 Close(rvh);
2523 return;
2524 }
2525
[email protected]9f76c1e2012-03-05 15:15:582526 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472527 return;
2528
[email protected]6934a702011-12-20 00:04:512529 if (delegate_)
2530 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322531}
2532
[email protected]b172aee2012-04-10 17:05:262533void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512534 if (delegate_)
2535 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322536}
2537
[email protected]b172aee2012-04-10 17:05:262538void WebContentsImpl::LoadStateChanged(
2539 const GURL& url,
2540 const net::LoadStateWithParam& load_state,
2541 uint64 upload_position,
2542 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322543 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562544 upload_position_ = upload_position;
2545 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502546 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202547 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302548 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212549 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322550 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462551 if (IsLoading()) {
2552 NotifyNavigationStateChanged(
2553 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2554 }
[email protected]420ae012009-04-24 05:16:322555}
2556
[email protected]b172aee2012-04-10 17:05:262557void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512558 if (delegate_)
2559 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252560}
2561
[email protected]b172aee2012-04-10 17:05:262562void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322563 bool proceed,
2564 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512565 if (delegate_)
2566 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322567}
2568
[email protected]b172aee2012-04-10 17:05:262569void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542570 RenderViewHost* render_view_host) {
2571 DidStartLoading();
2572}
2573
[email protected]b172aee2012-04-10 17:05:262574void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542575 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232576 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2577 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542578}
2579
[email protected]b172aee2012-04-10 17:05:262580void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102581 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262582 gfx::Size size = view_->GetContainerSize();
2583 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2584 // here during container initialization and normal window size will be set
2585 // later. In case of tab duplication this resizing to 0x0 prevents setting
2586 // normal size later so just ignore it.
2587 if (!size.IsEmpty())
2588 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322589}
2590
[email protected]b172aee2012-04-10 17:05:262591void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542592 NotifySwapped();
2593}
2594
[email protected]14392a52012-05-02 20:28:442595int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2596 SiteInstance* instance) {
2597 if (!opener_)
2598 return MSG_ROUTING_NONE;
2599
2600 // Recursively create RenderViews for anything else in the opener chain.
2601 return opener_->CreateOpenerRenderViews(instance);
2602}
2603
2604int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2605 int opener_route_id = MSG_ROUTING_NONE;
2606
2607 // If this tab has an opener, ensure it has a RenderView in the given
2608 // SiteInstance as well.
2609 if (opener_)
2610 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2611
2612 // Create a swapped out RenderView in the given SiteInstance if none exists,
2613 // setting its opener to the given route_id. Return the new view's route_id.
2614 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2615}
2616
[email protected]b172aee2012-04-10 17:05:262617NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202618 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542619}
2620
[email protected]b172aee2012-04-10 17:05:262621WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562622 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322623}
2624
[email protected]10f417c52011-12-28 21:04:232625NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262626 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322627 return controller_.GetLastCommittedEntry();
2628}
2629
[email protected]b172aee2012-04-10 17:05:262630bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442631 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442632 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322633 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522634
[email protected]420ae012009-04-24 05:16:322635 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442636 if (rwh_view)
2637 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322638
[email protected]74ce1ad2011-12-16 21:51:462639 // Make sure we use the correct starting page_id in the new RenderView.
2640 UpdateMaxPageIDIfNecessary(render_view_host);
2641 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582642 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462643
[email protected]9f76c1e2012-03-05 15:15:582644 if (!static_cast<RenderViewHostImpl*>(
[email protected]14392a52012-05-02 20:28:442645 render_view_host)->CreateRenderView(string16(), opener_route_id,
2646 max_page_id)) {
[email protected]a4127722011-04-27 23:13:522647 return false;
[email protected]14392a52012-05-02 20:28:442648 }
[email protected]a4127722011-04-27 23:13:522649
[email protected]e60c0232011-11-11 19:56:352650#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502651 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2652 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442653 if (rwh_view) {
2654 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2655 render_widget_host->WasResized();
2656 }
[email protected]f8233cc2011-05-31 20:24:502657#endif
2658
[email protected]420ae012009-04-24 05:16:322659 return true;
2660}
2661
[email protected]b172aee2012-04-10 17:05:262662void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2663 IPC::Message* reply_msg,
2664 bool success,
2665 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542666 if (is_showing_before_unload_dialog_ && !success) {
2667 // If a beforeunload dialog is canceled, we need to stop the throbber from
2668 // spinning, since we forced it to start spinning in Navigate.
2669 DidStopLoading();
2670
[email protected]3bbacc5b2012-04-17 17:46:152671 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542672 }
2673 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582674 static_cast<RenderViewHostImpl*>(
2675 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542676}
2677
[email protected]b172aee2012-04-10 17:05:262678void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122679 encoding_ = content::GetContentClient()->browser()->
2680 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102681}
[email protected]f45d2a72010-03-08 23:28:352682
[email protected]b172aee2012-04-10 17:05:262683void WebContentsImpl::SaveURL(const GURL& url,
2684 const GURL& referrer,
2685 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142686 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2687 if (!dlm)
2688 return;
2689 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262690 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142691 const NavigationEntry* entry = controller_.GetActiveEntry();
2692 if (entry)
2693 post_id = entry->GetPostID();
2694 }
[email protected]29a5ffc82012-03-13 19:35:582695 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142696 save_info.prompt_for_save_location = true;
2697 dlm->DownloadUrl(url,
2698 referrer,
2699 "",
2700 true, // prefer_cache
2701 post_id,
2702 save_info,
[email protected]89e6aa72012-03-12 22:51:332703 this,
2704 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142705}
2706
[email protected]b172aee2012-04-10 17:05:262707void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212708 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442709 // Can be NULL during tests.
2710 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212711 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362712}
[email protected]9f76c1e2012-03-05 15:15:582713
[email protected]b172aee2012-04-10 17:05:262714RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582715 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2716}