blob: 9d38244d52b4374ccc0d43a76bd7bca80e4ab740 [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]8b3b36152012-05-01 04:55:0761#include "ui/gfx/monitor.h"
62#include "ui/gfx/screen.h"
[email protected]a53209b2012-01-20 16:48:1663#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2964#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5465#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3466#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3767#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2468#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3169#include "webkit/glue/webpreferences.h"
70
[email protected]68b52252012-04-04 19:26:1371#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:3572#include "content/browser/web_contents/web_contents_view_aura.h"
[email protected]68b52252012-04-04 19:26:1373#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:3574#include "content/browser/web_contents/web_contents_view_win.h"
[email protected]38b098f2012-03-14 21:11:5775#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:3576#include "content/browser/web_contents/web_contents_view_gtk.h"
[email protected]38b098f2012-03-14 21:11:5777#elif defined(OS_MACOSX)
[email protected]0c4e92e62012-04-11 15:19:0078#include "content/browser/web_contents/web_contents_view_mac.h"
[email protected]8b3b36152012-05-01 04:55:0779#include "ui/base/ui_base_switches.h"
[email protected]b9b751f22011-03-25 14:04:1280#include "ui/gfx/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]6c6b02d2011-09-02 03:36:47222
223 if (delegate)
224 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34225}
226
[email protected]420ae012009-04-24 05:16:32227} // namespace
228
[email protected]a81343d232011-12-27 07:39:20229namespace content {
230
231WebContents* WebContents::Create(
232 BrowserContext* browser_context,
233 SiteInstance* site_instance,
234 int routing_id,
[email protected]b172aee2012-04-10 17:05:26235 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20236 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26237 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43238 browser_context,
239 site_instance,
240 routing_id,
[email protected]b172aee2012-04-10 17:05:26241 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]adbfb8df2012-02-24 01:19:43242 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20243}
244}
[email protected]f4f50ef2011-01-21 19:01:19245
[email protected]b172aee2012-04-10 17:05:26246// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32247
[email protected]b172aee2012-04-10 17:05:26248WebContentsImpl::WebContentsImpl(
249 content::BrowserContext* browser_context,
250 SiteInstance* site_instance,
251 int routing_id,
252 const WebContentsImpl* base_web_contents,
253 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42254 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07255 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37256 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22257 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34258 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23259 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
260 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34261 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21262 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56263 upload_size_(0),
264 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47265 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57266 capturing_contents_(false),
267 is_being_destroyed_(false),
268 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55269 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57270#if defined(OS_WIN)
271 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
272#endif
[email protected]7ab1e7d62009-10-14 23:32:01273 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56274 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38275 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25276 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01277 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25278 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01279 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00280 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43281 content_restrictions_(0),
[email protected]e018d3b2012-04-17 13:24:15282 view_type_(content::VIEW_TYPE_WEB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20283 has_opener_(false),
284 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37285 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32286
[email protected]38b098f2012-03-14 21:11:57287 view_.reset(content::GetContentClient()->browser()->
288 OverrideCreateWebContentsView(this));
289 if (!view_.get()) {
290 content::WebContentsViewDelegate* delegate =
291 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
292 this);
[email protected]68b52252012-04-04 19:26:13293#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:35294 view_.reset(new WebContentsViewAura(this, delegate));
[email protected]68b52252012-04-04 19:26:13295#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:35296 view_.reset(new WebContentsViewWin(this, delegate));
[email protected]38b098f2012-03-14 21:11:57297#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:35298 view_.reset(new content::WebContentsViewGtk(this, delegate));
[email protected]38b098f2012-03-14 21:11:57299#elif defined(OS_MACOSX)
300 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
301#elif defined(OS_ANDROID)
302 view_.reset(new WebContentsViewAndroid(this));
303#endif
[email protected]dbd407f2012-03-14 21:30:37304 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57305 }
306 CHECK(view_.get());
307
[email protected]ca13a442012-04-17 14:00:12308 // We have the initial size of the view be based on the size of the view of
309 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26310 view_->CreateView(base_web_contents ?
311 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00312
313#if defined(ENABLE_JAVA_BRIDGE)
314 java_bridge_dispatcher_host_manager_.reset(
315 new JavaBridgeDispatcherHostManager(this));
316#endif
[email protected]8dd709fb2012-04-06 00:49:06317
318 browser_plugin_web_contents_observer_.reset(
319 new content::BrowserPluginWebContentsObserver(this));
[email protected]332af7732009-03-11 13:21:35320}
initial.commit09911bf2008-07-26 23:55:29321
[email protected]b172aee2012-04-10 17:05:26322WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32323 is_being_destroyed_ = true;
324
[email protected]3ab9cb82011-06-03 18:02:07325 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55326 if (dialog_creator_)
327 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07328
[email protected]da8543762012-03-20 08:52:20329 if (color_chooser_)
330 color_chooser_->End();
331
[email protected]420ae012009-04-24 05:16:32332 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32333
[email protected]ca13a442012-04-17 14:00:12334 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07335 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09336 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
337 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07338 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32339
340 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07341#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32342 // If we still have a window handle, destroy it. GetNativeView can return
343 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42344 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52345 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58346 if (host && host->GetView())
347 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42348 }
[email protected]420ae012009-04-24 05:16:32349#endif
[email protected]7ab1e7d62009-10-14 23:32:01350
351 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15352 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01353 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15354 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01355 }
[email protected]b5a1d11c2011-02-17 03:09:42356
[email protected]2db9bd72012-04-13 20:20:56357 FOR_EACH_OBSERVER(WebContentsObserver,
358 observers_,
359 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08360
[email protected]6934a702011-12-20 00:04:51361 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42362}
363
[email protected]b172aee2012-04-10 17:05:26364WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
365 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54366 WebPreferences prefs;
367
368 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
369
370 prefs.developer_extras_enabled = true;
371 prefs.javascript_enabled =
372 !command_line.HasSwitch(switches::kDisableJavaScript);
373 prefs.web_security_enabled =
374 !command_line.HasSwitch(switches::kDisableWebSecurity);
375 prefs.plugins_enabled =
376 !command_line.HasSwitch(switches::kDisablePlugins);
377 prefs.java_enabled =
378 !command_line.HasSwitch(switches::kDisableJava);
379
380 prefs.uses_page_cache =
381 command_line.HasSwitch(switches::kEnableFastback);
382 prefs.remote_fonts_enabled =
383 !command_line.HasSwitch(switches::kDisableRemoteFonts);
384 prefs.xss_auditor_enabled =
385 !command_line.HasSwitch(switches::kDisableXSSAuditor);
386 prefs.application_cache_enabled =
387 !command_line.HasSwitch(switches::kDisableApplicationCache);
388
389 prefs.local_storage_enabled =
390 !command_line.HasSwitch(switches::kDisableLocalStorage);
391 prefs.databases_enabled =
392 !command_line.HasSwitch(switches::kDisableDatabases);
393 prefs.webaudio_enabled =
394 !command_line.HasSwitch(switches::kDisableWebAudio);
395
396 prefs.experimental_webgl_enabled =
397 GpuProcessHost::gpu_enabled() &&
398 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
399 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
400
401 prefs.gl_multisampling_enabled =
402 !command_line.HasSwitch(switches::kDisableGLMultisampling);
403 prefs.privileged_webgl_extensions_enabled =
404 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
405 prefs.site_specific_quirks_enabled =
406 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
407 prefs.allow_file_access_from_file_urls =
408 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
409 prefs.show_composited_layer_borders =
410 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
411 prefs.show_composited_layer_tree =
412 command_line.HasSwitch(switches::kShowCompositedLayerTree);
413 prefs.show_fps_counter =
414 command_line.HasSwitch(switches::kShowFPSCounter);
415 prefs.accelerated_compositing_enabled =
416 GpuProcessHost::gpu_enabled() &&
417 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54418 prefs.force_compositing_mode =
419 command_line.HasSwitch(switches::kForceCompositingMode);
420 prefs.fixed_position_compositing_enabled =
421 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
422 prefs.accelerated_2d_canvas_enabled =
423 GpuProcessHost::gpu_enabled() &&
424 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58425 prefs.deferred_2d_canvas_enabled =
426 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36427 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31428 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54429 prefs.accelerated_painting_enabled =
430 GpuProcessHost::gpu_enabled() &&
431 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
432 prefs.accelerated_filters_enabled =
433 GpuProcessHost::gpu_enabled() &&
434 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
435 prefs.accelerated_layers_enabled =
436 prefs.accelerated_animation_enabled =
437 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54438 prefs.accelerated_plugins_enabled =
439 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
440 prefs.accelerated_video_enabled =
441 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
442 prefs.partial_swap_enabled =
443 command_line.HasSwitch(switches::kEnablePartialSwap);
444 prefs.interactive_form_validation_enabled =
445 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
446 prefs.fullscreen_enabled =
447 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16448 prefs.css_regions_enabled =
449 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29450 prefs.css_shaders_enabled =
451 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54452
453#if defined(OS_MACOSX)
454 bool default_enable_scroll_animator = true;
455#else
456 // On CrOS, the launcher always passes in the --enable flag.
457 bool default_enable_scroll_animator = false;
458#endif
459 prefs.enable_scroll_animator = default_enable_scroll_animator;
460 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
461 prefs.enable_scroll_animator = true;
462 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
463 prefs.enable_scroll_animator = false;
464
465 prefs.visual_word_movement_enabled =
466 command_line.HasSwitch(switches::kEnableVisualWordMovement);
467 prefs.per_tile_painting_enabled =
468 command_line.HasSwitch(switches::kEnablePerTilePainting);
469
470 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32471 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54472 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11473 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
474 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54475 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11476 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54477 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11478 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54479 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11480 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54481 prefs.gl_multisampling_enabled = false;
482
483 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45484 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32485 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54486 prefs.accelerated_video_enabled = false;
487 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45488 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54489 }
490 }
491
[email protected]b9535422012-02-09 01:47:59492 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58493 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54494 prefs.loads_images_automatically = true;
495 prefs.javascript_enabled = true;
496 }
497
498 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
499
500 // Force accelerated compositing and 2d canvas off for chrome:, about: and
501 // chrome-devtools: pages (unless it's specifically allowed).
502 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54503 url.SchemeIs(chrome::kChromeUIScheme) ||
504 (url.SchemeIs(chrome::kAboutScheme) &&
505 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25506 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54507 prefs.accelerated_compositing_enabled = false;
508 prefs.accelerated_2d_canvas_enabled = false;
509 }
[email protected]8b3b36152012-05-01 04:55:07510#if defined(OS_MACOSX)
511 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
512 // crbug.com/125690.
[email protected]43d9d782012-03-01 15:40:09513 int default_device_scale_factor;
514 base::StringToInt(command_line.GetSwitchValueASCII(
515 switches::kDefaultDeviceScaleFactor),
516 &default_device_scale_factor);
[email protected]43d9d782012-03-01 15:40:09517 prefs.default_device_scale_factor = default_device_scale_factor;
[email protected]8b3b36152012-05-01 04:55:07518#else
519 if (rvh->GetView()) {
520 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
521 rvh->GetView()->GetNativeView());
522 prefs.default_device_scale_factor =
523 static_cast<int>(monitor.device_scale_factor());
524 } else {
525 prefs.default_device_scale_factor = 1;
526 }
527#endif
[email protected]43d9d782012-03-01 15:40:09528
[email protected]2e21fe292012-03-02 22:52:32529 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54530
531 return prefs;
532}
533
[email protected]b172aee2012-04-10 17:05:26534NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20535 return controller_;
536}
537
[email protected]b172aee2012-04-10 17:05:26538RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28539 return &render_manager_;
540}
541
[email protected]b172aee2012-04-10 17:05:26542bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56543 if (GetWebUI() &&
544 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17545 return true;
[email protected]d2353452012-01-19 19:53:56546 }
[email protected]f82d57b52011-04-27 19:13:17547
[email protected]d8c660432011-12-22 20:51:25548 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
549 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10550 while ((observer = it.GetNext()) != NULL)
551 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53552 return true;
[email protected]403415a2011-01-10 18:57:53553
[email protected]724159a2010-12-30 01:11:18554 bool handled = true;
555 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26556 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58557 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
558 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24559 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
560 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18561 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
562 OnDidStartProvisionalLoadForFrame)
563 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
564 OnDidRedirectProvisionalLoad)
565 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
566 OnDidFailProvisionalLoadWithError)
567 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
568 OnDidLoadResourceFromMemoryCache)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
570 OnDidDisplayInsecureContent)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
572 OnDidRunInsecureContent)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
574 OnDocumentLoadedInFrame)
575 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26576 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
577 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17578 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
579 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25580 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26581 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59582 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21583 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20584 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
585 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
586 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16587 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45588 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10589 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20590 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
591 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
592 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
593 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29594 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50595 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18596 IPC_MESSAGE_UNHANDLED(handled = false)
597 IPC_END_MESSAGE_MAP_EX()
598
599 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38600 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18601 GetRenderProcessHost()->ReceivedBadMessage();
602 }
603
604 return handled;
605}
606
[email protected]b172aee2012-04-10 17:05:26607void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18608 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23609 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51610 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18611}
612
[email protected]b172aee2012-04-10 17:05:26613NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56614 return controller_;
615}
616
[email protected]b172aee2012-04-10 17:05:26617const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56618 return controller_;
619}
620
[email protected]b172aee2012-04-10 17:05:26621content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55622 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30623}
624
[email protected]b172aee2012-04-10 17:05:26625void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56626 view_type_ = type;
627}
628
[email protected]b172aee2012-04-10 17:05:26629content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09630 return view_type_;
631}
632
[email protected]b172aee2012-04-10 17:05:26633const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31634 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23635 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51636 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31637}
638
639
[email protected]b172aee2012-04-10 17:05:26640const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31641 return &property_bag_;
642}
643
[email protected]b172aee2012-04-10 17:05:26644base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31645 return &property_bag_;
646}
647
[email protected]b172aee2012-04-10 17:05:26648content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31649 return delegate_;
650}
651
[email protected]b172aee2012-04-10 17:05:26652void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31653 // TODO(cbentzel): remove this debugging code?
654 if (delegate == delegate_)
655 return;
656 if (delegate_)
657 delegate_->Detach(this);
658 delegate_ = delegate;
659 if (delegate_)
660 delegate_->Attach(this);
661}
662
[email protected]b172aee2012-04-10 17:05:26663content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41664 RenderViewHostImpl* host = render_manager_.current_host();
665 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16666}
667
[email protected]b172aee2012-04-10 17:05:26668RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31669 return render_manager_.current_host();
670}
671
[email protected]b172aee2012-04-10 17:05:26672RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31673 return render_manager_.GetRenderWidgetHostView();
674}
675
[email protected]b172aee2012-04-10 17:05:26676content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31677 return view_.get();
678}
679
[email protected]b172aee2012-04-10 17:05:26680content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50681 WebUIControllerFactory* factory =
682 content::GetContentClient()->browser()->GetWebUIControllerFactory();
683 if (!factory)
684 return NULL;
[email protected]d2353452012-01-19 19:53:56685 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22686 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50687 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22688 if (controller) {
689 web_ui->SetController(controller);
690 return web_ui;
691 }
692
693 delete web_ui;
694 return NULL;
695}
696
[email protected]b172aee2012-04-10 17:05:26697content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31698 return render_manager_.web_ui() ? render_manager_.web_ui()
699 : render_manager_.pending_web_ui();
700}
701
[email protected]b172aee2012-04-10 17:05:26702content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31703 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34704}
705
[email protected]b172aee2012-04-10 17:05:26706const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55707 // Transient entries take precedence. They are used for interstitial pages
708 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23709 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08710 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20711 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30712 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23713 if (entry) {
[email protected]b5cca982011-05-26 04:42:08714 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23715 }
[email protected]7ade2732011-02-10 00:13:58716 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
717 render_manager_.pending_web_ui() : render_manager_.web_ui();
718 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54719 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55720 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54721 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35722 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22723 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54724 if (!title.empty())
725 return title;
726 }
727 }
728
729 // We use the title for the last committed entry rather than a pending
730 // navigation entry. For example, when the user types in a URL, we want to
731 // keep the old page's title until the new load has committed and we get a new
732 // title.
[email protected]96d185d2009-04-24 03:28:54733 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23734 if (entry) {
[email protected]b5cca982011-05-26 04:42:08735 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23736 }
[email protected]987fc3a2011-05-26 14:18:09737
738 // |page_title_when_no_navigation_entry_| is finally used
739 // if no title cannot be retrieved.
740 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54741}
742
[email protected]b172aee2012-04-10 17:05:26743int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46744 return GetMaxPageIDForSiteInstance(GetSiteInstance());
745}
746
[email protected]b172aee2012-04-10 17:05:26747int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
748 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33749 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
750 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46751
[email protected]b6583592012-01-25 19:52:33752 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34753}
754
[email protected]b172aee2012-04-10 17:05:26755void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46756 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
757}
758
[email protected]b172aee2012-04-10 17:05:26759void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33760 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46761 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33762 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34763}
764
[email protected]b172aee2012-04-10 17:05:26765void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
766 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57767}
768
[email protected]b172aee2012-04-10 17:05:26769SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58770 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54771}
772
[email protected]b172aee2012-04-10 17:05:26773SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38774 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
775 render_manager_.pending_render_view_host() :
776 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58777 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38778}
779
[email protected]b172aee2012-04-10 17:05:26780bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31781 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49782}
783
[email protected]b172aee2012-04-10 17:05:26784bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31785 return waiting_for_response_;
786}
787
[email protected]b172aee2012-04-10 17:05:26788const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31789 return load_state_;
790}
791
[email protected]b172aee2012-04-10 17:05:26792const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31793 return load_state_host_;
794}
795
[email protected]b172aee2012-04-10 17:05:26796uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31797 return upload_size_;
798}
799
[email protected]b172aee2012-04-10 17:05:26800uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31801 return upload_position_;
802}
803
[email protected]b172aee2012-04-10 17:05:26804const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31805 return encoding_;
806}
807
[email protected]b172aee2012-04-10 17:05:26808bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31809 return displayed_insecure_content_;
810}
811
[email protected]b172aee2012-04-10 17:05:26812void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31813 capturing_contents_ = cap;
814}
815
[email protected]b172aee2012-04-10 17:05:26816bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31817 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
818 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
819 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49820}
821
[email protected]b172aee2012-04-10 17:05:26822void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
823 int error_code) {
[email protected]443b80e2010-12-14 00:42:23824 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34825 return;
826
[email protected]443b80e2010-12-14 00:42:23827 crashed_status_ = status;
828 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46829 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34830}
831
[email protected]b172aee2012-04-10 17:05:26832base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31833 return crashed_status_;
834}
835
[email protected]b172aee2012-04-10 17:05:26836bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return is_being_destroyed_;
838}
839
[email protected]b172aee2012-04-10 17:05:26840void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34841 if (delegate_)
842 delegate_->NavigationStateChanged(this, changed_flags);
843}
844
[email protected]b172aee2012-04-10 17:05:26845void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54846 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04847 RenderWidgetHostViewPort* rwhv =
848 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16849 if (rwhv) {
850 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43851#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16852 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43853#endif
854 }
[email protected]96d185d2009-04-24 03:28:54855
[email protected]5ac20162010-11-24 23:33:11856 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38857
[email protected]d8c660432011-12-22 20:51:25858 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59859
860 // The resize rect might have changed while this was inactive -- send the new
861 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58862 RenderViewHostImpl* rvh =
863 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59864 if (rvh) {
865 rvh->ResizeRectChanged(GetRootWindowResizerRect());
866 }
[email protected]96d185d2009-04-24 03:28:54867}
868
[email protected]be1f56ab2011-12-22 06:55:31869
[email protected]b172aee2012-04-10 17:05:26870base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return last_selected_time_;
872}
873
[email protected]b172aee2012-04-10 17:05:26874void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31875 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52876 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
877 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26878 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52879 // removes the |GetRenderViewHost()|; then when we actually destroy the
880 // window, OnWindowPosChanged() notices and calls HideContents() (which
881 // calls us).
[email protected]c30585c2012-02-16 15:02:04882 RenderWidgetHostViewPort* rwhv =
883 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16884 if (rwhv)
885 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54886 }
887
[email protected]ad50def52011-10-19 23:17:07888 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09889 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
890 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07891 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54892}
893
[email protected]b172aee2012-04-10 17:05:26894void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04895 RenderWidgetHostViewPort* rwhv =
896 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31897 if (rwhv)
898 rwhv->DidBecomeSelected();
899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31902 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
903 // our superclass HideContents(), because some callers want to be very picky
904 // about the order in which these get called. In addition to making the code
905 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26906 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
907 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31908 WasHidden();
909}
910
[email protected]b172aee2012-04-10 17:05:26911bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31912 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27913 return WillNotifyDisconnection() &&
914 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58915 !static_cast<RenderViewHostImpl*>(
916 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31917}
918
[email protected]b172aee2012-04-10 17:05:26919void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27920 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25921 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27922}
923
[email protected]b172aee2012-04-10 17:05:26924WebContents* WebContentsImpl::Clone() {
[email protected]0bfbf882011-12-22 18:19:27925 // We create a new SiteInstance so that the new tab won't share processes
926 // with the old one. This can be changed in the future if we need it to share
927 // processes for some reason.
[email protected]b172aee2012-04-10 17:05:26928 WebContentsImpl* tc = new WebContentsImpl(
[email protected]0bfbf882011-12-22 18:19:27929 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33930 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27931 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20932 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27933 return tc;
934}
935
[email protected]b172aee2012-04-10 17:05:26936void WebContentsImpl::AddNewContents(WebContents* new_contents,
937 WindowOpenDisposition disposition,
938 const gfx::Rect& initial_pos,
939 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27940 if (!delegate_)
941 return;
942
943 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
944 user_gesture);
945}
946
[email protected]b172aee2012-04-10 17:05:26947gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27948 return view_->GetContentNativeView();
949}
950
[email protected]b172aee2012-04-10 17:05:26951gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27952 return view_->GetNativeView();
953}
954
[email protected]b172aee2012-04-10 17:05:26955void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27956 view_->GetContainerBounds(out);
957}
958
[email protected]b172aee2012-04-10 17:05:26959void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27960 view_->Focus();
961}
962
[email protected]b172aee2012-04-10 17:05:26963void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31964 observers_.AddObserver(observer);
965}
966
[email protected]b172aee2012-04-10 17:05:26967void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31968 observers_.RemoveObserver(observer);
969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:34972 if (delegate_)
973 delegate_->ActivateContents(this);
974}
975
[email protected]b172aee2012-04-10 17:05:26976void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:12977 if (delegate_)
978 delegate_->DeactivateContents(this);
979}
980
[email protected]b172aee2012-04-10 17:05:26981void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:48982 if (delegate_)
983 delegate_->LostCapture();
984}
985
[email protected]b172aee2012-04-10 17:05:26986bool WebContentsImpl::PreHandleKeyboardEvent(
987 const NativeWebKeyboardEvent& event,
988 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:48989 return delegate_ &&
990 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
991}
992
[email protected]b172aee2012-04-10 17:05:26993void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:48994 if (delegate_)
995 delegate_->HandleKeyboardEvent(event);
996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:43999 if (delegate_)
1000 delegate_->HandleMouseDown();
1001}
1002
[email protected]b172aee2012-04-10 17:05:261003void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481004 if (delegate_)
1005 delegate_->HandleMouseUp();
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481009 if (delegate_)
1010 delegate_->HandleMouseActivate();
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471014 if (delegate_)
1015 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1016}
1017
[email protected]b172aee2012-04-10 17:05:261018bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381019 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121020}
1021
[email protected]42252e02012-04-26 16:29:391022void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371023 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391024 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371025 } else {
1026 GotResponseToLockMouseRequest(false);
1027 }
1028}
1029
[email protected]b172aee2012-04-10 17:05:261030void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371031 if (delegate_)
1032 delegate_->LostMouseLock();
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231036 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331037 if (delegate_)
1038 delegate_->UpdatePreferredSize(this, pref_size);
1039}
1040
[email protected]b172aee2012-04-10 17:05:261041void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341042 if (delegate_)
1043 delegate_->ResizeDueToAutoResize(this, new_size);
1044}
1045
[email protected]b172aee2012-04-10 17:05:261046WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201047 if (!delegate_)
1048 return NULL;
[email protected]00c37fc2011-08-02 00:22:501049
[email protected]e5d549d2011-12-28 01:29:201050 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1051 // Notify observers.
1052 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1053 DidOpenURL(params.url, params.referrer,
1054 params.disposition, params.transition));
1055 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341056}
1057
[email protected]b172aee2012-04-10 17:05:261058bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501059 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251060 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231061 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251062 reload_type);
[email protected]876bc832010-09-07 16:29:541063}
[email protected]96d185d2009-04-24 03:28:541064
[email protected]b172aee2012-04-10 17:05:261065bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231066 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501067 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401068 // The renderer will reject IPC messages with URLs longer than
1069 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511070 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401071 return false;
1072
[email protected]9f76c1e2012-03-05 15:15:581073 RenderViewHostImpl* dest_render_view_host =
1074 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401075 if (!dest_render_view_host)
1076 return false; // Unable to create the desired render view host.
1077
[email protected]80a8fad2011-01-29 04:02:381078 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071079 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581080 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501081 WebUIControllerFactory* factory =
1082 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271083 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501084 bool is_allowed_in_web_ui_renderer =
1085 factory &&
[email protected]24e18252012-04-16 21:26:271086 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1087 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231088 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1089 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271090 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231091 content::GetContentClient()->SetActiveURL(entry.GetURL());
1092 CHECK(0);
1093 }
[email protected]54ec6472010-04-09 19:39:581094
[email protected]96d185d2009-04-24 03:28:541095 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441096 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521097 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441098 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511099 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541100
1101 // Used for page load time metrics.
1102 current_load_start_ = base::TimeTicks::Now();
1103
1104 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341105 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271106 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471107 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341108 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541109
[email protected]36fc0392011-12-25 03:59:511110 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541111 // HACK!! This code suppresses javascript: URLs from being added to
1112 // session history, which is what we want to do for javascript: URLs that
1113 // do not generate content. What we really need is a message from the
1114 // renderer telling us that a new page was not created. The same message
1115 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511116 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541117 return false;
1118 }
1119
[email protected]3c9e1872010-11-18 16:17:491120 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251121 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041122 observers_,
[email protected]36fc0392011-12-25 03:59:511123 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541124
[email protected]09b29342011-06-24 19:18:481125 if (delegate_)
1126 delegate_->DidNavigateToPendingEntry(this);
1127
[email protected]d5f942ba2008-09-26 19:30:341128 return true;
1129}
1130
[email protected]b172aee2012-04-10 17:05:261131void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331132 const SiteInstance* site_instance,
1133 int history_length,
1134 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411135 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1136 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191137 if (render_manager_.pending_render_view_host()) {
1138 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141139 return;
[email protected]9e1ad4b2011-08-14 16:49:191140 }
[email protected]9f76c1e2012-03-05 15:15:581141 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191142 if (!rvh) {
1143 NOTREACHED();
1144 return;
1145 }
[email protected]9f76c1e2012-03-05 15:15:581146 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191147 NOTREACHED();
1148 return;
1149 }
[email protected]9f76c1e2012-03-05 15:15:581150 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191151 history_length,
1152 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271156 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541157 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1158 return;
1159 }
[email protected]9f76c1e2012-03-05 15:15:581160 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541161}
1162
[email protected]b172aee2012-04-10 17:05:261163bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271164 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541165}
1166
[email protected]b172aee2012-04-10 17:05:261167InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271168 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221169}
1170
[email protected]b172aee2012-04-10 17:05:261171bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161172 // WebKit creates Document object when MIME type is application/xhtml+xml,
1173 // so we also support this MIME type.
1174 return contents_mime_type_ == "text/html" ||
1175 contents_mime_type_ == "text/xml" ||
1176 contents_mime_type_ == "application/xhtml+xml" ||
1177 contents_mime_type_ == "text/plain" ||
1178 contents_mime_type_ == "text/css" ||
1179 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1180}
1181
[email protected]b172aee2012-04-10 17:05:261182void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591183 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161184 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481185 download_stats::RecordDownloadSource(
1186 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261187 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141188 return;
[email protected]c7dd2f62011-07-18 15:57:591189 }
1190
1191 Stop();
1192
1193 // Create the save package and possibly prompt the user for the name to save
1194 // the page as. The user prompt is an asynchronous operation that runs on
1195 // another thread.
1196 save_package_ = new SavePackage(this);
1197 save_package_->GetSaveInfo();
1198}
1199
1200// Used in automated testing to bypass prompting the user for file names.
1201// Instead, the names and paths are hard coded rather than running them through
1202// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261203bool WebContentsImpl::SavePage(const FilePath& main_file,
1204 const FilePath& dir_path,
1205 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591206 // Stop the page from navigating.
1207 Stop();
1208
1209 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1210 return save_package_->Init();
1211}
1212
[email protected]b172aee2012-04-10 17:05:261213void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121214 const FilePath& file,
1215 const base::Callback<void(const FilePath&, int64)>& callback) {
1216 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1217}
1218
[email protected]b172aee2012-04-10 17:05:261219bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231220 NavigationEntryImpl* active_entry =
1221 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321222 return (active_entry != NULL &&
1223 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511224 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321225}
1226
[email protected]b172aee2012-04-10 17:05:261227const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271228 return contents_mime_type_;
1229}
1230
[email protected]b172aee2012-04-10 17:05:261231bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271232 return notify_disconnection_;
1233}
1234
[email protected]b172aee2012-04-10 17:05:261235void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311236 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581237 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1238 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161239}
1240
[email protected]b172aee2012-04-10 17:05:261241void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311242 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581243 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1244 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161245}
1246
[email protected]b172aee2012-04-10 17:05:261247content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271248 return &renderer_preferences_;
1249}
1250
[email protected]b172aee2012-04-10 17:05:261251void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271252 new_tab_start_time_ = time;
1253}
1254
[email protected]b172aee2012-04-10 17:05:261255base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271256 return new_tab_start_time_;
1257}
1258
[email protected]b172aee2012-04-10 17:05:261259void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151260 if (close_start_time_.is_null())
1261 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011262}
1263
[email protected]b172aee2012-04-10 17:05:261264bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191265#if defined(OS_CHROMEOS)
1266 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1267 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511268 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201269 return false;
1270 return true;
[email protected]46624bf2010-06-09 16:04:191271#else
1272 return true;
1273#endif
1274}
1275
[email protected]b172aee2012-04-10 17:05:261276void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521277 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581278 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511279 if (delegate_)
1280 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341281}
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271284 closed_by_user_gesture_ = value;
1285}
1286
[email protected]b172aee2012-04-10 17:05:261287bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271288 return closed_by_user_gesture_;
1289}
1290
[email protected]b172aee2012-04-10 17:05:261291double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051292 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561293 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251294 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171295 return 0;
[email protected]b75b8292010-10-01 07:28:251296
1297 double zoom_level;
1298 if (temporary_zoom_settings_) {
1299 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581300 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251301 } else {
[email protected]2ae88d12011-10-14 09:11:191302 GURL url;
[email protected]10f417c52011-12-28 21:04:231303 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191304 // Since zoom map is updated using rewritten URL, use rewritten URL
1305 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511306 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191307 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251308 }
[email protected]d0b8d092010-10-25 04:05:171309 return zoom_level;
1310}
[email protected]b75b8292010-10-01 07:28:251311
[email protected]b172aee2012-04-10 17:05:261312int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1313 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171314 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011315 // Calculate the zoom percent from the factor. Round up to the nearest whole
1316 // number.
[email protected]b75b8292010-10-01 07:28:251317 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011318 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251319 *enable_decrement = percent > minimum_zoom_percent_;
1320 *enable_increment = percent < maximum_zoom_percent_;
1321 return percent;
1322}
1323
[email protected]b172aee2012-04-10 17:05:261324void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501325 if (!delegate_)
1326 return;
1327
[email protected]10f417c52011-12-28 21:04:231328 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501329 if (!active_entry)
1330 return;
1331
[email protected]36fc0392011-12-25 03:59:511332 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121333}
1334
[email protected]b172aee2012-04-10 17:05:261335void WebContentsImpl::ViewFrameSource(const GURL& url,
1336 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271337 if (!delegate_)
1338 return;
1339
1340 delegate_->ViewSourceForFrame(this, url, content_state);
1341}
1342
[email protected]b172aee2012-04-10 17:05:261343int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271344 return minimum_zoom_percent_;
1345}
1346
[email protected]b172aee2012-04-10 17:05:261347int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271348 return maximum_zoom_percent_;
1349}
1350
[email protected]b172aee2012-04-10 17:05:261351gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231352 return preferred_size_;
1353}
1354
[email protected]b172aee2012-04-10 17:05:261355int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271356 return content_restrictions_;
1357}
1358
[email protected]b172aee2012-04-10 17:05:261359WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501360 WebUIControllerFactory* factory =
1361 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1362 if (!factory)
1363 return WebUI::kNoWebUI;
1364 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271365}
1366
[email protected]b172aee2012-04-10 17:05:261367content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271368 // When there is a pending navigation entry, we want to use the pending WebUI
1369 // that goes along with it to control the basic flags. For example, we want to
1370 // show the pending URL in the URL bar, so we want the display_url flag to
1371 // be from the pending entry.
1372 //
1373 // The confusion comes because there are multiple possibilities for the
1374 // initial load in a tab as a side effect of the way the RenderViewHostManager
1375 // works.
1376 //
1377 // - For the very first tab the load looks "normal". The new tab Web UI is
1378 // the pending one, and we want it to apply here.
1379 //
1380 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1381 // get switched to the one previously associated with the new tab pages.
1382 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1383 // have a committed Web UI in this case.
1384 //
1385 // This condition handles all of these cases:
1386 //
1387 // - First load in first tab: no committed nav entry + pending nav entry +
1388 // pending dom ui:
1389 // -> Use pending Web UI if any.
1390 //
1391 // - First load in second tab: no committed nav entry + pending nav entry +
1392 // no pending Web UI:
1393 // -> Use the committed Web UI if any.
1394 //
1395 // - Second navigation in any tab: committed nav entry + pending nav entry:
1396 // -> Use pending Web UI if any.
1397 //
1398 // - Normal state with no load: committed nav entry + no pending nav entry:
1399 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251400 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271401 (controller_.GetLastCommittedEntry() ||
1402 render_manager_.pending_web_ui()))
1403 return render_manager_.pending_web_ui();
1404 return render_manager_.web_ui();
1405}
1406
[email protected]b172aee2012-04-10 17:05:261407bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271408 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581409 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271410}
1411
[email protected]b172aee2012-04-10 17:05:261412bool WebContentsImpl::HasOpener() const {
[email protected]a0358d72012-03-09 14:06:501413 return has_opener_;
1414}
1415
[email protected]b172aee2012-04-10 17:05:261416void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321417 SkColor color) {
[email protected]da8543762012-03-20 08:52:201418 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1419 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1420}
1421
[email protected]b172aee2012-04-10 17:05:261422void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201423 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1424 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1425 if (delegate_)
1426 delegate_->DidEndColorChooser();
1427 color_chooser_ = NULL;
1428}
1429
[email protected]b172aee2012-04-10 17:05:261430bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471431 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271432 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221433 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231434 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411435 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271436}
1437
[email protected]b172aee2012-04-10 17:05:261438void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271439 if (delegate_)
1440 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211441}
1442
[email protected]b172aee2012-04-10 17:05:261443void WebContentsImpl::OnRegisterIntentService(const string16& action,
1444 const string16& type,
1445 const string16& href,
1446 const string16& title,
1447 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511448 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301449 this, action, type, href, title, disposition);
1450}
1451
[email protected]b172aee2012-04-10 17:05:261452void WebContentsImpl::OnWebIntentDispatch(
1453 const webkit_glue::WebIntentData& intent,
1454 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001455 WebIntentsDispatcherImpl* intents_dispatcher =
1456 new WebIntentsDispatcherImpl(this, intent, intent_id);
1457 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301458}
1459
[email protected]b172aee2012-04-10 17:05:261460void WebContentsImpl::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1461 bool is_main_frame,
1462 const GURL& opener_url,
1463 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281464 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181465 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451466 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581467 GetRenderViewHostImpl()->FilterURL(
1468 ChildProcessSecurityPolicyImpl::GetInstance(),
1469 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451470 false,
[email protected]9f76c1e2012-03-05 15:15:581471 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451472 GetRenderViewHostImpl()->FilterURL(
1473 ChildProcessSecurityPolicyImpl::GetInstance(),
1474 GetRenderProcessHost()->GetID(),
1475 true,
1476 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181477
[email protected]8093a542011-05-13 07:29:321478 RenderViewHost* rvh =
1479 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521480 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101481 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101483 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321484 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101485
[email protected]724159a2010-12-30 01:11:181486 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591487 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251488 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451489 ProvisionalChangeToMainFrameUrl(validated_url,
1490 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181491 }
1492}
1493
[email protected]b172aee2012-04-10 17:05:261494void WebContentsImpl::OnDidRedirectProvisionalLoad(int32 page_id,
1495 const GURL& opener_url,
1496 const GURL& source_url,
1497 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491498 // TODO(creis): Remove this method and have the pre-rendering code listen to
1499 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1500 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451501 GURL validated_source_url(source_url);
1502 GURL validated_target_url(target_url);
1503 GURL validated_opener_url(opener_url);
1504 GetRenderViewHostImpl()->FilterURL(
1505 ChildProcessSecurityPolicyImpl::GetInstance(),
1506 GetRenderProcessHost()->GetID(),
1507 false,
1508 &validated_source_url);
1509 GetRenderViewHostImpl()->FilterURL(
1510 ChildProcessSecurityPolicyImpl::GetInstance(),
1511 GetRenderProcessHost()->GetID(),
1512 false,
1513 &validated_target_url);
1514 GetRenderViewHostImpl()->FilterURL(
1515 ChildProcessSecurityPolicyImpl::GetInstance(),
1516 GetRenderProcessHost()->GetID(),
1517 true,
1518 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231519 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181520 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251521 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181522 else
1523 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451524 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181525 return;
[email protected]e7d50892011-01-19 21:47:381526
[email protected]4850a7f2011-03-08 23:36:591527 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251528 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451529 ProvisionalChangeToMainFrameUrl(validated_target_url,
1530 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181531}
1532
[email protected]b172aee2012-04-10 17:05:261533void WebContentsImpl::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581534 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1535 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1536 << ", error_code: " << params.error_code
1537 << ", error_description: " << params.error_description
1538 << ", is_main_frame: " << params.is_main_frame
1539 << ", showing_repost_interstitial: " <<
1540 params.showing_repost_interstitial
1541 << ", frame_id: " << params.frame_id;
1542 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581543 GetRenderViewHostImpl()->FilterURL(
1544 ChildProcessSecurityPolicyImpl::GetInstance(),
1545 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451546 false,
[email protected]9f76c1e2012-03-05 15:15:581547 &validated_url);
[email protected]724159a2010-12-30 01:11:181548
[email protected]d7b175e2011-10-11 15:31:581549 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181550 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1551 // This means that the interstitial won't be torn down properly, which is
1552 // bad. But if we have an interstitial, go back to another tab type, and
1553 // then load the same interstitial again, we could end up getting the first
1554 // interstitial's "failed" message (as a result of the cancel) when we're on
1555 // the second one.
1556 //
1557 // We can't tell this apart, so we think we're tearing down the current page
1558 // which will cause a crash later one. There is also some code in
1559 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1560 // out because of this problem.
1561 //
1562 // http://code.google.com/p/chromium/issues/detail?id=2855
1563 // Because this will not tear down the interstitial properly, if "back" is
1564 // back to another tab type, the interstitial will still be somewhat alive
1565 // in the previous tab type. If you navigate somewhere that activates the
1566 // tab with the interstitial again, you'll see a flash before the new load
1567 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271568 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181569 LOG(WARNING) << "Discarding message during interstitial.";
1570 return;
1571 }
1572
[email protected]02102f82011-06-13 20:37:021573 // Discard our pending entry if the load canceled (e.g. if we decided to
1574 // download the file instead of load it). We do not verify that the URL
1575 // being canceled matches the pending entry's URL because they will not
1576 // match if a redirect occurred (in which case we do not want to leave a
1577 // stale redirect URL showing). This means that we also cancel the pending
1578 // entry if the user started a new navigation. As a result, the navigation
1579 // controller may not remember that a load is in progress, but the
1580 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251581 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161582 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181583
[email protected]151a63d2011-12-20 22:32:521584 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181585 }
1586
[email protected]d8c660432011-12-22 20:51:251587 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581588 observers_,
1589 DidFailProvisionalLoad(params.frame_id,
1590 params.is_main_frame,
1591 validated_url,
1592 params.error_code,
1593 params.error_description));
[email protected]724159a2010-12-30 01:11:181594}
1595
[email protected]b172aee2012-04-10 17:05:261596void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181597 const GURL& url,
[email protected]70435962011-08-02 20:13:281598 const std::string& security_info,
1599 const std::string& http_method,
1600 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191601 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181602 cache.Increment();
1603
1604 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081605 int cert_id = 0;
1606 net::CertStatus cert_status = 0;
1607 int security_bits = -1;
1608 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511609 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1610 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301611 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161612 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181613
[email protected]ad50def52011-10-19 23:17:071614 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271615 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501616 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531617 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181618}
1619
[email protected]b172aee2012-04-10 17:05:261620void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381621 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181622 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201623 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181624}
1625
[email protected]b172aee2012-04-10 17:05:261626void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021627 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231628 LOG(INFO) << security_origin << " ran insecure content from "
1629 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381630 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411631 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1632 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181633 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411634 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201635 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181636}
1637
[email protected]b172aee2012-04-10 17:05:261638void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181639 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101641 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181642}
1643
[email protected]b172aee2012-04-10 17:05:261644void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311645 int64 frame_id,
1646 const GURL& validated_url,
1647 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251648 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311649 DidFinishLoad(frame_id, validated_url, is_main_frame));
1650}
1651
[email protected]b172aee2012-04-10 17:05:261652void WebContentsImpl::OnDidFailLoadWithError(
1653 int64 frame_id,
1654 const GURL& validated_url,
1655 bool is_main_frame,
1656 int error_code,
1657 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311659 DidFailLoad(frame_id, validated_url, is_main_frame,
1660 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181661}
1662
[email protected]b172aee2012-04-10 17:05:261663void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271664 content_restrictions_ = restrictions;
1665 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171666}
1667
[email protected]b172aee2012-04-10 17:05:261668void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261669 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231670 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251671 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261672 if (!entry)
1673 return;
1674 // Note that we don't call NavigationController::GotToOffset() as we don't
1675 // want to create a pending navigation entry (it might end up lingering
1676 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251677 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581678 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511679 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581680 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471681 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571682
1683 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1684 // it in now that we know. This allows us to find the entry when it commits.
1685 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231686 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331687 entry->set_site_instance(
1688 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571689 }
[email protected]216813952011-05-19 22:21:261690 }
1691}
1692
[email protected]b172aee2012-04-10 17:05:261693void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1694 int maximum_percent,
1695 bool remember) {
[email protected]216813952011-05-19 22:21:261696 minimum_zoom_percent_ = minimum_percent;
1697 maximum_zoom_percent_ = maximum_percent;
1698 temporary_zoom_settings_ = !remember;
1699}
1700
[email protected]b172aee2012-04-10 17:05:261701void WebContentsImpl::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481702 download_stats::RecordDownloadSource(
1703 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261704 // Check if the URL to save matches the URL of the main frame. Since this
1705 // message originates from Pepper plugins, it may not be the case if the
1706 // plugin is an embedded element.
1707 GURL main_frame_url = GetURL();
1708 if (!main_frame_url.is_valid())
1709 return;
1710 bool is_main_frame = (url == main_frame_url);
1711 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271712}
1713
[email protected]b172aee2012-04-10 17:05:261714void WebContentsImpl::OnEnumerateDirectory(int request_id,
1715 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591716 ChildProcessSecurityPolicyImpl* policy =
1717 ChildProcessSecurityPolicyImpl::GetInstance();
1718 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1719 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211720}
1721
[email protected]b172aee2012-04-10 17:05:261722void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511723 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1727 const GURL& url,
1728 const string16& title) {
[email protected]b9535422012-02-09 01:47:591729 ChildProcessSecurityPolicyImpl* policy =
1730 ChildProcessSecurityPolicyImpl::GetInstance();
1731 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1732 return;
[email protected]6934a702011-12-20 00:04:511733 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201734}
1735
[email protected]b172aee2012-04-10 17:05:261736void WebContentsImpl::OnFindReply(int request_id,
1737 int number_of_matches,
1738 const gfx::Rect& selection_rect,
1739 int active_match_ordinal,
1740 bool final_update) {
[email protected]6934a702011-12-20 00:04:511741 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1742 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001743 // Send a notification to the renderer that we are ready to receive more
1744 // results from the scoping effort of the Find operation. The FindInPage
1745 // scoping is asynchronous and periodically sends results back up to the
1746 // browser using IPC. In an effort to not spam the browser we have the
1747 // browser send an ACK for each FindReply message and have the renderer
1748 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581749 GetRenderViewHostImpl()->Send(
1750 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441754 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1755 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1759 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101760 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101762 AppCacheAccessed(manifest_url, blocked_by_policy));
1763}
1764
[email protected]b172aee2012-04-10 17:05:261765void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321766 SkColor color) {
[email protected]da8543762012-03-20 08:52:201767 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1768}
1769
[email protected]b172aee2012-04-10 17:05:261770void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201771 if (color_chooser_ &&
1772 color_chooser_id == color_chooser_->identifier())
1773 color_chooser_->End();
1774}
1775
[email protected]b172aee2012-04-10 17:05:261776void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321777 SkColor color) {
[email protected]da8543762012-03-20 08:52:201778 if (color_chooser_ &&
1779 color_chooser_id == color_chooser_->identifier())
1780 color_chooser_->SetSelectedColor(color);
1781}
1782
[email protected]9f2a9d72012-04-16 16:02:221783void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1784 const FilePath& path,
1785 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441786 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1787 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291788}
1789
[email protected]d0759f492012-04-19 22:50:501790// This exists for render views that don't have a WebUI, but do have WebUI
1791// bindings enabled.
1792void WebContentsImpl::OnWebUISend(const GURL& source_url,
1793 const std::string& name,
1794 const base::ListValue& args) {
1795 if (delegate_)
1796 delegate_->WebUISend(this, source_url, name, args);
1797}
1798
[email protected]96d185d2009-04-24 03:28:541799// Notifies the RenderWidgetHost instance about the fact that the page is
1800// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261801void WebContentsImpl::SetIsLoading(bool is_loading,
1802 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541803 if (is_loading == is_loading_)
1804 return;
1805
1806 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211807 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541808 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561809 upload_size_ = 0;
1810 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541811 }
1812
1813 render_manager_.SetIsLoading(is_loading);
1814
1815 is_loading_ = is_loading;
1816 waiting_for_response_ = is_loading;
1817
[email protected]6ebdc9b2010-09-27 16:55:571818 if (delegate_)
1819 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461820 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541821
[email protected]432115822011-07-10 15:52:271822 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1823 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071824 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541825 if (details)
[email protected]6c2381d2011-10-19 02:52:531826 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071827 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501828 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541829 det);
1830}
1831
[email protected]b172aee2012-04-10 17:05:261832void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131833 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321834 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561835 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381836 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441837 // that opened the window, as long as both renderers have the same
1838 // privileges.
[email protected]1fd1a502011-03-30 16:55:561839 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561840 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581841 // web_ui might be NULL if the URL refers to a non-existent extension.
1842 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401843 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521844 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441845 }
1846 }
[email protected]1fd1a502011-03-30 16:55:561847 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441848 }
1849
[email protected]4e697b042011-07-08 06:44:561850 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321851 // Clear the status bubble. This is a workaround for a bug where WebKit
1852 // doesn't let us know that the cursor left an element during a
1853 // transition (this is also why the mouse cursor remains as a hand after
1854 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1855 // clear the bubble when a user navigates to a named anchor in the same
1856 // page.
[email protected]36fc0392011-12-25 03:59:511857 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321858 }
1859
[email protected]a6e82fc2010-02-24 22:28:141860 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471861 // Once the main frame is navigated, we're no longer considered to have
1862 // displayed insecure content.
1863 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171864 }
[email protected]ce5c4502009-05-06 16:46:111865
[email protected]3c9e1872010-11-18 16:17:491866 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251867 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041868 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321869}
1870
[email protected]b172aee2012-04-10 17:05:261871void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321872 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131873 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321874 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061875 // If we navigate off the page, reset JavaScript state. This does nothing
1876 // to prevent a malicious script from spamming messages, since the script
1877 // could just reload the page to stop blocking.
1878 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551879 dialog_creator_->ResetJavaScriptState(this);
1880 dialog_creator_ = NULL;
1881 }
[email protected]420ae012009-04-24 05:16:321882
[email protected]3c9e1872010-11-18 16:17:491883 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251884 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041885 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321886}
1887
[email protected]b172aee2012-04-10 17:05:261888void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461889 // If we are creating a RVH for a restored controller, then we need to make
1890 // sure the RenderView starts with a next_page_id_ larger than the number
1891 // of restored entries. This must be called before the RenderView starts
1892 // navigating (to avoid a race between the browser updating max_page_id and
1893 // the renderer updating next_page_id_). Because of this, we only call this
1894 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561895 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581896 if (max_restored_page_id >
1897 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1898 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1899 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321900}
1901
[email protected]b172aee2012-04-10 17:05:261902bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1903 const string16& title) {
[email protected]420ae012009-04-24 05:16:321904 // For file URLs without a title, use the pathname instead. In the case of a
1905 // synthesized title, we don't want the update to count toward the "one set
1906 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511907 string16 final_title;
[email protected]420ae012009-04-24 05:16:321908 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511909 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1910 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321911 explicit_set = false; // Don't count synthetic titles toward the set limit.
1912 } else {
[email protected]acafd272011-07-26 17:35:571913 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321914 explicit_set = true;
1915 }
1916
[email protected]987fc3a2011-05-26 14:18:091917 // If a page is created via window.open and never navigated,
1918 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551919 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091920 if (entry) {
[email protected]36fc0392011-12-25 03:59:511921 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091922 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321923
[email protected]36fc0392011-12-25 03:59:511924 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091925 } else {
1926 if (page_title_when_no_navigation_entry_ == final_title)
1927 return false; // Nothing changed, don't bother.
1928
1929 page_title_when_no_navigation_entry_ = final_title;
1930 }
[email protected]420ae012009-04-24 05:16:321931
[email protected]420ae012009-04-24 05:16:321932 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231933 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321934
[email protected]2bb171882012-03-07 02:09:461935 std::pair<content::NavigationEntry*, bool> details =
1936 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141937
[email protected]ad50def52011-10-19 23:17:071938 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441939 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1940 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461941 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041942
[email protected]420ae012009-04-24 05:16:321943 return true;
1944}
1945
[email protected]b172aee2012-04-10 17:05:261946void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321947 // After sending out a swap notification, we need to send a disconnect
1948 // notification so that clients that pick up a pointer to |this| can NULL the
1949 // pointer. See Bug 1230284.
1950 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071951 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201952 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1953 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071954 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321955}
1956
[email protected]b172aee2012-04-10 17:05:261957void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:321958 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071959 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121960 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1961 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071962 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321963}
1964
[email protected]b172aee2012-04-10 17:05:261965void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:321966 if (!notify_disconnection_)
1967 return;
1968
1969 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071970 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321971 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1972 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071973 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321974}
1975
[email protected]b172aee2012-04-10 17:05:261976RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321977 return view_.get();
1978}
1979
[email protected]8d3347f2009-07-09 22:00:211980RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:261981WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:211982 return &render_manager_;
1983}
1984
[email protected]b172aee2012-04-10 17:05:261985content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371986 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461987 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511988}
1989
[email protected]b172aee2012-04-10 17:05:261990WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:171991 return this;
1992}
1993
[email protected]b172aee2012-04-10 17:05:261994content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431995 return view_type_;
[email protected]7b291f92009-08-14 05:43:531996}
1997
[email protected]b172aee2012-04-10 17:05:261998gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:171999 if (delegate_)
2000 return delegate_->GetRootWindowResizerRect();
2001 return gfx::Rect();
2002}
2003
[email protected]b172aee2012-04-10 17:05:262004void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:072005 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272006 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322007 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532008 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232009 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322010 if (!entry)
2011 return;
2012
2013 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352014 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562015 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582016 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322017
2018 if (entry->IsViewSourceMode()) {
2019 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582020 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2021 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322022 }
[email protected]0666aef2009-05-13 19:48:082023
[email protected]d487beefe2011-12-21 05:41:212024 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262025
2026 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252027 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322028}
2029
[email protected]b172aee2012-04-10 17:05:262030void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522031 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322032 // Don't notify the world, since this came from a renderer in the
2033 // background.
2034 return;
2035 }
2036
2037 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312038 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232039 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302040
2041 // Restore the focus to the tab (otherwise the focus will be on the top
2042 // window).
[email protected]484ae5912010-09-29 19:16:142043 if (was_crashed && !FocusLocationBarByDefault() &&
2044 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302045 Focus();
[email protected]484ae5912010-09-29 19:16:142046 }
[email protected]32ded2212011-11-10 18:51:432047
[email protected]d8c660432011-12-22 20:51:252048 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322049}
2050
[email protected]b172aee2012-04-10 17:05:262051void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2052 base::TerminationStatus status,
2053 int error_code) {
[email protected]151a63d2011-12-20 22:32:522054 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322055 // The pending page's RenderViewHost is gone.
2056 return;
2057 }
2058
2059 SetIsLoading(false, NULL);
2060 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232061 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312062 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322063
[email protected]d8c660432011-12-22 20:51:252064 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272065 observers_,
[email protected]be1f56ab2011-12-22 06:55:312066 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482070 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252071 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062072}
2073
[email protected]b172aee2012-04-10 17:05:262074void WebContentsImpl::DidNavigate(
2075 RenderViewHost* rvh,
2076 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582077 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322078 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372079
[email protected]434f69f2012-02-06 21:56:522080 // Update the site of the SiteInstance if it doesn't have one yet, unless
2081 // this is for about:blank. In that case, the SiteInstance can still be
2082 // considered unused until a navigation to a real page.
2083 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2084 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332085 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522086 }
[email protected]420ae012009-04-24 05:16:322087
2088 // Need to update MIME type here because it's referred to in
2089 // UpdateNavigationCommands() called by RendererDidNavigate() to
2090 // determine whether or not to enable the encoding menu.
2091 // It's updated only for the main frame. For a subframe,
2092 // RenderView::UpdateURL does not set params.contents_mime_type.
2093 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2094 // TODO(jungshik): Add a test for the encoding menu to avoid
2095 // regressing it again.
[email protected]2905f742011-10-13 03:51:582096 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322097 contents_mime_type_ = params.contents_mime_type;
2098
[email protected]8286f51a2011-05-31 17:39:132099 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002100 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392101
[email protected]a9c0bfe2010-09-17 08:35:222102 // Send notification about committed provisional loads. This notification is
2103 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2104 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082105 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072106 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2107 // that is not recorded in the navigation history. For the purpose of
2108 // tracking navigation events, we treat this event as a sub frame navigation
2109 // event.
2110 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582111 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222112 // Whether or not a page transition was triggered by going backward or
2113 // forward in the history is only stored in the navigation controller's
2114 // entry list.
2115 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512116 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582117 content::PAGE_TRANSITION_FORWARD_BACK)) {
2118 transition_type = content::PageTransitionFromInt(
2119 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222120 }
[email protected]0d60f0192011-04-14 12:40:102121 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252122 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102123 DidCommitProvisionalLoadForFrame(params.frame_id,
2124 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222125 }
2126
[email protected]76543b92009-08-31 17:27:452127 if (!did_navigate)
2128 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322129
2130 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2131 // for the appropriate notification (best) or you can add it to
2132 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2133 // necessary, please).
2134
2135 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002136 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322137 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512138 if (delegate_)
2139 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002140 }
[email protected]420ae012009-04-24 05:16:322141 DidNavigateAnyFramePostCommit(rvh, details, params);
2142}
2143
[email protected]b172aee2012-04-10 17:05:262144void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2145 int32 page_id,
2146 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152147 // Ensure that this state update comes from either the active RVH or one of
2148 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522149 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322150
2151 // We must be prepared to handle state updates for any page, these occur
2152 // when the user is scrolling and entering form data, as well as when we're
2153 // leaving a page, in which case our state may have already been moved to
2154 // the next page. The navigation controller will look up the appropriate
2155 // NavigationEntry and update it when it is notified via the delegate.
2156
2157 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582158 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322159 if (entry_index < 0)
2160 return;
[email protected]10f417c52011-12-28 21:04:232161 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322162
[email protected]36fc0392011-12-25 03:59:512163 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322164 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512165 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322166 controller_.NotifyEntryChanged(entry, entry_index);
2167}
2168
[email protected]b172aee2012-04-10 17:05:262169void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2170 int32 page_id,
2171 const string16& title,
2172 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322173 // If we have a title, that's a pretty good indication that we've started
2174 // getting useful data.
2175 SetNotWaitingForResponse();
2176
[email protected]73eb2602012-02-09 19:50:552177 // Try to find the navigation entry, which might not be the current one.
2178 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232179 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582180 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092181
[email protected]73eb2602012-02-09 19:50:552182 // We can handle title updates when we don't have an entry in
2183 // UpdateTitleForEntry, but only if the update is from the current RVH.
2184 if (!entry && rvh != GetRenderViewHost())
2185 return;
2186
[email protected]a49e10b2011-08-01 23:57:462187 // TODO(evan): make use of title_direction.
2188 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092189 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322190 return;
2191
2192 // Broadcast notifications when the UI should be updated.
2193 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462194 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322195}
2196
[email protected]b172aee2012-04-10 17:05:262197void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2198 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312199 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322200}
2201
[email protected]b172aee2012-04-10 17:05:262202void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512203 if (delegate_)
2204 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322205}
2206
[email protected]b172aee2012-04-10 17:05:262207void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292208 // The UI may be in an event-tracking loop, such as between the
2209 // mouse-down and mouse-up in text selection or a button click.
2210 // Defer the close until after tracking is complete, so that we
2211 // don't free objects out from under the UI.
2212 // TODO(shess): This could probably be integrated with the
2213 // IsDoingDrag() test below. Punting for now because I need more
2214 // research to understand how this impacts platforms other than Mac.
2215 // TODO(shess): This could get more fine-grained. For instance,
2216 // closing a tab in another window while selecting text in the
2217 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212218 if (GetView()->IsEventTracking()) {
2219 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292220 return;
2221 }
2222
[email protected]24a4d1062009-07-10 23:10:422223 // If we close the tab while we're in the middle of a drag, we'll crash.
2224 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212225 if (GetView()->IsDoingDrag()) {
2226 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422227 return;
2228 }
2229
[email protected]420ae012009-04-24 05:16:322230 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522231 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512232 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322233}
2234
[email protected]b172aee2012-04-10 17:05:262235void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522236 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512237 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572238}
2239
[email protected]b172aee2012-04-10 17:05:262240void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512241 if (delegate_ && delegate_->IsPopupOrPanel(this))
2242 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322243}
2244
[email protected]b172aee2012-04-10 17:05:262245void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322246 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492247
[email protected]82114f52012-03-20 22:53:412248 if (delegate_ && content_restrictions_)
2249 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492250
2251 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252252 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322253}
2254
[email protected]b172aee2012-04-10 17:05:262255void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322256 scoped_ptr<LoadNotificationDetails> details;
2257
[email protected]10f417c52011-12-28 21:04:232258 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322259 // An entry may not exist for a stop when loading an initial blank page or
2260 // if an iframe injected by script into a blank page finishes loading.
2261 if (entry) {
[email protected]420ae012009-04-24 05:16:322262 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2263
2264 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512265 entry->GetVirtualURL(),
2266 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322267 elapsed,
2268 &controller_,
2269 controller_.GetCurrentEntryIndex()));
2270 }
2271
[email protected]420ae012009-04-24 05:16:322272 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492273
2274 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252275 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322276}
2277
[email protected]b172aee2012-04-10 17:05:262278void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162279 controller_.DiscardNonCommittedEntries();
2280
2281 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462282 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162283}
2284
[email protected]b172aee2012-04-10 17:05:262285void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512286 if (delegate_)
2287 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402288}
2289
[email protected]87717d0e2012-04-26 02:58:432290void WebContentsImpl::DocumentAvailableInMainFrame(
2291 RenderViewHost* render_view_host) {
2292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2293 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082297 RenderViewHost* render_view_host,
2298 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072299 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272300 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322301 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532302 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::RequestOpenURL(const GURL& url,
2306 const content::Referrer& referrer,
2307 WindowOpenDisposition disposition,
2308 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482309 // Delegate to RequestTransferURL because this is just the generic
2310 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582311 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482312 GlobalRequestID());
2313}
2314
[email protected]b172aee2012-04-10 17:05:262315void WebContentsImpl::RequestTransferURL(
2316 const GURL& url,
2317 const content::Referrer& referrer,
2318 WindowOpenDisposition disposition,
2319 int64 source_frame_id,
2320 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202321 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582322 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582323 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352324 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322325 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2326 // generated suggestions).
2327 //
[email protected]e0112912011-02-02 22:54:352328 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162329 // want web sites to see a referrer of "chrome://blah" (and some
2330 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322331 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432332 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222333 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482334 false /* is_renderer_initiated */);
2335 params.transferred_global_request_id = old_request_id;
2336 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222337 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322338 } else {
[email protected]6bf6a6b52012-02-03 15:41:432339 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482340 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2341 params.transferred_global_request_id = old_request_id;
2342 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582343 }
2344 if (new_contents) {
2345 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252346 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582347 DidOpenRequestedURL(new_contents,
2348 url,
2349 referrer,
2350 disposition,
2351 transition_type,
2352 source_frame_id));
[email protected]420ae012009-04-24 05:16:322353 }
2354}
2355
[email protected]b172aee2012-04-10 17:05:262356void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342357 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412358 const string16& message,
2359 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322360 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472361 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322362 IPC::Message* reply_msg,
2363 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072364 // Suppress JavaScript dialogs when requested. Also suppress messages when
2365 // showing an interstitial as it's shown over the previous page and we don't
2366 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502367 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582368 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272369 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072370 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522371 delegate_->ShouldSuppressDialogs() ||
2372 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322373
2374 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432375 std::string accept_lang = content::GetContentClient()->browser()->
2376 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552377 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522378 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432379 this,
2380 frame_url.GetOrigin(),
2381 accept_lang,
2382 javascript_message_type,
2383 message,
[email protected]51da7e32012-01-30 19:24:522384 default_prompt,
[email protected]b172aee2012-04-10 17:05:262385 base::Bind(&WebContentsImpl::OnDialogClosed,
2386 base::Unretained(this),
2387 rvh,
2388 reply_msg),
[email protected]51da7e32012-01-30 19:24:522389 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322390 }
[email protected]3ab9cb82011-06-03 18:02:072391
2392 if (suppress_this_message) {
2393 // If we are suppressing messages, just reply as if the user immediately
2394 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342395 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072396 }
2397
2398 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322399}
2400
[email protected]b172aee2012-04-10 17:05:262401void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2402 const string16& message,
2403 bool is_reload,
2404 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582405 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512406 if (delegate_)
2407 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072408
2409 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582410 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072411 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522412 delegate_->ShouldSuppressDialogs() ||
2413 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152414 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342415 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582416 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502417 return;
2418 }
[email protected]3ab9cb82011-06-03 18:02:072419
[email protected]7ab1e7d62009-10-14 23:32:012420 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552421 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522422 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322423 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262424 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522425 reply_msg));
[email protected]420ae012009-04-24 05:16:322426}
2427
[email protected]b172aee2012-04-10 17:05:262428WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332429 // We want to base the page config off of the real URL, rather than the
2430 // display URL.
2431 GURL url = controller_.GetActiveEntry()
2432 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2433 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322434}
2435
[email protected]b172aee2012-04-10 17:05:262436void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272437 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252438 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222439
[email protected]ea114722012-03-12 01:11:252440 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172441 if (rdh) // NULL in unittests.
2442 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252443}
2444
[email protected]b172aee2012-04-10 17:05:262445void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442446 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252447 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442448}
2449
[email protected]b172aee2012-04-10 17:05:262450void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2451 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152452 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522453 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152454 return;
2455
[email protected]9f76c1e2012-03-05 15:15:582456 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2457
[email protected]e5fc1632011-08-08 07:51:532458 // Ignore renderer unresponsive event if debugger is attached to the tab
2459 // since the event may be a result of the renderer sitting on a breakpoint.
2460 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442461 DevToolsAgentHost* agent =
2462 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2463 if (agent &&
2464 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532465 return;
2466
[email protected]420ae012009-04-24 05:16:322467 if (is_during_unload) {
2468 // Hang occurred while firing the beforeunload/unload handler.
2469 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582470 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322471
2472 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2473 return;
2474
2475 // If the tab hangs in the beforeunload/unload handler there's really
2476 // nothing we can do to recover. Pretend the unload listeners have
2477 // all fired and close the tab. If the hang is in the beforeunload handler
2478 // then the user will not have the option of cancelling the close.
2479 Close(rvh);
2480 return;
2481 }
2482
[email protected]9f76c1e2012-03-05 15:15:582483 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472484 return;
2485
[email protected]6934a702011-12-20 00:04:512486 if (delegate_)
2487 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322488}
2489
[email protected]b172aee2012-04-10 17:05:262490void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512491 if (delegate_)
2492 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322493}
2494
[email protected]b172aee2012-04-10 17:05:262495void WebContentsImpl::LoadStateChanged(
2496 const GURL& url,
2497 const net::LoadStateWithParam& load_state,
2498 uint64 upload_position,
2499 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322500 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562501 upload_position_ = upload_position;
2502 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502503 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202504 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302505 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212506 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322507 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462508 if (IsLoading()) {
2509 NotifyNavigationStateChanged(
2510 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2511 }
[email protected]420ae012009-04-24 05:16:322512}
2513
[email protected]b172aee2012-04-10 17:05:262514void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512515 if (delegate_)
2516 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252517}
2518
[email protected]b172aee2012-04-10 17:05:262519void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322520 bool proceed,
2521 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512522 if (delegate_)
2523 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322524}
2525
[email protected]b172aee2012-04-10 17:05:262526void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542527 RenderViewHost* render_view_host) {
2528 DidStartLoading();
2529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542532 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232533 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2534 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542535}
2536
[email protected]b172aee2012-04-10 17:05:262537void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102538 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262539 gfx::Size size = view_->GetContainerSize();
2540 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2541 // here during container initialization and normal window size will be set
2542 // later. In case of tab duplication this resizing to 0x0 prevents setting
2543 // normal size later so just ignore it.
2544 if (!size.IsEmpty())
2545 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322546}
2547
[email protected]b172aee2012-04-10 17:05:262548void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542549 NotifySwapped();
2550}
2551
[email protected]b172aee2012-04-10 17:05:262552NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202553 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542554}
2555
[email protected]b172aee2012-04-10 17:05:262556WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562557 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322558}
2559
[email protected]10f417c52011-12-28 21:04:232560NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262561 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322562 return controller_.GetLastCommittedEntry();
2563}
2564
[email protected]b172aee2012-04-10 17:05:262565bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]420ae012009-04-24 05:16:322566 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442567 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322568 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522569
[email protected]420ae012009-04-24 05:16:322570 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442571 if (rwh_view)
2572 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322573
[email protected]74ce1ad2011-12-16 21:51:462574 // Make sure we use the correct starting page_id in the new RenderView.
2575 UpdateMaxPageIDIfNecessary(render_view_host);
2576 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582577 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462578
[email protected]9f76c1e2012-03-05 15:15:582579 if (!static_cast<RenderViewHostImpl*>(
2580 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522581 return false;
2582
[email protected]e60c0232011-11-11 19:56:352583#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502584 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2585 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442586 if (rwh_view) {
2587 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2588 render_widget_host->WasResized();
2589 }
[email protected]f8233cc2011-05-31 20:24:502590#endif
2591
[email protected]420ae012009-04-24 05:16:322592 return true;
2593}
2594
[email protected]b172aee2012-04-10 17:05:262595void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2596 IPC::Message* reply_msg,
2597 bool success,
2598 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542599 if (is_showing_before_unload_dialog_ && !success) {
2600 // If a beforeunload dialog is canceled, we need to stop the throbber from
2601 // spinning, since we forced it to start spinning in Navigate.
2602 DidStopLoading();
2603
[email protected]3bbacc5b2012-04-17 17:46:152604 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542605 }
2606 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582607 static_cast<RenderViewHostImpl*>(
2608 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542609}
2610
[email protected]b172aee2012-04-10 17:05:262611void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122612 encoding_ = content::GetContentClient()->browser()->
2613 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102614}
[email protected]f45d2a72010-03-08 23:28:352615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::SaveURL(const GURL& url,
2617 const GURL& referrer,
2618 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142619 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2620 if (!dlm)
2621 return;
2622 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262623 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142624 const NavigationEntry* entry = controller_.GetActiveEntry();
2625 if (entry)
2626 post_id = entry->GetPostID();
2627 }
[email protected]29a5ffc82012-03-13 19:35:582628 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142629 save_info.prompt_for_save_location = true;
2630 dlm->DownloadUrl(url,
2631 referrer,
2632 "",
2633 true, // prefer_cache
2634 post_id,
2635 save_info,
[email protected]89e6aa72012-03-12 22:51:332636 this,
2637 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142638}
2639
[email protected]b172aee2012-04-10 17:05:262640void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212641 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442642 // Can be NULL during tests.
2643 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212644 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362645}
[email protected]9f76c1e2012-03-05 15:15:582646
[email protected]b172aee2012-04-10 17:05:262647RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582648 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2649}