blob: 08d28b39efad341c003a49450b681216f969a7c9 [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]82c9a8e2012-05-02 01:07:2361#include "ui/base/ui_base_switches.h"
[email protected]8b3b36152012-05-01 04:55:0762#include "ui/gfx/monitor.h"
63#include "ui/gfx/screen.h"
[email protected]a53209b2012-01-20 16:48:1664#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2965#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5466#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3467#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3768#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2469#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3170#include "webkit/glue/webpreferences.h"
71
[email protected]68b52252012-04-04 19:26:1372#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:3573#include "content/browser/web_contents/web_contents_view_aura.h"
[email protected]68b52252012-04-04 19:26:1374#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:3575#include "content/browser/web_contents/web_contents_view_win.h"
[email protected]38b098f2012-03-14 21:11:5776#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:3577#include "content/browser/web_contents/web_contents_view_gtk.h"
[email protected]38b098f2012-03-14 21:11:5778#elif defined(OS_MACOSX)
[email protected]0c4e92e62012-04-11 15:19:0079#include "content/browser/web_contents/web_contents_view_mac.h"
[email protected]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]82c9a8e2012-05-02 01:07:23513 prefs.default_device_scale_factor =
514 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07515#else
516 if (rvh->GetView()) {
517 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
518 rvh->GetView()->GetNativeView());
519 prefs.default_device_scale_factor =
520 static_cast<int>(monitor.device_scale_factor());
521 } else {
[email protected]82c9a8e2012-05-02 01:07:23522 prefs.default_device_scale_factor =
523 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07524 }
525#endif
[email protected]43d9d782012-03-01 15:40:09526
[email protected]2e21fe292012-03-02 22:52:32527 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54528
529 return prefs;
530}
531
[email protected]b172aee2012-04-10 17:05:26532NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20533 return controller_;
534}
535
[email protected]b172aee2012-04-10 17:05:26536RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28537 return &render_manager_;
538}
539
[email protected]b172aee2012-04-10 17:05:26540bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56541 if (GetWebUI() &&
542 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17543 return true;
[email protected]d2353452012-01-19 19:53:56544 }
[email protected]f82d57b52011-04-27 19:13:17545
[email protected]d8c660432011-12-22 20:51:25546 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
547 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10548 while ((observer = it.GetNext()) != NULL)
549 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53550 return true;
[email protected]403415a2011-01-10 18:57:53551
[email protected]724159a2010-12-30 01:11:18552 bool handled = true;
553 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26554 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58555 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
556 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24557 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
558 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18559 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
560 OnDidStartProvisionalLoadForFrame)
561 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
562 OnDidRedirectProvisionalLoad)
563 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
564 OnDidFailProvisionalLoadWithError)
565 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
566 OnDidLoadResourceFromMemoryCache)
567 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
568 OnDidDisplayInsecureContent)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
570 OnDidRunInsecureContent)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
572 OnDocumentLoadedInFrame)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26574 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
575 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17576 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
577 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25578 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26579 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59580 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21581 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20582 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
583 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
584 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16585 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45586 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10587 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20588 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
589 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
590 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
591 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29592 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50593 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18594 IPC_MESSAGE_UNHANDLED(handled = false)
595 IPC_END_MESSAGE_MAP_EX()
596
597 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38598 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18599 GetRenderProcessHost()->ReceivedBadMessage();
600 }
601
602 return handled;
603}
604
[email protected]b172aee2012-04-10 17:05:26605void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18606 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23607 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51608 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18609}
610
[email protected]b172aee2012-04-10 17:05:26611NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56612 return controller_;
613}
614
[email protected]b172aee2012-04-10 17:05:26615const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56616 return controller_;
617}
618
[email protected]b172aee2012-04-10 17:05:26619content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55620 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30621}
622
[email protected]b172aee2012-04-10 17:05:26623void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56624 view_type_ = type;
625}
626
[email protected]b172aee2012-04-10 17:05:26627content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09628 return view_type_;
629}
630
[email protected]b172aee2012-04-10 17:05:26631const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31632 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23633 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51634 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31635}
636
637
[email protected]b172aee2012-04-10 17:05:26638const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31639 return &property_bag_;
640}
641
[email protected]b172aee2012-04-10 17:05:26642base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31643 return &property_bag_;
644}
645
[email protected]b172aee2012-04-10 17:05:26646content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31647 return delegate_;
648}
649
[email protected]b172aee2012-04-10 17:05:26650void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31651 // TODO(cbentzel): remove this debugging code?
652 if (delegate == delegate_)
653 return;
654 if (delegate_)
655 delegate_->Detach(this);
656 delegate_ = delegate;
657 if (delegate_)
658 delegate_->Attach(this);
659}
660
[email protected]b172aee2012-04-10 17:05:26661content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41662 RenderViewHostImpl* host = render_manager_.current_host();
663 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16664}
665
[email protected]b172aee2012-04-10 17:05:26666RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31667 return render_manager_.current_host();
668}
669
[email protected]b172aee2012-04-10 17:05:26670RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31671 return render_manager_.GetRenderWidgetHostView();
672}
673
[email protected]b172aee2012-04-10 17:05:26674content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31675 return view_.get();
676}
677
[email protected]b172aee2012-04-10 17:05:26678content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50679 WebUIControllerFactory* factory =
680 content::GetContentClient()->browser()->GetWebUIControllerFactory();
681 if (!factory)
682 return NULL;
[email protected]d2353452012-01-19 19:53:56683 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22684 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50685 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22686 if (controller) {
687 web_ui->SetController(controller);
688 return web_ui;
689 }
690
691 delete web_ui;
692 return NULL;
693}
694
[email protected]b172aee2012-04-10 17:05:26695content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31696 return render_manager_.web_ui() ? render_manager_.web_ui()
697 : render_manager_.pending_web_ui();
698}
699
[email protected]b172aee2012-04-10 17:05:26700content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31701 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34702}
703
[email protected]b172aee2012-04-10 17:05:26704const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55705 // Transient entries take precedence. They are used for interstitial pages
706 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23707 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08708 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20709 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30710 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23711 if (entry) {
[email protected]b5cca982011-05-26 04:42:08712 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23713 }
[email protected]7ade2732011-02-10 00:13:58714 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
715 render_manager_.pending_web_ui() : render_manager_.web_ui();
716 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54717 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55718 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54719 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35720 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22721 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54722 if (!title.empty())
723 return title;
724 }
725 }
726
727 // We use the title for the last committed entry rather than a pending
728 // navigation entry. For example, when the user types in a URL, we want to
729 // keep the old page's title until the new load has committed and we get a new
730 // title.
[email protected]96d185d2009-04-24 03:28:54731 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23732 if (entry) {
[email protected]b5cca982011-05-26 04:42:08733 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23734 }
[email protected]987fc3a2011-05-26 14:18:09735
736 // |page_title_when_no_navigation_entry_| is finally used
737 // if no title cannot be retrieved.
738 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54739}
740
[email protected]b172aee2012-04-10 17:05:26741int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46742 return GetMaxPageIDForSiteInstance(GetSiteInstance());
743}
744
[email protected]b172aee2012-04-10 17:05:26745int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
746 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33747 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
748 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46749
[email protected]b6583592012-01-25 19:52:33750 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34751}
752
[email protected]b172aee2012-04-10 17:05:26753void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46754 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
755}
756
[email protected]b172aee2012-04-10 17:05:26757void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33758 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46759 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33760 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34761}
762
[email protected]b172aee2012-04-10 17:05:26763void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
764 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57765}
766
[email protected]b172aee2012-04-10 17:05:26767SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58768 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54769}
770
[email protected]b172aee2012-04-10 17:05:26771SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38772 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
773 render_manager_.pending_render_view_host() :
774 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58775 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38776}
777
[email protected]b172aee2012-04-10 17:05:26778bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31779 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49780}
781
[email protected]b172aee2012-04-10 17:05:26782bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31783 return waiting_for_response_;
784}
785
[email protected]b172aee2012-04-10 17:05:26786const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31787 return load_state_;
788}
789
[email protected]b172aee2012-04-10 17:05:26790const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31791 return load_state_host_;
792}
793
[email protected]b172aee2012-04-10 17:05:26794uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31795 return upload_size_;
796}
797
[email protected]b172aee2012-04-10 17:05:26798uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31799 return upload_position_;
800}
801
[email protected]b172aee2012-04-10 17:05:26802const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return encoding_;
804}
805
[email protected]b172aee2012-04-10 17:05:26806bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31807 return displayed_insecure_content_;
808}
809
[email protected]b172aee2012-04-10 17:05:26810void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31811 capturing_contents_ = cap;
812}
813
[email protected]b172aee2012-04-10 17:05:26814bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31815 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
816 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
817 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49818}
819
[email protected]b172aee2012-04-10 17:05:26820void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
821 int error_code) {
[email protected]443b80e2010-12-14 00:42:23822 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34823 return;
824
[email protected]443b80e2010-12-14 00:42:23825 crashed_status_ = status;
826 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46827 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34828}
829
[email protected]b172aee2012-04-10 17:05:26830base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return crashed_status_;
832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return is_being_destroyed_;
836}
837
[email protected]b172aee2012-04-10 17:05:26838void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34839 if (delegate_)
840 delegate_->NavigationStateChanged(this, changed_flags);
841}
842
[email protected]b172aee2012-04-10 17:05:26843void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54844 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04845 RenderWidgetHostViewPort* rwhv =
846 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16847 if (rwhv) {
848 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43849#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16850 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43851#endif
852 }
[email protected]96d185d2009-04-24 03:28:54853
[email protected]5ac20162010-11-24 23:33:11854 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38855
[email protected]d8c660432011-12-22 20:51:25856 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59857
858 // The resize rect might have changed while this was inactive -- send the new
859 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58860 RenderViewHostImpl* rvh =
861 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59862 if (rvh) {
863 rvh->ResizeRectChanged(GetRootWindowResizerRect());
864 }
[email protected]96d185d2009-04-24 03:28:54865}
866
[email protected]be1f56ab2011-12-22 06:55:31867
[email protected]b172aee2012-04-10 17:05:26868base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31869 return last_selected_time_;
870}
871
[email protected]b172aee2012-04-10 17:05:26872void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31873 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52874 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
875 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26876 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52877 // removes the |GetRenderViewHost()|; then when we actually destroy the
878 // window, OnWindowPosChanged() notices and calls HideContents() (which
879 // calls us).
[email protected]c30585c2012-02-16 15:02:04880 RenderWidgetHostViewPort* rwhv =
881 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16882 if (rwhv)
883 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54884 }
885
[email protected]ad50def52011-10-19 23:17:07886 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09887 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
888 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07889 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54890}
891
[email protected]b172aee2012-04-10 17:05:26892void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04893 RenderWidgetHostViewPort* rwhv =
894 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31895 if (rwhv)
896 rwhv->DidBecomeSelected();
897}
898
[email protected]b172aee2012-04-10 17:05:26899void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31900 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
901 // our superclass HideContents(), because some callers want to be very picky
902 // about the order in which these get called. In addition to making the code
903 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26904 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
905 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31906 WasHidden();
907}
908
[email protected]b172aee2012-04-10 17:05:26909bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31910 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27911 return WillNotifyDisconnection() &&
912 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58913 !static_cast<RenderViewHostImpl*>(
914 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31915}
916
[email protected]b172aee2012-04-10 17:05:26917void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27918 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25919 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27920}
921
[email protected]b172aee2012-04-10 17:05:26922WebContents* WebContentsImpl::Clone() {
[email protected]0bfbf882011-12-22 18:19:27923 // We create a new SiteInstance so that the new tab won't share processes
924 // with the old one. This can be changed in the future if we need it to share
925 // processes for some reason.
[email protected]b172aee2012-04-10 17:05:26926 WebContentsImpl* tc = new WebContentsImpl(
[email protected]0bfbf882011-12-22 18:19:27927 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33928 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27929 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20930 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27931 return tc;
932}
933
[email protected]b172aee2012-04-10 17:05:26934void WebContentsImpl::AddNewContents(WebContents* new_contents,
935 WindowOpenDisposition disposition,
936 const gfx::Rect& initial_pos,
937 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27938 if (!delegate_)
939 return;
940
941 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
942 user_gesture);
943}
944
[email protected]b172aee2012-04-10 17:05:26945gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27946 return view_->GetContentNativeView();
947}
948
[email protected]b172aee2012-04-10 17:05:26949gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27950 return view_->GetNativeView();
951}
952
[email protected]b172aee2012-04-10 17:05:26953void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27954 view_->GetContainerBounds(out);
955}
956
[email protected]b172aee2012-04-10 17:05:26957void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27958 view_->Focus();
959}
960
[email protected]b172aee2012-04-10 17:05:26961void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31962 observers_.AddObserver(observer);
963}
964
[email protected]b172aee2012-04-10 17:05:26965void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31966 observers_.RemoveObserver(observer);
967}
968
[email protected]b172aee2012-04-10 17:05:26969void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:34970 if (delegate_)
971 delegate_->ActivateContents(this);
972}
973
[email protected]b172aee2012-04-10 17:05:26974void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:12975 if (delegate_)
976 delegate_->DeactivateContents(this);
977}
978
[email protected]b172aee2012-04-10 17:05:26979void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:48980 if (delegate_)
981 delegate_->LostCapture();
982}
983
[email protected]b172aee2012-04-10 17:05:26984bool WebContentsImpl::PreHandleKeyboardEvent(
985 const NativeWebKeyboardEvent& event,
986 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:48987 return delegate_ &&
988 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
989}
990
[email protected]b172aee2012-04-10 17:05:26991void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:48992 if (delegate_)
993 delegate_->HandleKeyboardEvent(event);
994}
995
[email protected]b172aee2012-04-10 17:05:26996void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:43997 if (delegate_)
998 delegate_->HandleMouseDown();
999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481002 if (delegate_)
1003 delegate_->HandleMouseUp();
1004}
1005
[email protected]b172aee2012-04-10 17:05:261006void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481007 if (delegate_)
1008 delegate_->HandleMouseActivate();
1009}
1010
[email protected]b172aee2012-04-10 17:05:261011void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471012 if (delegate_)
1013 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381017 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121018}
1019
[email protected]42252e02012-04-26 16:29:391020void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371021 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391022 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371023 } else {
1024 GotResponseToLockMouseRequest(false);
1025 }
1026}
1027
[email protected]b172aee2012-04-10 17:05:261028void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371029 if (delegate_)
1030 delegate_->LostMouseLock();
1031}
1032
[email protected]b172aee2012-04-10 17:05:261033void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231034 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331035 if (delegate_)
1036 delegate_->UpdatePreferredSize(this, pref_size);
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341040 if (delegate_)
1041 delegate_->ResizeDueToAutoResize(this, new_size);
1042}
1043
[email protected]b172aee2012-04-10 17:05:261044WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201045 if (!delegate_)
1046 return NULL;
[email protected]00c37fc2011-08-02 00:22:501047
[email protected]e5d549d2011-12-28 01:29:201048 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1049 // Notify observers.
1050 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1051 DidOpenURL(params.url, params.referrer,
1052 params.disposition, params.transition));
1053 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341054}
1055
[email protected]b172aee2012-04-10 17:05:261056bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501057 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251058 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231059 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251060 reload_type);
[email protected]876bc832010-09-07 16:29:541061}
[email protected]96d185d2009-04-24 03:28:541062
[email protected]b172aee2012-04-10 17:05:261063bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231064 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501065 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401066 // The renderer will reject IPC messages with URLs longer than
1067 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511068 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401069 return false;
1070
[email protected]9f76c1e2012-03-05 15:15:581071 RenderViewHostImpl* dest_render_view_host =
1072 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401073 if (!dest_render_view_host)
1074 return false; // Unable to create the desired render view host.
1075
[email protected]80a8fad2011-01-29 04:02:381076 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071077 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581078 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501079 WebUIControllerFactory* factory =
1080 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271081 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501082 bool is_allowed_in_web_ui_renderer =
1083 factory &&
[email protected]24e18252012-04-16 21:26:271084 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1085 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231086 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1087 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271088 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231089 content::GetContentClient()->SetActiveURL(entry.GetURL());
1090 CHECK(0);
1091 }
[email protected]54ec6472010-04-09 19:39:581092
[email protected]96d185d2009-04-24 03:28:541093 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441094 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521095 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441096 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511097 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541098
1099 // Used for page load time metrics.
1100 current_load_start_ = base::TimeTicks::Now();
1101
1102 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341103 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271104 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471105 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341106 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541107
[email protected]36fc0392011-12-25 03:59:511108 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541109 // HACK!! This code suppresses javascript: URLs from being added to
1110 // session history, which is what we want to do for javascript: URLs that
1111 // do not generate content. What we really need is a message from the
1112 // renderer telling us that a new page was not created. The same message
1113 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511114 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541115 return false;
1116 }
1117
[email protected]3c9e1872010-11-18 16:17:491118 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251119 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041120 observers_,
[email protected]36fc0392011-12-25 03:59:511121 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541122
[email protected]09b29342011-06-24 19:18:481123 if (delegate_)
1124 delegate_->DidNavigateToPendingEntry(this);
1125
[email protected]d5f942ba2008-09-26 19:30:341126 return true;
1127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331130 const SiteInstance* site_instance,
1131 int history_length,
1132 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411133 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1134 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191135 if (render_manager_.pending_render_view_host()) {
1136 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141137 return;
[email protected]9e1ad4b2011-08-14 16:49:191138 }
[email protected]9f76c1e2012-03-05 15:15:581139 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191140 if (!rvh) {
1141 NOTREACHED();
1142 return;
1143 }
[email protected]9f76c1e2012-03-05 15:15:581144 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191145 NOTREACHED();
1146 return;
1147 }
[email protected]9f76c1e2012-03-05 15:15:581148 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191149 history_length,
1150 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141151}
1152
[email protected]b172aee2012-04-10 17:05:261153void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271154 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541155 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1156 return;
1157 }
[email protected]9f76c1e2012-03-05 15:15:581158 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541159}
1160
[email protected]b172aee2012-04-10 17:05:261161bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271162 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541163}
1164
[email protected]b172aee2012-04-10 17:05:261165InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271166 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221167}
1168
[email protected]b172aee2012-04-10 17:05:261169bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161170 // WebKit creates Document object when MIME type is application/xhtml+xml,
1171 // so we also support this MIME type.
1172 return contents_mime_type_ == "text/html" ||
1173 contents_mime_type_ == "text/xml" ||
1174 contents_mime_type_ == "application/xhtml+xml" ||
1175 contents_mime_type_ == "text/plain" ||
1176 contents_mime_type_ == "text/css" ||
1177 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1178}
1179
[email protected]b172aee2012-04-10 17:05:261180void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591181 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161182 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481183 download_stats::RecordDownloadSource(
1184 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261185 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141186 return;
[email protected]c7dd2f62011-07-18 15:57:591187 }
1188
1189 Stop();
1190
1191 // Create the save package and possibly prompt the user for the name to save
1192 // the page as. The user prompt is an asynchronous operation that runs on
1193 // another thread.
1194 save_package_ = new SavePackage(this);
1195 save_package_->GetSaveInfo();
1196}
1197
1198// Used in automated testing to bypass prompting the user for file names.
1199// Instead, the names and paths are hard coded rather than running them through
1200// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261201bool WebContentsImpl::SavePage(const FilePath& main_file,
1202 const FilePath& dir_path,
1203 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591204 // Stop the page from navigating.
1205 Stop();
1206
1207 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1208 return save_package_->Init();
1209}
1210
[email protected]b172aee2012-04-10 17:05:261211void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121212 const FilePath& file,
1213 const base::Callback<void(const FilePath&, int64)>& callback) {
1214 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1215}
1216
[email protected]b172aee2012-04-10 17:05:261217bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231218 NavigationEntryImpl* active_entry =
1219 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321220 return (active_entry != NULL &&
1221 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511222 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321223}
1224
[email protected]b172aee2012-04-10 17:05:261225const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271226 return contents_mime_type_;
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271230 return notify_disconnection_;
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311234 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581235 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1236 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161237}
1238
[email protected]b172aee2012-04-10 17:05:261239void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311240 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581241 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1242 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161243}
1244
[email protected]b172aee2012-04-10 17:05:261245content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271246 return &renderer_preferences_;
1247}
1248
[email protected]b172aee2012-04-10 17:05:261249void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271250 new_tab_start_time_ = time;
1251}
1252
[email protected]b172aee2012-04-10 17:05:261253base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271254 return new_tab_start_time_;
1255}
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151258 if (close_start_time_.is_null())
1259 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011260}
1261
[email protected]b172aee2012-04-10 17:05:261262bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191263#if defined(OS_CHROMEOS)
1264 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1265 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511266 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201267 return false;
1268 return true;
[email protected]46624bf2010-06-09 16:04:191269#else
1270 return true;
1271#endif
1272}
1273
[email protected]b172aee2012-04-10 17:05:261274void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521275 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581276 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511277 if (delegate_)
1278 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341279}
1280
[email protected]b172aee2012-04-10 17:05:261281void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271282 closed_by_user_gesture_ = value;
1283}
1284
[email protected]b172aee2012-04-10 17:05:261285bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271286 return closed_by_user_gesture_;
1287}
1288
[email protected]b172aee2012-04-10 17:05:261289double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051290 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561291 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251292 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171293 return 0;
[email protected]b75b8292010-10-01 07:28:251294
1295 double zoom_level;
1296 if (temporary_zoom_settings_) {
1297 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581298 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251299 } else {
[email protected]2ae88d12011-10-14 09:11:191300 GURL url;
[email protected]10f417c52011-12-28 21:04:231301 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191302 // Since zoom map is updated using rewritten URL, use rewritten URL
1303 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511304 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191305 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251306 }
[email protected]d0b8d092010-10-25 04:05:171307 return zoom_level;
1308}
[email protected]b75b8292010-10-01 07:28:251309
[email protected]b172aee2012-04-10 17:05:261310int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1311 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171312 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011313 // Calculate the zoom percent from the factor. Round up to the nearest whole
1314 // number.
[email protected]b75b8292010-10-01 07:28:251315 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011316 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251317 *enable_decrement = percent > minimum_zoom_percent_;
1318 *enable_increment = percent < maximum_zoom_percent_;
1319 return percent;
1320}
1321
[email protected]b172aee2012-04-10 17:05:261322void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501323 if (!delegate_)
1324 return;
1325
[email protected]10f417c52011-12-28 21:04:231326 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501327 if (!active_entry)
1328 return;
1329
[email protected]36fc0392011-12-25 03:59:511330 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121331}
1332
[email protected]b172aee2012-04-10 17:05:261333void WebContentsImpl::ViewFrameSource(const GURL& url,
1334 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271335 if (!delegate_)
1336 return;
1337
1338 delegate_->ViewSourceForFrame(this, url, content_state);
1339}
1340
[email protected]b172aee2012-04-10 17:05:261341int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271342 return minimum_zoom_percent_;
1343}
1344
[email protected]b172aee2012-04-10 17:05:261345int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271346 return maximum_zoom_percent_;
1347}
1348
[email protected]b172aee2012-04-10 17:05:261349gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231350 return preferred_size_;
1351}
1352
[email protected]b172aee2012-04-10 17:05:261353int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271354 return content_restrictions_;
1355}
1356
[email protected]b172aee2012-04-10 17:05:261357WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501358 WebUIControllerFactory* factory =
1359 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1360 if (!factory)
1361 return WebUI::kNoWebUI;
1362 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271363}
1364
[email protected]b172aee2012-04-10 17:05:261365content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271366 // When there is a pending navigation entry, we want to use the pending WebUI
1367 // that goes along with it to control the basic flags. For example, we want to
1368 // show the pending URL in the URL bar, so we want the display_url flag to
1369 // be from the pending entry.
1370 //
1371 // The confusion comes because there are multiple possibilities for the
1372 // initial load in a tab as a side effect of the way the RenderViewHostManager
1373 // works.
1374 //
1375 // - For the very first tab the load looks "normal". The new tab Web UI is
1376 // the pending one, and we want it to apply here.
1377 //
1378 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1379 // get switched to the one previously associated with the new tab pages.
1380 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1381 // have a committed Web UI in this case.
1382 //
1383 // This condition handles all of these cases:
1384 //
1385 // - First load in first tab: no committed nav entry + pending nav entry +
1386 // pending dom ui:
1387 // -> Use pending Web UI if any.
1388 //
1389 // - First load in second tab: no committed nav entry + pending nav entry +
1390 // no pending Web UI:
1391 // -> Use the committed Web UI if any.
1392 //
1393 // - Second navigation in any tab: committed nav entry + pending nav entry:
1394 // -> Use pending Web UI if any.
1395 //
1396 // - Normal state with no load: committed nav entry + no pending nav entry:
1397 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251398 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271399 (controller_.GetLastCommittedEntry() ||
1400 render_manager_.pending_web_ui()))
1401 return render_manager_.pending_web_ui();
1402 return render_manager_.web_ui();
1403}
1404
[email protected]b172aee2012-04-10 17:05:261405bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271406 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581407 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271408}
1409
[email protected]b172aee2012-04-10 17:05:261410bool WebContentsImpl::HasOpener() const {
[email protected]a0358d72012-03-09 14:06:501411 return has_opener_;
1412}
1413
[email protected]b172aee2012-04-10 17:05:261414void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321415 SkColor color) {
[email protected]da8543762012-03-20 08:52:201416 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1417 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1418}
1419
[email protected]b172aee2012-04-10 17:05:261420void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201421 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1422 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1423 if (delegate_)
1424 delegate_->DidEndColorChooser();
1425 color_chooser_ = NULL;
1426}
1427
[email protected]b172aee2012-04-10 17:05:261428bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471429 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271430 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221431 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231432 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411433 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271434}
1435
[email protected]b172aee2012-04-10 17:05:261436void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271437 if (delegate_)
1438 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211439}
1440
[email protected]b172aee2012-04-10 17:05:261441void WebContentsImpl::OnRegisterIntentService(const string16& action,
1442 const string16& type,
1443 const string16& href,
1444 const string16& title,
1445 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511446 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301447 this, action, type, href, title, disposition);
1448}
1449
[email protected]b172aee2012-04-10 17:05:261450void WebContentsImpl::OnWebIntentDispatch(
1451 const webkit_glue::WebIntentData& intent,
1452 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001453 WebIntentsDispatcherImpl* intents_dispatcher =
1454 new WebIntentsDispatcherImpl(this, intent, intent_id);
1455 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301456}
1457
[email protected]b172aee2012-04-10 17:05:261458void WebContentsImpl::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1459 bool is_main_frame,
1460 const GURL& opener_url,
1461 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281462 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181463 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451464 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581465 GetRenderViewHostImpl()->FilterURL(
1466 ChildProcessSecurityPolicyImpl::GetInstance(),
1467 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451468 false,
[email protected]9f76c1e2012-03-05 15:15:581469 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451470 GetRenderViewHostImpl()->FilterURL(
1471 ChildProcessSecurityPolicyImpl::GetInstance(),
1472 GetRenderProcessHost()->GetID(),
1473 true,
1474 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181475
[email protected]8093a542011-05-13 07:29:321476 RenderViewHost* rvh =
1477 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521478 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101479 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251480 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101481 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321482 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101483
[email protected]724159a2010-12-30 01:11:181484 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591485 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251486 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451487 ProvisionalChangeToMainFrameUrl(validated_url,
1488 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181489 }
1490}
1491
[email protected]b172aee2012-04-10 17:05:261492void WebContentsImpl::OnDidRedirectProvisionalLoad(int32 page_id,
1493 const GURL& opener_url,
1494 const GURL& source_url,
1495 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491496 // TODO(creis): Remove this method and have the pre-rendering code listen to
1497 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1498 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451499 GURL validated_source_url(source_url);
1500 GURL validated_target_url(target_url);
1501 GURL validated_opener_url(opener_url);
1502 GetRenderViewHostImpl()->FilterURL(
1503 ChildProcessSecurityPolicyImpl::GetInstance(),
1504 GetRenderProcessHost()->GetID(),
1505 false,
1506 &validated_source_url);
1507 GetRenderViewHostImpl()->FilterURL(
1508 ChildProcessSecurityPolicyImpl::GetInstance(),
1509 GetRenderProcessHost()->GetID(),
1510 false,
1511 &validated_target_url);
1512 GetRenderViewHostImpl()->FilterURL(
1513 ChildProcessSecurityPolicyImpl::GetInstance(),
1514 GetRenderProcessHost()->GetID(),
1515 true,
1516 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231517 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181518 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251519 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181520 else
1521 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451522 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181523 return;
[email protected]e7d50892011-01-19 21:47:381524
[email protected]4850a7f2011-03-08 23:36:591525 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451527 ProvisionalChangeToMainFrameUrl(validated_target_url,
1528 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181529}
1530
[email protected]b172aee2012-04-10 17:05:261531void WebContentsImpl::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581532 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1533 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1534 << ", error_code: " << params.error_code
1535 << ", error_description: " << params.error_description
1536 << ", is_main_frame: " << params.is_main_frame
1537 << ", showing_repost_interstitial: " <<
1538 params.showing_repost_interstitial
1539 << ", frame_id: " << params.frame_id;
1540 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581541 GetRenderViewHostImpl()->FilterURL(
1542 ChildProcessSecurityPolicyImpl::GetInstance(),
1543 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451544 false,
[email protected]9f76c1e2012-03-05 15:15:581545 &validated_url);
[email protected]724159a2010-12-30 01:11:181546
[email protected]d7b175e2011-10-11 15:31:581547 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181548 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1549 // This means that the interstitial won't be torn down properly, which is
1550 // bad. But if we have an interstitial, go back to another tab type, and
1551 // then load the same interstitial again, we could end up getting the first
1552 // interstitial's "failed" message (as a result of the cancel) when we're on
1553 // the second one.
1554 //
1555 // We can't tell this apart, so we think we're tearing down the current page
1556 // which will cause a crash later one. There is also some code in
1557 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1558 // out because of this problem.
1559 //
1560 // http://code.google.com/p/chromium/issues/detail?id=2855
1561 // Because this will not tear down the interstitial properly, if "back" is
1562 // back to another tab type, the interstitial will still be somewhat alive
1563 // in the previous tab type. If you navigate somewhere that activates the
1564 // tab with the interstitial again, you'll see a flash before the new load
1565 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271566 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181567 LOG(WARNING) << "Discarding message during interstitial.";
1568 return;
1569 }
1570
[email protected]02102f82011-06-13 20:37:021571 // Discard our pending entry if the load canceled (e.g. if we decided to
1572 // download the file instead of load it). We do not verify that the URL
1573 // being canceled matches the pending entry's URL because they will not
1574 // match if a redirect occurred (in which case we do not want to leave a
1575 // stale redirect URL showing). This means that we also cancel the pending
1576 // entry if the user started a new navigation. As a result, the navigation
1577 // controller may not remember that a load is in progress, but the
1578 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251579 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161580 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181581
[email protected]151a63d2011-12-20 22:32:521582 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181583 }
1584
[email protected]d8c660432011-12-22 20:51:251585 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581586 observers_,
1587 DidFailProvisionalLoad(params.frame_id,
1588 params.is_main_frame,
1589 validated_url,
1590 params.error_code,
1591 params.error_description));
[email protected]724159a2010-12-30 01:11:181592}
1593
[email protected]b172aee2012-04-10 17:05:261594void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181595 const GURL& url,
[email protected]70435962011-08-02 20:13:281596 const std::string& security_info,
1597 const std::string& http_method,
1598 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191599 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181600 cache.Increment();
1601
1602 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081603 int cert_id = 0;
1604 net::CertStatus cert_status = 0;
1605 int security_bits = -1;
1606 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511607 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1608 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301609 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161610 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181611
[email protected]ad50def52011-10-19 23:17:071612 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271613 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501614 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531615 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181616}
1617
[email protected]b172aee2012-04-10 17:05:261618void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381619 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181620 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201621 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181622}
1623
[email protected]b172aee2012-04-10 17:05:261624void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021625 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231626 LOG(INFO) << security_origin << " ran insecure content from "
1627 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381628 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411629 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1630 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181631 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411632 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201633 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181634}
1635
[email protected]b172aee2012-04-10 17:05:261636void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181637 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101639 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181640}
1641
[email protected]b172aee2012-04-10 17:05:261642void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311643 int64 frame_id,
1644 const GURL& validated_url,
1645 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251646 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311647 DidFinishLoad(frame_id, validated_url, is_main_frame));
1648}
1649
[email protected]b172aee2012-04-10 17:05:261650void WebContentsImpl::OnDidFailLoadWithError(
1651 int64 frame_id,
1652 const GURL& validated_url,
1653 bool is_main_frame,
1654 int error_code,
1655 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251656 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311657 DidFailLoad(frame_id, validated_url, is_main_frame,
1658 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181659}
1660
[email protected]b172aee2012-04-10 17:05:261661void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271662 content_restrictions_ = restrictions;
1663 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171664}
1665
[email protected]b172aee2012-04-10 17:05:261666void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261667 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231668 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251669 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261670 if (!entry)
1671 return;
1672 // Note that we don't call NavigationController::GotToOffset() as we don't
1673 // want to create a pending navigation entry (it might end up lingering
1674 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251675 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581676 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511677 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581678 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471679 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571680
1681 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1682 // it in now that we know. This allows us to find the entry when it commits.
1683 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231684 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331685 entry->set_site_instance(
1686 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571687 }
[email protected]216813952011-05-19 22:21:261688 }
1689}
1690
[email protected]b172aee2012-04-10 17:05:261691void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1692 int maximum_percent,
1693 bool remember) {
[email protected]216813952011-05-19 22:21:261694 minimum_zoom_percent_ = minimum_percent;
1695 maximum_zoom_percent_ = maximum_percent;
1696 temporary_zoom_settings_ = !remember;
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481700 download_stats::RecordDownloadSource(
1701 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261702 // Check if the URL to save matches the URL of the main frame. Since this
1703 // message originates from Pepper plugins, it may not be the case if the
1704 // plugin is an embedded element.
1705 GURL main_frame_url = GetURL();
1706 if (!main_frame_url.is_valid())
1707 return;
1708 bool is_main_frame = (url == main_frame_url);
1709 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271710}
1711
[email protected]b172aee2012-04-10 17:05:261712void WebContentsImpl::OnEnumerateDirectory(int request_id,
1713 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591714 ChildProcessSecurityPolicyImpl* policy =
1715 ChildProcessSecurityPolicyImpl::GetInstance();
1716 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1717 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211718}
1719
[email protected]b172aee2012-04-10 17:05:261720void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511721 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201722}
1723
[email protected]b172aee2012-04-10 17:05:261724void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1725 const GURL& url,
1726 const string16& title) {
[email protected]b9535422012-02-09 01:47:591727 ChildProcessSecurityPolicyImpl* policy =
1728 ChildProcessSecurityPolicyImpl::GetInstance();
1729 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1730 return;
[email protected]6934a702011-12-20 00:04:511731 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201732}
1733
[email protected]b172aee2012-04-10 17:05:261734void WebContentsImpl::OnFindReply(int request_id,
1735 int number_of_matches,
1736 const gfx::Rect& selection_rect,
1737 int active_match_ordinal,
1738 bool final_update) {
[email protected]6934a702011-12-20 00:04:511739 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1740 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001741 // Send a notification to the renderer that we are ready to receive more
1742 // results from the scoping effort of the Find operation. The FindInPage
1743 // scoping is asynchronous and periodically sends results back up to the
1744 // browser using IPC. In an effort to not spam the browser we have the
1745 // browser send an ACK for each FindReply message and have the renderer
1746 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581747 GetRenderViewHostImpl()->Send(
1748 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161749}
1750
[email protected]b172aee2012-04-10 17:05:261751void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441752 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1753 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451754}
1755
[email protected]b172aee2012-04-10 17:05:261756void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1757 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101758 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251759 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101760 AppCacheAccessed(manifest_url, blocked_by_policy));
1761}
1762
[email protected]b172aee2012-04-10 17:05:261763void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321764 SkColor color) {
[email protected]da8543762012-03-20 08:52:201765 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1766}
1767
[email protected]b172aee2012-04-10 17:05:261768void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201769 if (color_chooser_ &&
1770 color_chooser_id == color_chooser_->identifier())
1771 color_chooser_->End();
1772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321775 SkColor color) {
[email protected]da8543762012-03-20 08:52:201776 if (color_chooser_ &&
1777 color_chooser_id == color_chooser_->identifier())
1778 color_chooser_->SetSelectedColor(color);
1779}
1780
[email protected]9f2a9d72012-04-16 16:02:221781void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1782 const FilePath& path,
1783 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441784 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1785 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291786}
1787
[email protected]d0759f492012-04-19 22:50:501788// This exists for render views that don't have a WebUI, but do have WebUI
1789// bindings enabled.
1790void WebContentsImpl::OnWebUISend(const GURL& source_url,
1791 const std::string& name,
1792 const base::ListValue& args) {
1793 if (delegate_)
1794 delegate_->WebUISend(this, source_url, name, args);
1795}
1796
[email protected]96d185d2009-04-24 03:28:541797// Notifies the RenderWidgetHost instance about the fact that the page is
1798// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261799void WebContentsImpl::SetIsLoading(bool is_loading,
1800 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541801 if (is_loading == is_loading_)
1802 return;
1803
1804 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211805 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541806 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561807 upload_size_ = 0;
1808 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541809 }
1810
1811 render_manager_.SetIsLoading(is_loading);
1812
1813 is_loading_ = is_loading;
1814 waiting_for_response_ = is_loading;
1815
[email protected]6ebdc9b2010-09-27 16:55:571816 if (delegate_)
1817 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461818 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541819
[email protected]432115822011-07-10 15:52:271820 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1821 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071822 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541823 if (details)
[email protected]6c2381d2011-10-19 02:52:531824 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071825 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501826 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541827 det);
1828}
1829
[email protected]b172aee2012-04-10 17:05:261830void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131831 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321832 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561833 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381834 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441835 // that opened the window, as long as both renderers have the same
1836 // privileges.
[email protected]1fd1a502011-03-30 16:55:561837 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561838 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581839 // web_ui might be NULL if the URL refers to a non-existent extension.
1840 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401841 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521842 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441843 }
1844 }
[email protected]1fd1a502011-03-30 16:55:561845 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441846 }
1847
[email protected]4e697b042011-07-08 06:44:561848 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321849 // Clear the status bubble. This is a workaround for a bug where WebKit
1850 // doesn't let us know that the cursor left an element during a
1851 // transition (this is also why the mouse cursor remains as a hand after
1852 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1853 // clear the bubble when a user navigates to a named anchor in the same
1854 // page.
[email protected]36fc0392011-12-25 03:59:511855 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321856 }
1857
[email protected]a6e82fc2010-02-24 22:28:141858 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471859 // Once the main frame is navigated, we're no longer considered to have
1860 // displayed insecure content.
1861 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171862 }
[email protected]ce5c4502009-05-06 16:46:111863
[email protected]3c9e1872010-11-18 16:17:491864 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251865 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041866 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321867}
1868
[email protected]b172aee2012-04-10 17:05:261869void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321870 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131871 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321872 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061873 // If we navigate off the page, reset JavaScript state. This does nothing
1874 // to prevent a malicious script from spamming messages, since the script
1875 // could just reload the page to stop blocking.
1876 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551877 dialog_creator_->ResetJavaScriptState(this);
1878 dialog_creator_ = NULL;
1879 }
[email protected]420ae012009-04-24 05:16:321880
[email protected]3c9e1872010-11-18 16:17:491881 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251882 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041883 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321884}
1885
[email protected]b172aee2012-04-10 17:05:261886void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461887 // If we are creating a RVH for a restored controller, then we need to make
1888 // sure the RenderView starts with a next_page_id_ larger than the number
1889 // of restored entries. This must be called before the RenderView starts
1890 // navigating (to avoid a race between the browser updating max_page_id and
1891 // the renderer updating next_page_id_). Because of this, we only call this
1892 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561893 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581894 if (max_restored_page_id >
1895 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1896 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1897 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321898}
1899
[email protected]b172aee2012-04-10 17:05:261900bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1901 const string16& title) {
[email protected]420ae012009-04-24 05:16:321902 // For file URLs without a title, use the pathname instead. In the case of a
1903 // synthesized title, we don't want the update to count toward the "one set
1904 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511905 string16 final_title;
[email protected]420ae012009-04-24 05:16:321906 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511907 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1908 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321909 explicit_set = false; // Don't count synthetic titles toward the set limit.
1910 } else {
[email protected]acafd272011-07-26 17:35:571911 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321912 explicit_set = true;
1913 }
1914
[email protected]987fc3a2011-05-26 14:18:091915 // If a page is created via window.open and never navigated,
1916 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551917 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091918 if (entry) {
[email protected]36fc0392011-12-25 03:59:511919 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091920 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321921
[email protected]36fc0392011-12-25 03:59:511922 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091923 } else {
1924 if (page_title_when_no_navigation_entry_ == final_title)
1925 return false; // Nothing changed, don't bother.
1926
1927 page_title_when_no_navigation_entry_ = final_title;
1928 }
[email protected]420ae012009-04-24 05:16:321929
[email protected]420ae012009-04-24 05:16:321930 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231931 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321932
[email protected]2bb171882012-03-07 02:09:461933 std::pair<content::NavigationEntry*, bool> details =
1934 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141935
[email protected]ad50def52011-10-19 23:17:071936 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441937 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1938 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461939 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041940
[email protected]420ae012009-04-24 05:16:321941 return true;
1942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321945 // After sending out a swap notification, we need to send a disconnect
1946 // notification so that clients that pick up a pointer to |this| can NULL the
1947 // pointer. See Bug 1230284.
1948 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071949 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201950 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1951 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071952 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321953}
1954
[email protected]b172aee2012-04-10 17:05:261955void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:321956 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071957 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121958 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1959 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071960 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321961}
1962
[email protected]b172aee2012-04-10 17:05:261963void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:321964 if (!notify_disconnection_)
1965 return;
1966
1967 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071968 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321969 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1970 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071971 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321972}
1973
[email protected]b172aee2012-04-10 17:05:261974RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321975 return view_.get();
1976}
1977
[email protected]8d3347f2009-07-09 22:00:211978RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:261979WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:211980 return &render_manager_;
1981}
1982
[email protected]b172aee2012-04-10 17:05:261983content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371984 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461985 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511986}
1987
[email protected]b172aee2012-04-10 17:05:261988WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:171989 return this;
1990}
1991
[email protected]b172aee2012-04-10 17:05:261992content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431993 return view_type_;
[email protected]7b291f92009-08-14 05:43:531994}
1995
[email protected]b172aee2012-04-10 17:05:261996gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:171997 if (delegate_)
1998 return delegate_->GetRootWindowResizerRect();
1999 return gfx::Rect();
2000}
2001
[email protected]b172aee2012-04-10 17:05:262002void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:072003 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272004 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322005 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532006 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232007 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322008 if (!entry)
2009 return;
2010
2011 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352012 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562013 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582014 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322015
2016 if (entry->IsViewSourceMode()) {
2017 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582018 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2019 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322020 }
[email protected]0666aef2009-05-13 19:48:082021
[email protected]d487beefe2011-12-21 05:41:212022 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262023
2024 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252025 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322026}
2027
[email protected]b172aee2012-04-10 17:05:262028void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522029 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322030 // Don't notify the world, since this came from a renderer in the
2031 // background.
2032 return;
2033 }
2034
2035 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312036 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232037 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302038
2039 // Restore the focus to the tab (otherwise the focus will be on the top
2040 // window).
[email protected]484ae5912010-09-29 19:16:142041 if (was_crashed && !FocusLocationBarByDefault() &&
2042 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302043 Focus();
[email protected]484ae5912010-09-29 19:16:142044 }
[email protected]32ded2212011-11-10 18:51:432045
[email protected]d8c660432011-12-22 20:51:252046 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322047}
2048
[email protected]b172aee2012-04-10 17:05:262049void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2050 base::TerminationStatus status,
2051 int error_code) {
[email protected]151a63d2011-12-20 22:32:522052 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322053 // The pending page's RenderViewHost is gone.
2054 return;
2055 }
2056
2057 SetIsLoading(false, NULL);
2058 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232059 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312060 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322061
[email protected]d8c660432011-12-22 20:51:252062 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272063 observers_,
[email protected]be1f56ab2011-12-22 06:55:312064 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322065}
2066
[email protected]b172aee2012-04-10 17:05:262067void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482068 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252069 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062070}
2071
[email protected]b172aee2012-04-10 17:05:262072void WebContentsImpl::DidNavigate(
2073 RenderViewHost* rvh,
2074 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582075 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322076 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372077
[email protected]434f69f2012-02-06 21:56:522078 // Update the site of the SiteInstance if it doesn't have one yet, unless
2079 // this is for about:blank. In that case, the SiteInstance can still be
2080 // considered unused until a navigation to a real page.
2081 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2082 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332083 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522084 }
[email protected]420ae012009-04-24 05:16:322085
2086 // Need to update MIME type here because it's referred to in
2087 // UpdateNavigationCommands() called by RendererDidNavigate() to
2088 // determine whether or not to enable the encoding menu.
2089 // It's updated only for the main frame. For a subframe,
2090 // RenderView::UpdateURL does not set params.contents_mime_type.
2091 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2092 // TODO(jungshik): Add a test for the encoding menu to avoid
2093 // regressing it again.
[email protected]2905f742011-10-13 03:51:582094 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322095 contents_mime_type_ = params.contents_mime_type;
2096
[email protected]8286f51a2011-05-31 17:39:132097 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002098 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392099
[email protected]a9c0bfe2010-09-17 08:35:222100 // Send notification about committed provisional loads. This notification is
2101 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2102 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082103 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072104 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2105 // that is not recorded in the navigation history. For the purpose of
2106 // tracking navigation events, we treat this event as a sub frame navigation
2107 // event.
2108 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582109 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222110 // Whether or not a page transition was triggered by going backward or
2111 // forward in the history is only stored in the navigation controller's
2112 // entry list.
2113 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512114 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582115 content::PAGE_TRANSITION_FORWARD_BACK)) {
2116 transition_type = content::PageTransitionFromInt(
2117 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222118 }
[email protected]0d60f0192011-04-14 12:40:102119 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252120 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102121 DidCommitProvisionalLoadForFrame(params.frame_id,
2122 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222123 }
2124
[email protected]76543b92009-08-31 17:27:452125 if (!did_navigate)
2126 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322127
2128 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2129 // for the appropriate notification (best) or you can add it to
2130 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2131 // necessary, please).
2132
2133 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002134 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322135 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512136 if (delegate_)
2137 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002138 }
[email protected]420ae012009-04-24 05:16:322139 DidNavigateAnyFramePostCommit(rvh, details, params);
2140}
2141
[email protected]b172aee2012-04-10 17:05:262142void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2143 int32 page_id,
2144 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152145 // Ensure that this state update comes from either the active RVH or one of
2146 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522147 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322148
2149 // We must be prepared to handle state updates for any page, these occur
2150 // when the user is scrolling and entering form data, as well as when we're
2151 // leaving a page, in which case our state may have already been moved to
2152 // the next page. The navigation controller will look up the appropriate
2153 // NavigationEntry and update it when it is notified via the delegate.
2154
2155 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582156 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322157 if (entry_index < 0)
2158 return;
[email protected]10f417c52011-12-28 21:04:232159 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322160
[email protected]36fc0392011-12-25 03:59:512161 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322162 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512163 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322164 controller_.NotifyEntryChanged(entry, entry_index);
2165}
2166
[email protected]b172aee2012-04-10 17:05:262167void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2168 int32 page_id,
2169 const string16& title,
2170 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322171 // If we have a title, that's a pretty good indication that we've started
2172 // getting useful data.
2173 SetNotWaitingForResponse();
2174
[email protected]73eb2602012-02-09 19:50:552175 // Try to find the navigation entry, which might not be the current one.
2176 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232177 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582178 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092179
[email protected]73eb2602012-02-09 19:50:552180 // We can handle title updates when we don't have an entry in
2181 // UpdateTitleForEntry, but only if the update is from the current RVH.
2182 if (!entry && rvh != GetRenderViewHost())
2183 return;
2184
[email protected]a49e10b2011-08-01 23:57:462185 // TODO(evan): make use of title_direction.
2186 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092187 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322188 return;
2189
2190 // Broadcast notifications when the UI should be updated.
2191 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462192 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2196 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312197 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322198}
2199
[email protected]b172aee2012-04-10 17:05:262200void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512201 if (delegate_)
2202 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322203}
2204
[email protected]b172aee2012-04-10 17:05:262205void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292206 // The UI may be in an event-tracking loop, such as between the
2207 // mouse-down and mouse-up in text selection or a button click.
2208 // Defer the close until after tracking is complete, so that we
2209 // don't free objects out from under the UI.
2210 // TODO(shess): This could probably be integrated with the
2211 // IsDoingDrag() test below. Punting for now because I need more
2212 // research to understand how this impacts platforms other than Mac.
2213 // TODO(shess): This could get more fine-grained. For instance,
2214 // closing a tab in another window while selecting text in the
2215 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212216 if (GetView()->IsEventTracking()) {
2217 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292218 return;
2219 }
2220
[email protected]24a4d1062009-07-10 23:10:422221 // If we close the tab while we're in the middle of a drag, we'll crash.
2222 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212223 if (GetView()->IsDoingDrag()) {
2224 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422225 return;
2226 }
2227
[email protected]420ae012009-04-24 05:16:322228 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522229 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512230 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522234 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512235 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512239 if (delegate_ && delegate_->IsPopupOrPanel(this))
2240 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322244 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492245
[email protected]82114f52012-03-20 22:53:412246 if (delegate_ && content_restrictions_)
2247 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492248
2249 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252250 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322254 scoped_ptr<LoadNotificationDetails> details;
2255
[email protected]10f417c52011-12-28 21:04:232256 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322257 // An entry may not exist for a stop when loading an initial blank page or
2258 // if an iframe injected by script into a blank page finishes loading.
2259 if (entry) {
[email protected]420ae012009-04-24 05:16:322260 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2261
2262 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512263 entry->GetVirtualURL(),
2264 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322265 elapsed,
2266 &controller_,
2267 controller_.GetCurrentEntryIndex()));
2268 }
2269
[email protected]420ae012009-04-24 05:16:322270 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492271
2272 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252273 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322274}
2275
[email protected]b172aee2012-04-10 17:05:262276void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162277 controller_.DiscardNonCommittedEntries();
2278
2279 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462280 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162281}
2282
[email protected]b172aee2012-04-10 17:05:262283void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512284 if (delegate_)
2285 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402286}
2287
[email protected]87717d0e2012-04-26 02:58:432288void WebContentsImpl::DocumentAvailableInMainFrame(
2289 RenderViewHost* render_view_host) {
2290 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2291 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102292}
2293
[email protected]b172aee2012-04-10 17:05:262294void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082295 RenderViewHost* render_view_host,
2296 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072297 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272298 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322299 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532300 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::RequestOpenURL(const GURL& url,
2304 const content::Referrer& referrer,
2305 WindowOpenDisposition disposition,
2306 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482307 // Delegate to RequestTransferURL because this is just the generic
2308 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582309 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482310 GlobalRequestID());
2311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::RequestTransferURL(
2314 const GURL& url,
2315 const content::Referrer& referrer,
2316 WindowOpenDisposition disposition,
2317 int64 source_frame_id,
2318 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202319 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582320 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582321 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352322 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322323 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2324 // generated suggestions).
2325 //
[email protected]e0112912011-02-02 22:54:352326 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162327 // want web sites to see a referrer of "chrome://blah" (and some
2328 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322329 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432330 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222331 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482332 false /* is_renderer_initiated */);
2333 params.transferred_global_request_id = old_request_id;
2334 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222335 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322336 } else {
[email protected]6bf6a6b52012-02-03 15:41:432337 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482338 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2339 params.transferred_global_request_id = old_request_id;
2340 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582341 }
2342 if (new_contents) {
2343 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252344 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582345 DidOpenRequestedURL(new_contents,
2346 url,
2347 referrer,
2348 disposition,
2349 transition_type,
2350 source_frame_id));
[email protected]420ae012009-04-24 05:16:322351 }
2352}
2353
[email protected]b172aee2012-04-10 17:05:262354void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342355 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412356 const string16& message,
2357 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322358 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472359 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322360 IPC::Message* reply_msg,
2361 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072362 // Suppress JavaScript dialogs when requested. Also suppress messages when
2363 // showing an interstitial as it's shown over the previous page and we don't
2364 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502365 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582366 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272367 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072368 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522369 delegate_->ShouldSuppressDialogs() ||
2370 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322371
2372 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432373 std::string accept_lang = content::GetContentClient()->browser()->
2374 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552375 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522376 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432377 this,
2378 frame_url.GetOrigin(),
2379 accept_lang,
2380 javascript_message_type,
2381 message,
[email protected]51da7e32012-01-30 19:24:522382 default_prompt,
[email protected]b172aee2012-04-10 17:05:262383 base::Bind(&WebContentsImpl::OnDialogClosed,
2384 base::Unretained(this),
2385 rvh,
2386 reply_msg),
[email protected]51da7e32012-01-30 19:24:522387 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322388 }
[email protected]3ab9cb82011-06-03 18:02:072389
2390 if (suppress_this_message) {
2391 // If we are suppressing messages, just reply as if the user immediately
2392 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342393 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072394 }
2395
2396 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322397}
2398
[email protected]b172aee2012-04-10 17:05:262399void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2400 const string16& message,
2401 bool is_reload,
2402 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582403 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512404 if (delegate_)
2405 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072406
2407 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582408 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072409 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522410 delegate_->ShouldSuppressDialogs() ||
2411 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152412 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342413 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582414 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502415 return;
2416 }
[email protected]3ab9cb82011-06-03 18:02:072417
[email protected]7ab1e7d62009-10-14 23:32:012418 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552419 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522420 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322421 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262422 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522423 reply_msg));
[email protected]420ae012009-04-24 05:16:322424}
2425
[email protected]b172aee2012-04-10 17:05:262426WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332427 // We want to base the page config off of the real URL, rather than the
2428 // display URL.
2429 GURL url = controller_.GetActiveEntry()
2430 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2431 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322432}
2433
[email protected]b172aee2012-04-10 17:05:262434void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272435 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252436 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222437
[email protected]ea114722012-03-12 01:11:252438 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172439 if (rdh) // NULL in unittests.
2440 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252441}
2442
[email protected]b172aee2012-04-10 17:05:262443void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442444 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252445 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442446}
2447
[email protected]b172aee2012-04-10 17:05:262448void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2449 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152450 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522451 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152452 return;
2453
[email protected]9f76c1e2012-03-05 15:15:582454 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2455
[email protected]e5fc1632011-08-08 07:51:532456 // Ignore renderer unresponsive event if debugger is attached to the tab
2457 // since the event may be a result of the renderer sitting on a breakpoint.
2458 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442459 DevToolsAgentHost* agent =
2460 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2461 if (agent &&
2462 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532463 return;
2464
[email protected]420ae012009-04-24 05:16:322465 if (is_during_unload) {
2466 // Hang occurred while firing the beforeunload/unload handler.
2467 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582468 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322469
2470 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2471 return;
2472
2473 // If the tab hangs in the beforeunload/unload handler there's really
2474 // nothing we can do to recover. Pretend the unload listeners have
2475 // all fired and close the tab. If the hang is in the beforeunload handler
2476 // then the user will not have the option of cancelling the close.
2477 Close(rvh);
2478 return;
2479 }
2480
[email protected]9f76c1e2012-03-05 15:15:582481 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472482 return;
2483
[email protected]6934a702011-12-20 00:04:512484 if (delegate_)
2485 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322486}
2487
[email protected]b172aee2012-04-10 17:05:262488void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512489 if (delegate_)
2490 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322491}
2492
[email protected]b172aee2012-04-10 17:05:262493void WebContentsImpl::LoadStateChanged(
2494 const GURL& url,
2495 const net::LoadStateWithParam& load_state,
2496 uint64 upload_position,
2497 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322498 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562499 upload_position_ = upload_position;
2500 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502501 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202502 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302503 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212504 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322505 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462506 if (IsLoading()) {
2507 NotifyNavigationStateChanged(
2508 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2509 }
[email protected]420ae012009-04-24 05:16:322510}
2511
[email protected]b172aee2012-04-10 17:05:262512void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512513 if (delegate_)
2514 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252515}
2516
[email protected]b172aee2012-04-10 17:05:262517void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322518 bool proceed,
2519 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512520 if (delegate_)
2521 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322522}
2523
[email protected]b172aee2012-04-10 17:05:262524void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542525 RenderViewHost* render_view_host) {
2526 DidStartLoading();
2527}
2528
[email protected]b172aee2012-04-10 17:05:262529void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542530 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232531 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2532 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542533}
2534
[email protected]b172aee2012-04-10 17:05:262535void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102536 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262537 gfx::Size size = view_->GetContainerSize();
2538 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2539 // here during container initialization and normal window size will be set
2540 // later. In case of tab duplication this resizing to 0x0 prevents setting
2541 // normal size later so just ignore it.
2542 if (!size.IsEmpty())
2543 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322544}
2545
[email protected]b172aee2012-04-10 17:05:262546void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542547 NotifySwapped();
2548}
2549
[email protected]b172aee2012-04-10 17:05:262550NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202551 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542552}
2553
[email protected]b172aee2012-04-10 17:05:262554WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562555 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322556}
2557
[email protected]10f417c52011-12-28 21:04:232558NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262559 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322560 return controller_.GetLastCommittedEntry();
2561}
2562
[email protected]b172aee2012-04-10 17:05:262563bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]420ae012009-04-24 05:16:322564 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442565 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322566 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522567
[email protected]420ae012009-04-24 05:16:322568 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442569 if (rwh_view)
2570 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322571
[email protected]74ce1ad2011-12-16 21:51:462572 // Make sure we use the correct starting page_id in the new RenderView.
2573 UpdateMaxPageIDIfNecessary(render_view_host);
2574 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582575 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462576
[email protected]9f76c1e2012-03-05 15:15:582577 if (!static_cast<RenderViewHostImpl*>(
2578 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522579 return false;
2580
[email protected]e60c0232011-11-11 19:56:352581#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502582 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2583 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442584 if (rwh_view) {
2585 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2586 render_widget_host->WasResized();
2587 }
[email protected]f8233cc2011-05-31 20:24:502588#endif
2589
[email protected]420ae012009-04-24 05:16:322590 return true;
2591}
2592
[email protected]b172aee2012-04-10 17:05:262593void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2594 IPC::Message* reply_msg,
2595 bool success,
2596 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542597 if (is_showing_before_unload_dialog_ && !success) {
2598 // If a beforeunload dialog is canceled, we need to stop the throbber from
2599 // spinning, since we forced it to start spinning in Navigate.
2600 DidStopLoading();
2601
[email protected]3bbacc5b2012-04-17 17:46:152602 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542603 }
2604 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582605 static_cast<RenderViewHostImpl*>(
2606 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122610 encoding_ = content::GetContentClient()->browser()->
2611 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102612}
[email protected]f45d2a72010-03-08 23:28:352613
[email protected]b172aee2012-04-10 17:05:262614void WebContentsImpl::SaveURL(const GURL& url,
2615 const GURL& referrer,
2616 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142617 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2618 if (!dlm)
2619 return;
2620 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262621 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142622 const NavigationEntry* entry = controller_.GetActiveEntry();
2623 if (entry)
2624 post_id = entry->GetPostID();
2625 }
[email protected]29a5ffc82012-03-13 19:35:582626 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142627 save_info.prompt_for_save_location = true;
2628 dlm->DownloadUrl(url,
2629 referrer,
2630 "",
2631 true, // prefer_cache
2632 post_id,
2633 save_info,
[email protected]89e6aa72012-03-12 22:51:332634 this,
2635 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142636}
2637
[email protected]b172aee2012-04-10 17:05:262638void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212639 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442640 // Can be NULL during tests.
2641 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212642 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362643}
[email protected]9f76c1e2012-03-05 15:15:582644
[email protected]b172aee2012-04-10 17:05:262645RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582646 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2647}