blob: 1bc75039c4c3fdea9293816365ae3f65efee2229 [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]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
[email protected]2bb171882012-03-07 02:09:468#include <utility>
[email protected]b75b8292010-10-01 07:28:259
[email protected]36fb2c7c2011-04-04 15:49:0810#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1812#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5413#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0914#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3715#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.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]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1221#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1622#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3223#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5424#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0525#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0026#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0127#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3229#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2530#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]567812d2011-02-24 17:40:5031#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1333#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2334#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4435#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5840#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1141#include "content/public/browser/browser_context.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]7f6f44c2011-12-14 13:23:3850#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4251#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2552#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1053#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5054#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2155#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4856#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1857#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5458#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0359#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1660#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2961#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5462#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3463#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3764#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3865#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2466#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3167#include "webkit/glue/webpreferences.h"
68
69#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1270#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3171#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0072
[email protected]420ae012009-04-24 05:16:3273// Cross-Site Navigations
74//
75// If a TabContents is told to navigate to a different web site (as determined
76// by SiteInstance), it will replace its current RenderViewHost with a new
77// RenderViewHost dedicated to the new SiteInstance. This works as follows:
78//
79// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4680// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3281// - The pending RVH is "suspended," so that no navigation messages are sent to
82// its renderer until the onbeforeunload JavaScript handler has a chance to
83// run in the current RVH.
84// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
85// that it has a pending cross-site request. ResourceDispatcherHost will
86// check for this when the response arrives.
87// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4688// cancel all the pending logic. Otherwise we allow the pending RVH to send
89// the navigation request to its renderer.
90// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
91// main resource load on the pending RVH. It checks CrossSiteRequestManager
92// to see that it is a cross-site request, and installs a
93// CrossSiteResourceHandler.
94// - When RDH receives a response, the BufferedResourceHandler determines
95// whether it is a download. If so, it sends a message to the new renderer
96// causing it to cancel the request, and the download proceeds. For now, the
97// pending RVH remains until the next DidNavigate event for this TabContents.
98// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3299// - After RDH receives a response and determines that it is safe and not a
100// download, it pauses the response to first run the old page's onunload
101// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15102// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32103// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15104// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32105// the ResourceDispatcherHost, who unpauses the response. Data is then sent
106// to the pending RVH.
107// - The pending renderer sends a FrameNavigate message that invokes the
108// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46109// pending RVH.
[email protected]992db4c2011-05-12 15:37:15110// - The previous renderer is kept swapped out in RenderViewHostManager in case
111// the user goes back. The process only stays live if another tab is using
112// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32113
[email protected]0e12d7d2011-12-01 16:21:44114using content::DevToolsAgentHost;
115using content::DevToolsAgentHostRegistry;
116using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17117using content::DownloadItem;
118using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20119using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56120using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13121using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27122using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50123using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23124using content::NavigationEntry;
125using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20126using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11127using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57128using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27129using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11130using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58131using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04132using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25133using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43134using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33135using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17136using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38137using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09138using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25139using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56140using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22141using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50142using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44143
[email protected]420ae012009-04-24 05:16:32144namespace {
145
146// Amount of time we wait between when a key event is received and the renderer
147// is queried for its state and pushed to the NavigationEntry.
148const int kQueryStateDelay = 5000;
149
[email protected]6ebdc9b2010-09-27 16:55:57150const int kSyncWaitDelay = 40;
151
[email protected]ca406032011-07-19 21:53:05152static const char kDotGoogleDotCom[] = ".google.com";
153
[email protected]420ae012009-04-24 05:16:32154#if defined(OS_WIN)
155
156BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
157 // Note: erase is required to properly paint some widgets borders. This can
158 // be seen with textfields.
159 InvalidateRect(hwnd, NULL, TRUE);
160 return TRUE;
161}
162#endif
163
[email protected]2c5569662011-03-22 20:45:02164ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23165 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50166 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16167 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47168 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02169 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47170 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02171 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47172 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16173 break; // Fall through to rest of function.
174 }
[email protected]5e369672009-11-03 23:48:30175
[email protected]59246c572012-02-10 13:32:13176 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
177 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23178 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13179 browser_context->DidLastSessionExitCleanly()) {
180 if (entry.GetHasPostData())
181 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02182 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13183 }
[email protected]5e369672009-11-03 23:48:30184
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30186}
187
[email protected]10f417c52011-12-28 21:04:23188void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47189 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42190 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50191 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16192 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51193 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54194 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55195 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
196 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51197 params->url = entry.GetURL();
198 params->referrer = entry.GetReferrer();
199 params->transition = entry.GetTransitionType();
200 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00201 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55202 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34203 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47204 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48205 params->transferred_request_child_id =
206 entry.transferred_global_request_id().child_id;
207 params->transferred_request_request_id =
208 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47209
210 if (delegate)
211 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34212}
213
[email protected]420ae012009-04-24 05:16:32214} // namespace
215
[email protected]a81343d232011-12-27 07:39:20216namespace content {
217
218WebContents* WebContents::Create(
219 BrowserContext* browser_context,
220 SiteInstance* site_instance,
221 int routing_id,
222 const WebContents* base_tab_contents,
223 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43224 return new TabContents(
225 browser_context,
226 site_instance,
227 routing_id,
228 static_cast<const TabContents*>(base_tab_contents),
229 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20230}
231}
[email protected]f4f50ef2011-01-21 19:01:19232
233// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32234
[email protected]3d7474ff2011-07-27 17:47:37235TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32236 SiteInstance* site_instance,
237 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07238 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43239 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42240 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07241 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37242 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13243 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10244 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22245 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34246 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23247 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
248 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34249 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21250 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56251 upload_size_(0),
252 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47253 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57254 capturing_contents_(false),
255 is_being_destroyed_(false),
256 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55257 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57258#if defined(OS_WIN)
259 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
260#endif
[email protected]7ab1e7d62009-10-14 23:32:01261 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56262 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38263 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25264 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01265 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25266 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01267 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00268 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43269 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50270 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
271 has_opener_(false) {
[email protected]3d7474ff2011-07-27 17:47:37272 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32273
[email protected]34ac70502009-09-25 17:07:23274 // We have the initial size of the view be based on the size of the passed in
275 // tab contents (normally a tab from the same window).
276 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21277 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00278
279#if defined(ENABLE_JAVA_BRIDGE)
280 java_bridge_dispatcher_host_manager_.reset(
281 new JavaBridgeDispatcherHostManager(this));
282#endif
[email protected]332af7732009-03-11 13:21:35283}
initial.commit09911bf2008-07-26 23:55:29284
285TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32286 is_being_destroyed_ = true;
287
[email protected]3ab9cb82011-06-03 18:02:07288 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55289 if (dialog_creator_)
290 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07291
[email protected]420ae012009-04-24 05:16:32292 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32293
[email protected]420ae012009-04-24 05:16:32294 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07295 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09296 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
297 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07298 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32299
300 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07301#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32302 // If we still have a window handle, destroy it. GetNativeView can return
303 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42304 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52305 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58306 if (host && host->GetView())
307 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42308 }
[email protected]420ae012009-04-24 05:16:32309#endif
[email protected]7ab1e7d62009-10-14 23:32:01310
311 // OnCloseStarted isn't called in unit tests.
312 if (!tab_close_start_time_.is_null()) {
313 UMA_HISTOGRAM_TIMES("Tab.Close",
314 base::TimeTicks::Now() - tab_close_start_time_);
315 }
[email protected]b5a1d11c2011-02-17 03:09:42316
[email protected]d8c660432011-12-22 20:51:25317 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08318
[email protected]6934a702011-12-20 00:04:51319 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42320}
321
[email protected]64d69de42012-02-06 00:19:54322WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
323 const GURL& url) {
324 WebPreferences prefs;
325
326 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
327
328 prefs.developer_extras_enabled = true;
329 prefs.javascript_enabled =
330 !command_line.HasSwitch(switches::kDisableJavaScript);
331 prefs.web_security_enabled =
332 !command_line.HasSwitch(switches::kDisableWebSecurity);
333 prefs.plugins_enabled =
334 !command_line.HasSwitch(switches::kDisablePlugins);
335 prefs.java_enabled =
336 !command_line.HasSwitch(switches::kDisableJava);
337
338 prefs.uses_page_cache =
339 command_line.HasSwitch(switches::kEnableFastback);
340 prefs.remote_fonts_enabled =
341 !command_line.HasSwitch(switches::kDisableRemoteFonts);
342 prefs.xss_auditor_enabled =
343 !command_line.HasSwitch(switches::kDisableXSSAuditor);
344 prefs.application_cache_enabled =
345 !command_line.HasSwitch(switches::kDisableApplicationCache);
346
347 prefs.local_storage_enabled =
348 !command_line.HasSwitch(switches::kDisableLocalStorage);
349 prefs.databases_enabled =
350 !command_line.HasSwitch(switches::kDisableDatabases);
351 prefs.webaudio_enabled =
352 !command_line.HasSwitch(switches::kDisableWebAudio);
353
354 prefs.experimental_webgl_enabled =
355 GpuProcessHost::gpu_enabled() &&
356 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
357 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
358
359 prefs.gl_multisampling_enabled =
360 !command_line.HasSwitch(switches::kDisableGLMultisampling);
361 prefs.privileged_webgl_extensions_enabled =
362 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
363 prefs.site_specific_quirks_enabled =
364 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
365 prefs.allow_file_access_from_file_urls =
366 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
367 prefs.show_composited_layer_borders =
368 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
369 prefs.show_composited_layer_tree =
370 command_line.HasSwitch(switches::kShowCompositedLayerTree);
371 prefs.show_fps_counter =
372 command_line.HasSwitch(switches::kShowFPSCounter);
373 prefs.accelerated_compositing_enabled =
374 GpuProcessHost::gpu_enabled() &&
375 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
376 prefs.threaded_compositing_enabled =
377 command_line.HasSwitch(switches::kEnableThreadedCompositing);
378 prefs.force_compositing_mode =
379 command_line.HasSwitch(switches::kForceCompositingMode);
380 prefs.fixed_position_compositing_enabled =
381 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
382 prefs.accelerated_2d_canvas_enabled =
383 GpuProcessHost::gpu_enabled() &&
384 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58385 prefs.deferred_2d_canvas_enabled =
386 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36387 prefs.threaded_animation_enabled =
388 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54389 prefs.accelerated_painting_enabled =
390 GpuProcessHost::gpu_enabled() &&
391 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
392 prefs.accelerated_filters_enabled =
393 GpuProcessHost::gpu_enabled() &&
394 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
395 prefs.accelerated_layers_enabled =
396 prefs.accelerated_animation_enabled =
397 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
398 prefs.composite_to_texture_enabled =
399 command_line.HasSwitch(switches::kEnableCompositeToTexture);
400 prefs.accelerated_plugins_enabled =
401 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
402 prefs.accelerated_video_enabled =
403 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
404 prefs.partial_swap_enabled =
405 command_line.HasSwitch(switches::kEnablePartialSwap);
406 prefs.interactive_form_validation_enabled =
407 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
408 prefs.fullscreen_enabled =
409 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16410 prefs.css_regions_enabled =
411 command_line.HasSwitch(switches::kEnableCssRegions);
412
[email protected]64d69de42012-02-06 00:19:54413
414#if defined(OS_MACOSX)
415 bool default_enable_scroll_animator = true;
416#else
417 // On CrOS, the launcher always passes in the --enable flag.
418 bool default_enable_scroll_animator = false;
419#endif
420 prefs.enable_scroll_animator = default_enable_scroll_animator;
421 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
422 prefs.enable_scroll_animator = true;
423 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
424 prefs.enable_scroll_animator = false;
425
426 prefs.visual_word_movement_enabled =
427 command_line.HasSwitch(switches::kEnableVisualWordMovement);
428 prefs.per_tile_painting_enabled =
429 command_line.HasSwitch(switches::kEnablePerTilePainting);
430
431 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32432 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54433 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11434 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
435 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54436 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11437 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54438 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11439 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54440 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11441 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54442 prefs.gl_multisampling_enabled = false;
443
444 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45445 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32446 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54447 prefs.accelerated_video_enabled = false;
448 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45449 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54450 }
451 }
452
[email protected]b9535422012-02-09 01:47:59453 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58454 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54455 prefs.loads_images_automatically = true;
456 prefs.javascript_enabled = true;
457 }
458
459 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
460
461 // Force accelerated compositing and 2d canvas off for chrome:, about: and
462 // chrome-devtools: pages (unless it's specifically allowed).
463 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54464 url.SchemeIs(chrome::kChromeUIScheme) ||
465 (url.SchemeIs(chrome::kAboutScheme) &&
466 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25467 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54468 prefs.accelerated_compositing_enabled = false;
469 prefs.accelerated_2d_canvas_enabled = false;
470 }
471
[email protected]43d9d782012-03-01 15:40:09472 int default_device_scale_factor;
473 base::StringToInt(command_line.GetSwitchValueASCII(
474 switches::kDefaultDeviceScaleFactor),
475 &default_device_scale_factor);
476
477 prefs.default_device_scale_factor = default_device_scale_factor;
478
[email protected]2e21fe292012-03-02 22:52:32479 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54480
481 return prefs;
482}
483
[email protected]d202a7c2012-01-04 07:53:47484NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20485 return controller_;
486}
487
[email protected]765187182012-01-11 23:59:28488RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
489 return &render_manager_;
490}
491
[email protected]724159a2010-12-30 01:11:18492bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56493 if (GetWebUI() &&
494 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17495 return true;
[email protected]d2353452012-01-19 19:53:56496 }
[email protected]f82d57b52011-04-27 19:13:17497
[email protected]d8c660432011-12-22 20:51:25498 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
499 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10500 while ((observer = it.GetNext()) != NULL)
501 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53502 return true;
[email protected]403415a2011-01-10 18:57:53503
[email protected]724159a2010-12-30 01:11:18504 bool handled = true;
505 bool message_is_ok = true;
506 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58507 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
508 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24509 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
510 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18511 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
512 OnDidStartProvisionalLoadForFrame)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
514 OnDidRedirectProvisionalLoad)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
516 OnDidFailProvisionalLoadWithError)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
518 OnDidLoadResourceFromMemoryCache)
519 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
520 OnDidDisplayInsecureContent)
521 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
522 OnDidRunInsecureContent)
523 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
524 OnDocumentLoadedInFrame)
525 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17526 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
527 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25528 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26529 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59530 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21531 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20532 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
534 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16535 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45536 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10537 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18538 IPC_MESSAGE_UNHANDLED(handled = false)
539 IPC_END_MESSAGE_MAP_EX()
540
541 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38542 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18543 GetRenderProcessHost()->ReceivedBadMessage();
544 }
545
546 return handled;
547}
548
[email protected]6c2e472f2011-08-24 23:26:18549void TabContents::RunFileChooser(
550 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23551 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51552 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18553}
554
[email protected]c5eed492012-01-04 17:07:50555NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56556 return controller_;
557}
558
[email protected]c5eed492012-01-04 17:07:50559const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56560 return controller_;
561}
562
[email protected]627e0512011-12-21 22:55:30563content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55564 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30565}
566
[email protected]f5fa20e2011-12-21 22:35:56567void TabContents::SetViewType(content::ViewType type) {
568 view_type_ = type;
569}
570
[email protected]ea049a02011-12-25 21:37:09571content::ViewType TabContents::GetViewType() const {
572 return view_type_;
573}
574
[email protected]be1f56ab2011-12-22 06:55:31575const GURL& TabContents::GetURL() const {
576 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23577 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31579}
580
581
582const base::PropertyBag* TabContents::GetPropertyBag() const {
583 return &property_bag_;
584}
585
586base::PropertyBag* TabContents::GetPropertyBag() {
587 return &property_bag_;
588}
589
590content::WebContentsDelegate* TabContents::GetDelegate() {
591 return delegate_;
592}
593
594void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
595 // TODO(cbentzel): remove this debugging code?
596 if (delegate == delegate_)
597 return;
598 if (delegate_)
599 delegate_->Detach(this);
600 delegate_ = delegate;
601 if (delegate_)
602 delegate_->Attach(this);
603}
604
[email protected]f3b1a082011-11-18 00:34:30605content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03606 if (render_manager_.current_host())
[email protected]9f76c1e2012-03-05 15:15:58607 return render_manager_.current_host()->GetProcess();
[email protected]4d0df262011-10-03 20:05:03608 else
609 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16610}
611
[email protected]be1f56ab2011-12-22 06:55:31612RenderViewHost* TabContents::GetRenderViewHost() const {
613 return render_manager_.current_host();
614}
615
616RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
617 return render_manager_.GetRenderWidgetHostView();
618}
619
[email protected]8643e6d2012-01-18 20:26:10620content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31621 return view_.get();
622}
623
[email protected]01ec4ec2012-01-18 04:13:47624content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50625 WebUIControllerFactory* factory =
626 content::GetContentClient()->browser()->GetWebUIControllerFactory();
627 if (!factory)
628 return NULL;
[email protected]d2353452012-01-19 19:53:56629 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22630 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50631 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22632 if (controller) {
633 web_ui->SetController(controller);
634 return web_ui;
635 }
636
637 delete web_ui;
638 return NULL;
639}
640
[email protected]01ec4ec2012-01-18 04:13:47641content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31642 return render_manager_.web_ui() ? render_manager_.web_ui()
643 : render_manager_.pending_web_ui();
644}
645
[email protected]01ec4ec2012-01-18 04:13:47646content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31647 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34648}
649
[email protected]96d185d2009-04-24 03:28:54650const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55651 // Transient entries take precedence. They are used for interstitial pages
652 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23653 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08654 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20655 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30656 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23657 if (entry) {
[email protected]b5cca982011-05-26 04:42:08658 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23659 }
[email protected]7ade2732011-02-10 00:13:58660 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
661 render_manager_.pending_web_ui() : render_manager_.web_ui();
662 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54663 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55664 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54665 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35666 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22667 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54668 if (!title.empty())
669 return title;
670 }
671 }
672
673 // We use the title for the last committed entry rather than a pending
674 // navigation entry. For example, when the user types in a URL, we want to
675 // keep the old page's title until the new load has committed and we get a new
676 // title.
[email protected]96d185d2009-04-24 03:28:54677 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23678 if (entry) {
[email protected]b5cca982011-05-26 04:42:08679 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23680 }
[email protected]987fc3a2011-05-26 14:18:09681
682 // |page_title_when_no_navigation_entry_| is finally used
683 // if no title cannot be retrieved.
684 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54685}
686
[email protected]d5f942ba2008-09-26 19:30:34687int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46688 return GetMaxPageIDForSiteInstance(GetSiteInstance());
689}
690
691int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33692 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
693 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46694
[email protected]b6583592012-01-25 19:52:33695 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34696}
697
698void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46699 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
700}
701
[email protected]b6583592012-01-25 19:52:33702void TabContents::UpdateMaxPageIDForSiteInstance(
703 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46704 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33705 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34706}
707
[email protected]91854cd2012-01-10 19:43:57708void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
709 max_page_ids_ = tab_contents->max_page_ids_;
710}
711
[email protected]96d185d2009-04-24 03:28:54712SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58713 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54714}
715
[email protected]77362eb2011-08-01 17:18:38716SiteInstance* TabContents::GetPendingSiteInstance() const {
717 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
718 render_manager_.pending_render_view_host() :
719 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58720 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38721}
722
[email protected]be1f56ab2011-12-22 06:55:31723bool TabContents::IsLoading() const {
724 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49725}
726
[email protected]be1f56ab2011-12-22 06:55:31727bool TabContents::IsWaitingForResponse() const {
728 return waiting_for_response_;
729}
730
731const net::LoadStateWithParam& TabContents::GetLoadState() const {
732 return load_state_;
733}
734
735const string16& TabContents::GetLoadStateHost() const {
736 return load_state_host_;
737}
738
739uint64 TabContents::GetUploadSize() const {
740 return upload_size_;
741}
742
743uint64 TabContents::GetUploadPosition() const {
744 return upload_position_;
745}
746
747const std::string& TabContents::GetEncoding() const {
748 return encoding_;
749}
750
751bool TabContents::DisplayedInsecureContent() const {
752 return displayed_insecure_content_;
753}
754
755void TabContents::SetCapturingContents(bool cap) {
756 capturing_contents_ = cap;
757}
758
759bool TabContents::IsCrashed() const {
760 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
761 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
762 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49763}
764
[email protected]443b80e2010-12-14 00:42:23765void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
766 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34767 return;
768
[email protected]443b80e2010-12-14 00:42:23769 crashed_status_ = status;
770 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46771 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34772}
773
[email protected]be1f56ab2011-12-22 06:55:31774base::TerminationStatus TabContents::GetCrashedStatus() const {
775 return crashed_status_;
776}
777
778bool TabContents::IsBeingDestroyed() const {
779 return is_being_destroyed_;
780}
781
[email protected]d5f942ba2008-09-26 19:30:34782void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
783 if (delegate_)
784 delegate_->NavigationStateChanged(this, changed_flags);
785}
786
[email protected]96d185d2009-04-24 03:28:54787void TabContents::DidBecomeSelected() {
788 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04789 RenderWidgetHostViewPort* rwhv =
790 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16791 if (rwhv) {
792 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43793#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16794 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43795#endif
796 }
[email protected]96d185d2009-04-24 03:28:54797
[email protected]5ac20162010-11-24 23:33:11798 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38799
[email protected]d8c660432011-12-22 20:51:25800 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59801
802 // The resize rect might have changed while this was inactive -- send the new
803 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58804 RenderViewHostImpl* rvh =
805 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59806 if (rvh) {
807 rvh->ResizeRectChanged(GetRootWindowResizerRect());
808 }
[email protected]96d185d2009-04-24 03:28:54809}
810
[email protected]be1f56ab2011-12-22 06:55:31811
812base::TimeTicks TabContents::GetLastSelectedTime() const {
813 return last_selected_time_;
814}
815
[email protected]96d185d2009-04-24 03:28:54816void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31817 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52818 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
819 // open a tab in then background, then closes the tab before selecting it.
820 // This is because closing the tab calls TabContents::Destroy(), which
821 // removes the |GetRenderViewHost()|; then when we actually destroy the
822 // window, OnWindowPosChanged() notices and calls HideContents() (which
823 // calls us).
[email protected]c30585c2012-02-16 15:02:04824 RenderWidgetHostViewPort* rwhv =
825 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16826 if (rwhv)
827 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54828 }
829
[email protected]ad50def52011-10-19 23:17:07830 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09831 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
832 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07833 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54834}
835
[email protected]be1f56ab2011-12-22 06:55:31836void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04837 RenderWidgetHostViewPort* rwhv =
838 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31839 if (rwhv)
840 rwhv->DidBecomeSelected();
841}
842
843void TabContents::HideContents() {
844 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
845 // our superclass HideContents(), because some callers want to be very picky
846 // about the order in which these get called. In addition to making the code
847 // here practically impossible to understand, this also means we end up
848 // calling TabContents::WasHidden() twice if callers call both versions of
849 // HideContents() on a TabContents.
850 WasHidden();
851}
852
853bool TabContents::NeedToFireBeforeUnload() {
854 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27855 return WillNotifyDisconnection() &&
856 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58857 !static_cast<RenderViewHostImpl*>(
858 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31859}
860
[email protected]0bfbf882011-12-22 18:19:27861void TabContents::Stop() {
862 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25863 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27864}
865
[email protected]d9083482012-01-06 00:38:46866WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27867 // We create a new SiteInstance so that the new tab won't share processes
868 // with the old one. This can be changed in the future if we need it to share
869 // processes for some reason.
870 TabContents* tc = new TabContents(
871 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33872 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27873 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20874 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27875 return tc;
876}
877
[email protected]2a6bc3e2011-12-28 23:51:33878void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27879 WindowOpenDisposition disposition,
880 const gfx::Rect& initial_pos,
881 bool user_gesture) {
882 if (!delegate_)
883 return;
884
885 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
886 user_gesture);
887}
888
889gfx::NativeView TabContents::GetContentNativeView() const {
890 return view_->GetContentNativeView();
891}
892
893gfx::NativeView TabContents::GetNativeView() const {
894 return view_->GetNativeView();
895}
896
897void TabContents::GetContainerBounds(gfx::Rect* out) const {
898 view_->GetContainerBounds(out);
899}
900
901void TabContents::Focus() {
902 view_->Focus();
903}
904
[email protected]d8c660432011-12-22 20:51:25905void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31906 observers_.AddObserver(observer);
907}
908
[email protected]d8c660432011-12-22 20:51:25909void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31910 observers_.RemoveObserver(observer);
911}
912
[email protected]d5f942ba2008-09-26 19:30:34913void TabContents::Activate() {
914 if (delegate_)
915 delegate_->ActivateContents(this);
916}
917
[email protected]ea42e7782010-08-23 23:58:12918void TabContents::Deactivate() {
919 if (delegate_)
920 delegate_->DeactivateContents(this);
921}
922
[email protected]63954792011-07-11 04:17:48923void TabContents::LostCapture() {
924 if (delegate_)
925 delegate_->LostCapture();
926}
927
928bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
929 bool* is_keyboard_shortcut) {
930 return delegate_ &&
931 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
932}
933
934void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
935 if (delegate_)
936 delegate_->HandleKeyboardEvent(event);
937}
938
[email protected]32ded2212011-11-10 18:51:43939void TabContents::HandleMouseDown() {
940 if (delegate_)
941 delegate_->HandleMouseDown();
942}
943
[email protected]63954792011-07-11 04:17:48944void TabContents::HandleMouseUp() {
945 if (delegate_)
946 delegate_->HandleMouseUp();
947}
948
949void TabContents::HandleMouseActivate() {
950 if (delegate_)
951 delegate_->HandleMouseActivate();
952}
953
[email protected]8a5e0ca2011-08-25 06:30:47954void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
955 if (delegate_)
956 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
957}
958
[email protected]5d5f7af2011-10-01 01:38:12959bool TabContents::IsFullscreenForCurrentTab() const {
960 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
961}
962
[email protected]e9621112011-10-17 05:38:37963void TabContents::RequestToLockMouse() {
964 if (delegate_) {
965 delegate_->RequestToLockMouse(this);
966 } else {
967 GotResponseToLockMouseRequest(false);
968 }
969}
970
971void TabContents::LostMouseLock() {
972 if (delegate_)
973 delegate_->LostMouseLock();
974}
975
[email protected]0548c5352011-09-07 00:33:33976void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23977 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33978 if (delegate_)
979 delegate_->UpdatePreferredSize(this, pref_size);
980}
981
[email protected]61e2b3cc2012-03-02 16:13:34982void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
983 if (delegate_)
984 delegate_->ResizeDueToAutoResize(this, new_size);
985}
986
[email protected]32ded2212011-11-10 18:51:43987void TabContents::WebUISend(RenderViewHost* render_view_host,
988 const GURL& source_url,
989 const std::string& name,
990 const base::ListValue& args) {
991 if (delegate_)
992 delegate_->WebUISend(this, source_url, name, args);
993}
994
[email protected]e5d549d2011-12-28 01:29:20995WebContents* TabContents::OpenURL(const OpenURLParams& params) {
996 if (!delegate_)
997 return NULL;
[email protected]00c37fc2011-08-02 00:22:50998
[email protected]e5d549d2011-12-28 01:29:20999 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1000 // Notify observers.
1001 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1002 DidOpenURL(params.url, params.referrer,
1003 params.disposition, params.transition));
1004 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341005}
1006
[email protected]1ccb3568d2010-02-19 10:51:161007bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501008 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251009 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231010 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251011 reload_type);
[email protected]876bc832010-09-07 16:29:541012}
[email protected]96d185d2009-04-24 03:28:541013
[email protected]876bc832010-09-07 16:29:541014bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231015 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501016 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401017 // The renderer will reject IPC messages with URLs longer than
1018 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511019 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401020 return false;
1021
[email protected]9f76c1e2012-03-05 15:15:581022 RenderViewHostImpl* dest_render_view_host =
1023 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401024 if (!dest_render_view_host)
1025 return false; // Unable to create the desired render view host.
1026
[email protected]80a8fad2011-01-29 04:02:381027 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071028 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581029 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501030 WebUIControllerFactory* factory =
1031 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1032 bool is_allowed_in_web_ui_renderer =
1033 factory &&
1034 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431035#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511036 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431037#endif
[email protected]e091df82011-10-11 18:13:211038 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551039 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581040
[email protected]96d185d2009-04-24 03:28:541041 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441042 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521043 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441044 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511045 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541046
1047 // Used for page load time metrics.
1048 current_load_start_ = base::TimeTicks::Now();
1049
1050 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341051 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271052 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471053 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341054 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541055
[email protected]36fc0392011-12-25 03:59:511056 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541057 // HACK!! This code suppresses javascript: URLs from being added to
1058 // session history, which is what we want to do for javascript: URLs that
1059 // do not generate content. What we really need is a message from the
1060 // renderer telling us that a new page was not created. The same message
1061 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511062 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541063 return false;
1064 }
1065
[email protected]3c9e1872010-11-18 16:17:491066 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251067 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041068 observers_,
[email protected]36fc0392011-12-25 03:59:511069 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541070
[email protected]09b29342011-06-24 19:18:481071 if (delegate_)
1072 delegate_->DidNavigateToPendingEntry(this);
1073
[email protected]d5f942ba2008-09-26 19:30:341074 return true;
1075}
1076
[email protected]b6583592012-01-25 19:52:331077void TabContents::SetHistoryLengthAndPrune(
1078 const SiteInstance* site_instance,
1079 int history_length,
1080 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411081 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1082 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191083 if (render_manager_.pending_render_view_host()) {
1084 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141085 return;
[email protected]9e1ad4b2011-08-14 16:49:191086 }
[email protected]9f76c1e2012-03-05 15:15:581087 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191088 if (!rvh) {
1089 NOTREACHED();
1090 return;
1091 }
[email protected]9f76c1e2012-03-05 15:15:581092 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191093 NOTREACHED();
1094 return;
1095 }
[email protected]9f76c1e2012-03-05 15:15:581096 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191097 history_length,
1098 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141099}
1100
[email protected]90daadb42009-06-08 21:27:281101void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271102 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541103 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1104 return;
1105 }
[email protected]9f76c1e2012-03-05 15:15:581106 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541107}
1108
[email protected]0bfbf882011-12-22 18:19:271109bool TabContents::ShowingInterstitialPage() const {
1110 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541111}
1112
[email protected]0bfbf882011-12-22 18:19:271113InterstitialPage* TabContents::GetInterstitialPage() const {
1114 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221115}
1116
[email protected]a53209b2012-01-20 16:48:161117bool TabContents::IsSavable() {
1118 // WebKit creates Document object when MIME type is application/xhtml+xml,
1119 // so we also support this MIME type.
1120 return contents_mime_type_ == "text/html" ||
1121 contents_mime_type_ == "text/xml" ||
1122 contents_mime_type_ == "application/xhtml+xml" ||
1123 contents_mime_type_ == "text/plain" ||
1124 contents_mime_type_ == "text/css" ||
1125 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1126}
1127
[email protected]c7dd2f62011-07-18 15:57:591128void TabContents::OnSavePage() {
1129 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161130 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481131 download_stats::RecordDownloadSource(
1132 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261133 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141134 return;
[email protected]c7dd2f62011-07-18 15:57:591135 }
1136
1137 Stop();
1138
1139 // Create the save package and possibly prompt the user for the name to save
1140 // the page as. The user prompt is an asynchronous operation that runs on
1141 // another thread.
1142 save_package_ = new SavePackage(this);
1143 save_package_->GetSaveInfo();
1144}
1145
1146// Used in automated testing to bypass prompting the user for file names.
1147// Instead, the names and paths are hard coded rather than running them through
1148// file name sanitation and extension / mime checking.
1149bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161150 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591151 // Stop the page from navigating.
1152 Stop();
1153
1154 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1155 return save_package_->Init();
1156}
1157
[email protected]aa4f3972012-03-01 18:12:121158void TabContents::GenerateMHTML(
1159 const FilePath& file,
1160 const base::Callback<void(const FilePath&, int64)>& callback) {
1161 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1162}
1163
[email protected]420ae012009-04-24 05:16:321164bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231165 NavigationEntryImpl* active_entry =
1166 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321167 return (active_entry != NULL &&
1168 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511169 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321170}
1171
[email protected]0bfbf882011-12-22 18:19:271172const std::string& TabContents::GetContentsMimeType() const {
1173 return contents_mime_type_;
1174}
1175
1176bool TabContents::WillNotifyDisconnection() const {
1177 return notify_disconnection_;
1178}
1179
[email protected]b2fe07d12010-02-09 14:38:081180void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311181 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581182 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1183 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161184}
1185
[email protected]b2fe07d12010-02-09 14:38:081186void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311187 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581188 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1189 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161190}
1191
[email protected]0bfbf882011-12-22 18:19:271192content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1193 return &renderer_preferences_;
1194}
1195
1196void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1197 new_tab_start_time_ = time;
1198}
1199
1200base::TimeTicks TabContents::GetNewTabStartTime() const {
1201 return new_tab_start_time_;
1202}
1203
[email protected]7ab1e7d62009-10-14 23:32:011204void TabContents::OnCloseStarted() {
1205 if (tab_close_start_time_.is_null())
1206 tab_close_start_time_ = base::TimeTicks::Now();
1207}
1208
[email protected]46624bf2010-06-09 16:04:191209bool TabContents::ShouldAcceptDragAndDrop() const {
1210#if defined(OS_CHROMEOS)
1211 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1212 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511213 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201214 return false;
1215 return true;
[email protected]46624bf2010-06-09 16:04:191216#else
1217 return true;
1218#endif
1219}
1220
[email protected]7813bd72011-02-05 02:19:341221void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521222 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581223 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511224 if (delegate_)
1225 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341226}
1227
[email protected]0bfbf882011-12-22 18:19:271228void TabContents::SetClosedByUserGesture(bool value) {
1229 closed_by_user_gesture_ = value;
1230}
1231
1232bool TabContents::GetClosedByUserGesture() const {
1233 return closed_by_user_gesture_;
1234}
1235
[email protected]d0b8d092010-10-25 04:05:171236double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051237 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561238 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251239 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171240 return 0;
[email protected]b75b8292010-10-01 07:28:251241
1242 double zoom_level;
1243 if (temporary_zoom_settings_) {
1244 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581245 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251246 } else {
[email protected]2ae88d12011-10-14 09:11:191247 GURL url;
[email protected]10f417c52011-12-28 21:04:231248 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191249 // Since zoom map is updated using rewritten URL, use rewritten URL
1250 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511251 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191252 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251253 }
[email protected]d0b8d092010-10-25 04:05:171254 return zoom_level;
1255}
[email protected]b75b8292010-10-01 07:28:251256
[email protected]d0b8d092010-10-25 04:05:171257int TabContents::GetZoomPercent(bool* enable_increment,
1258 bool* enable_decrement) {
1259 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011260 // Calculate the zoom percent from the factor. Round up to the nearest whole
1261 // number.
[email protected]b75b8292010-10-01 07:28:251262 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011263 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251264 *enable_decrement = percent > minimum_zoom_percent_;
1265 *enable_increment = percent < maximum_zoom_percent_;
1266 return percent;
1267}
1268
[email protected]3c733bde2010-12-21 19:56:311269void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501270 if (!delegate_)
1271 return;
1272
[email protected]10f417c52011-12-28 21:04:231273 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501274 if (!active_entry)
1275 return;
1276
[email protected]36fc0392011-12-25 03:59:511277 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121278}
1279
[email protected]932b7a12011-03-09 12:50:271280void TabContents::ViewFrameSource(const GURL& url,
1281 const std::string& content_state) {
1282 if (!delegate_)
1283 return;
1284
1285 delegate_->ViewSourceForFrame(this, url, content_state);
1286}
1287
[email protected]0bfbf882011-12-22 18:19:271288int TabContents::GetMinimumZoomPercent() const {
1289 return minimum_zoom_percent_;
1290}
1291
1292int TabContents::GetMaximumZoomPercent() const {
1293 return maximum_zoom_percent_;
1294}
1295
[email protected]bcd2815602012-01-14 18:17:231296gfx::Size TabContents::GetPreferredSize() const {
1297 return preferred_size_;
1298}
1299
[email protected]0bfbf882011-12-22 18:19:271300int TabContents::GetContentRestrictions() const {
1301 return content_restrictions_;
1302}
1303
1304WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501305 WebUIControllerFactory* factory =
1306 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1307 if (!factory)
1308 return WebUI::kNoWebUI;
1309 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271310}
1311
[email protected]01ec4ec2012-01-18 04:13:471312content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271313 // When there is a pending navigation entry, we want to use the pending WebUI
1314 // that goes along with it to control the basic flags. For example, we want to
1315 // show the pending URL in the URL bar, so we want the display_url flag to
1316 // be from the pending entry.
1317 //
1318 // The confusion comes because there are multiple possibilities for the
1319 // initial load in a tab as a side effect of the way the RenderViewHostManager
1320 // works.
1321 //
1322 // - For the very first tab the load looks "normal". The new tab Web UI is
1323 // the pending one, and we want it to apply here.
1324 //
1325 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1326 // get switched to the one previously associated with the new tab pages.
1327 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1328 // have a committed Web UI in this case.
1329 //
1330 // This condition handles all of these cases:
1331 //
1332 // - First load in first tab: no committed nav entry + pending nav entry +
1333 // pending dom ui:
1334 // -> Use pending Web UI if any.
1335 //
1336 // - First load in second tab: no committed nav entry + pending nav entry +
1337 // no pending Web UI:
1338 // -> Use the committed Web UI if any.
1339 //
1340 // - Second navigation in any tab: committed nav entry + pending nav entry:
1341 // -> Use pending Web UI if any.
1342 //
1343 // - Normal state with no load: committed nav entry + no pending nav entry:
1344 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251345 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271346 (controller_.GetLastCommittedEntry() ||
1347 render_manager_.pending_web_ui()))
1348 return render_manager_.pending_web_ui();
1349 return render_manager_.web_ui();
1350}
1351
1352bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1353 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581354 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271355}
1356
[email protected]a0358d72012-03-09 14:06:501357bool TabContents::HasOpener() const {
1358 return has_opener_;
1359}
1360
[email protected]0bfbf882011-12-22 18:19:271361bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471362 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271363 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221364 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231365 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511366 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271367 return true;
1368 return false;
1369}
1370
1371void TabContents::SetFocusToLocationBar(bool select_all) {
1372 if (delegate_)
1373 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211374}
1375
[email protected]8b5af492011-11-28 21:50:581376void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301377 const string16& type,
1378 const string16& href,
1379 const string16& title,
1380 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511381 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301382 this, action, type, href, title, disposition);
1383}
1384
[email protected]678105012011-12-09 04:01:211385void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301386 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001387 WebIntentsDispatcherImpl* intents_dispatcher =
1388 new WebIntentsDispatcherImpl(this, intent, intent_id);
1389 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301390}
1391
[email protected]724159a2010-12-30 01:11:181392void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1393 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591394 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181395 const GURL& url) {
1396 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1397 GURL validated_url(url);
[email protected]9f76c1e2012-03-05 15:15:581398 GetRenderViewHostImpl()->FilterURL(
1399 ChildProcessSecurityPolicyImpl::GetInstance(),
1400 GetRenderProcessHost()->GetID(),
1401 &validated_url);
[email protected]724159a2010-12-30 01:11:181402
[email protected]8093a542011-05-13 07:29:321403 RenderViewHost* rvh =
1404 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521405 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101406 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251407 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101408 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321409 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101410
[email protected]724159a2010-12-30 01:11:181411 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591412 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251413 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591414 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181415 }
1416}
1417
1418void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591419 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181420 const GURL& source_url,
1421 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491422 // TODO(creis): Remove this method and have the pre-rendering code listen to
1423 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1424 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231425 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181426 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251427 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181428 else
1429 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511430 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181431 return;
[email protected]e7d50892011-01-19 21:47:381432
[email protected]4850a7f2011-03-08 23:36:591433 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251434 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261435 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591436 opener_url));
[email protected]724159a2010-12-30 01:11:181437}
1438
1439void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581440 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1441 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1442 << ", error_code: " << params.error_code
1443 << ", error_description: " << params.error_description
1444 << ", is_main_frame: " << params.is_main_frame
1445 << ", showing_repost_interstitial: " <<
1446 params.showing_repost_interstitial
1447 << ", frame_id: " << params.frame_id;
1448 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581449 GetRenderViewHostImpl()->FilterURL(
1450 ChildProcessSecurityPolicyImpl::GetInstance(),
1451 GetRenderProcessHost()->GetID(),
1452 &validated_url);
[email protected]724159a2010-12-30 01:11:181453
[email protected]d7b175e2011-10-11 15:31:581454 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181455 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1456 // This means that the interstitial won't be torn down properly, which is
1457 // bad. But if we have an interstitial, go back to another tab type, and
1458 // then load the same interstitial again, we could end up getting the first
1459 // interstitial's "failed" message (as a result of the cancel) when we're on
1460 // the second one.
1461 //
1462 // We can't tell this apart, so we think we're tearing down the current page
1463 // which will cause a crash later one. There is also some code in
1464 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1465 // out because of this problem.
1466 //
1467 // http://code.google.com/p/chromium/issues/detail?id=2855
1468 // Because this will not tear down the interstitial properly, if "back" is
1469 // back to another tab type, the interstitial will still be somewhat alive
1470 // in the previous tab type. If you navigate somewhere that activates the
1471 // tab with the interstitial again, you'll see a flash before the new load
1472 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271473 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181474 LOG(WARNING) << "Discarding message during interstitial.";
1475 return;
1476 }
1477
[email protected]02102f82011-06-13 20:37:021478 // Discard our pending entry if the load canceled (e.g. if we decided to
1479 // download the file instead of load it). We do not verify that the URL
1480 // being canceled matches the pending entry's URL because they will not
1481 // match if a redirect occurred (in which case we do not want to leave a
1482 // stale redirect URL showing). This means that we also cancel the pending
1483 // entry if the user started a new navigation. As a result, the navigation
1484 // controller may not remember that a load is in progress, but the
1485 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251486 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161487 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181488
[email protected]151a63d2011-12-20 22:32:521489 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181490 }
1491
1492 // Send out a notification that we failed a provisional load with an error.
1493 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581494 params.is_main_frame,
1495 controller_.IsURLInPageNavigation(validated_url),
1496 validated_url,
1497 std::string(),
1498 false,
1499 params.frame_id);
1500 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181501
[email protected]ad50def52011-10-19 23:17:071502 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271503 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501504 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531505 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101506
[email protected]d8c660432011-12-22 20:51:251507 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581508 observers_,
1509 DidFailProvisionalLoad(params.frame_id,
1510 params.is_main_frame,
1511 validated_url,
1512 params.error_code,
1513 params.error_description));
[email protected]724159a2010-12-30 01:11:181514}
1515
1516void TabContents::OnDidLoadResourceFromMemoryCache(
1517 const GURL& url,
[email protected]70435962011-08-02 20:13:281518 const std::string& security_info,
1519 const std::string& http_method,
1520 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191521 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181522 cache.Increment();
1523
1524 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081525 int cert_id = 0;
1526 net::CertStatus cert_status = 0;
1527 int security_bits = -1;
1528 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511529 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1530 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301531 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161532 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181533
[email protected]ad50def52011-10-19 23:17:071534 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271535 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501536 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531537 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181538}
1539
1540void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381541 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181542 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201543 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181544}
1545
1546void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021547 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231548 LOG(INFO) << security_origin << " ran insecure content from "
1549 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381550 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051551 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381552 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051553 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1554 }
[email protected]330614de2012-02-13 17:07:181555 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411556 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201557 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181558}
1559
1560void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1561 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251562 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101563 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181564}
1565
[email protected]1a55c5be2011-11-29 11:36:311566void TabContents::OnDidFinishLoad(
1567 int64 frame_id,
1568 const GURL& validated_url,
1569 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311571 DidFinishLoad(frame_id, validated_url, is_main_frame));
1572}
1573
1574void TabContents::OnDidFailLoadWithError(int64 frame_id,
1575 const GURL& validated_url,
1576 bool is_main_frame,
1577 int error_code,
1578 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251579 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311580 DidFailLoad(frame_id, validated_url, is_main_frame,
1581 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181582}
1583
[email protected]c8f73ab2011-01-22 00:05:171584void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271585 content_restrictions_ = restrictions;
1586 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171587}
1588
[email protected]216813952011-05-19 22:21:261589void TabContents::OnGoToEntryAtOffset(int offset) {
1590 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231591 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251592 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261593 if (!entry)
1594 return;
1595 // Note that we don't call NavigationController::GotToOffset() as we don't
1596 // want to create a pending navigation entry (it might end up lingering
1597 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251598 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581599 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511600 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581601 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471602 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571603
1604 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1605 // it in now that we know. This allows us to find the entry when it commits.
1606 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231607 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331608 entry->set_site_instance(
1609 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571610 }
[email protected]216813952011-05-19 22:21:261611 }
1612}
1613
1614void TabContents::OnUpdateZoomLimits(int minimum_percent,
1615 int maximum_percent,
1616 bool remember) {
1617 minimum_zoom_percent_ = minimum_percent;
1618 maximum_zoom_percent_ = maximum_percent;
1619 temporary_zoom_settings_ = !remember;
1620}
1621
[email protected]0bfbf882011-12-22 18:19:271622void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481623 download_stats::RecordDownloadSource(
1624 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261625 // Check if the URL to save matches the URL of the main frame. Since this
1626 // message originates from Pepper plugins, it may not be the case if the
1627 // plugin is an embedded element.
1628 GURL main_frame_url = GetURL();
1629 if (!main_frame_url.is_valid())
1630 return;
1631 bool is_main_frame = (url == main_frame_url);
1632 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271633}
1634
[email protected]3a29a6e2011-08-24 18:26:211635void TabContents::OnEnumerateDirectory(int request_id,
1636 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591637 ChildProcessSecurityPolicyImpl* policy =
1638 ChildProcessSecurityPolicyImpl::GetInstance();
1639 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1640 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211641}
1642
[email protected]7d189022011-08-25 22:54:201643void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511644 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201645}
1646
1647void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1648 const GURL& url,
1649 const string16& title) {
[email protected]b9535422012-02-09 01:47:591650 ChildProcessSecurityPolicyImpl* policy =
1651 ChildProcessSecurityPolicyImpl::GetInstance();
1652 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1653 return;
[email protected]6934a702011-12-20 00:04:511654 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201655}
1656
[email protected]b888919c2011-09-02 00:32:161657void TabContents::OnFindReply(int request_id,
1658 int number_of_matches,
1659 const gfx::Rect& selection_rect,
1660 int active_match_ordinal,
1661 bool final_update) {
[email protected]6934a702011-12-20 00:04:511662 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1663 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001664 // Send a notification to the renderer that we are ready to receive more
1665 // results from the scoping effort of the Find operation. The FindInPage
1666 // scoping is asynchronous and periodically sends results back up to the
1667 // browser using IPC. In an effort to not spam the browser we have the
1668 // browser send an ACK for each FindReply message and have the renderer
1669 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581670 GetRenderViewHostImpl()->Send(
1671 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161672}
1673
[email protected]d952a052011-09-06 18:42:451674void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511675 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451676}
1677
[email protected]7fc4bbb2011-09-08 21:23:101678void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1679 bool blocked_by_policy) {
1680 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101682 AppCacheAccessed(manifest_url, blocked_by_policy));
1683}
1684
[email protected]96d185d2009-04-24 03:28:541685// Notifies the RenderWidgetHost instance about the fact that the page is
1686// loading, or done loading and calls the base implementation.
1687void TabContents::SetIsLoading(bool is_loading,
1688 LoadNotificationDetails* details) {
1689 if (is_loading == is_loading_)
1690 return;
1691
1692 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211693 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541694 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561695 upload_size_ = 0;
1696 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541697 }
1698
1699 render_manager_.SetIsLoading(is_loading);
1700
1701 is_loading_ = is_loading;
1702 waiting_for_response_ = is_loading;
1703
[email protected]6ebdc9b2010-09-27 16:55:571704 if (delegate_)
1705 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461706 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541707
[email protected]432115822011-07-10 15:52:271708 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1709 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071710 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541711 if (details)
[email protected]6c2381d2011-10-19 02:52:531712 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071713 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501714 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541715 det);
1716}
1717
[email protected]420ae012009-04-24 05:16:321718void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131719 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321720 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561721 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381722 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441723 // that opened the window, as long as both renderers have the same
1724 // privileges.
[email protected]1fd1a502011-03-30 16:55:561725 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561726 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581727 // web_ui might be NULL if the URL refers to a non-existent extension.
1728 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401729 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521730 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441731 }
1732 }
[email protected]1fd1a502011-03-30 16:55:561733 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441734 }
1735
[email protected]4e697b042011-07-08 06:44:561736 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321737 // Clear the status bubble. This is a workaround for a bug where WebKit
1738 // doesn't let us know that the cursor left an element during a
1739 // transition (this is also why the mouse cursor remains as a hand after
1740 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1741 // clear the bubble when a user navigates to a named anchor in the same
1742 // page.
[email protected]36fc0392011-12-25 03:59:511743 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321744 }
1745
[email protected]a6e82fc2010-02-24 22:28:141746 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471747 // Once the main frame is navigated, we're no longer considered to have
1748 // displayed insecure content.
1749 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171750 }
[email protected]ce5c4502009-05-06 16:46:111751
[email protected]3c9e1872010-11-18 16:17:491752 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251753 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041754 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321755}
1756
1757void TabContents::DidNavigateAnyFramePostCommit(
1758 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131759 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321760 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061761 // If we navigate off the page, reset JavaScript state. This does nothing
1762 // to prevent a malicious script from spamming messages, since the script
1763 // could just reload the page to stop blocking.
1764 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551765 dialog_creator_->ResetJavaScriptState(this);
1766 dialog_creator_ = NULL;
1767 }
[email protected]420ae012009-04-24 05:16:321768
[email protected]3c9e1872010-11-18 16:17:491769 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251770 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041771 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321772}
1773
[email protected]74ce1ad2011-12-16 21:51:461774void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1775 // If we are creating a RVH for a restored controller, then we need to make
1776 // sure the RenderView starts with a next_page_id_ larger than the number
1777 // of restored entries. This must be called before the RenderView starts
1778 // navigating (to avoid a race between the browser updating max_page_id and
1779 // the renderer updating next_page_id_). Because of this, we only call this
1780 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561781 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581782 if (max_restored_page_id >
1783 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1784 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1785 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321786}
1787
[email protected]10f417c52011-12-28 21:04:231788bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571789 const string16& title) {
[email protected]420ae012009-04-24 05:16:321790 // For file URLs without a title, use the pathname instead. In the case of a
1791 // synthesized title, we don't want the update to count toward the "one set
1792 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511793 string16 final_title;
[email protected]420ae012009-04-24 05:16:321794 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511795 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1796 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321797 explicit_set = false; // Don't count synthetic titles toward the set limit.
1798 } else {
[email protected]acafd272011-07-26 17:35:571799 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321800 explicit_set = true;
1801 }
1802
[email protected]987fc3a2011-05-26 14:18:091803 // If a page is created via window.open and never navigated,
1804 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551805 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091806 if (entry) {
[email protected]36fc0392011-12-25 03:59:511807 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091808 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321809
[email protected]36fc0392011-12-25 03:59:511810 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091811 } else {
1812 if (page_title_when_no_navigation_entry_ == final_title)
1813 return false; // Nothing changed, don't bother.
1814
1815 page_title_when_no_navigation_entry_ = final_title;
1816 }
[email protected]420ae012009-04-24 05:16:321817
[email protected]420ae012009-04-24 05:16:321818 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231819 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321820
[email protected]2bb171882012-03-07 02:09:461821 std::pair<content::NavigationEntry*, bool> details =
1822 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141823
[email protected]ad50def52011-10-19 23:17:071824 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441825 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1826 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461827 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041828
[email protected]420ae012009-04-24 05:16:321829 return true;
1830}
1831
1832void TabContents::NotifySwapped() {
1833 // After sending out a swap notification, we need to send a disconnect
1834 // notification so that clients that pick up a pointer to |this| can NULL the
1835 // pointer. See Bug 1230284.
1836 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071837 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201838 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1839 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071840 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321841}
1842
1843void TabContents::NotifyConnected() {
1844 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071845 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121846 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1847 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071848 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321849}
1850
1851void TabContents::NotifyDisconnected() {
1852 if (!notify_disconnection_)
1853 return;
1854
1855 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071856 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321857 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1858 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071859 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321860}
1861
[email protected]8d3347f2009-07-09 22:00:211862RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321863 return view_.get();
1864}
1865
[email protected]8d3347f2009-07-09 22:00:211866RenderViewHostDelegate::RendererManagement*
1867TabContents::GetRendererManagementDelegate() {
1868 return &render_manager_;
1869}
1870
[email protected]daf82f82011-10-31 22:35:311871content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371872 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461873 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511874}
1875
[email protected]768c5472011-12-26 19:06:171876WebContents* TabContents::GetAsWebContents() {
1877 return this;
1878}
1879
[email protected]da4dfc42011-10-12 15:53:561880content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431881 return view_type_;
[email protected]7b291f92009-08-14 05:43:531882}
1883
[email protected]b7a756d42012-01-23 18:08:171884gfx::Rect TabContents::GetRootWindowResizerRect() const {
1885 if (delegate_)
1886 return delegate_->GetRootWindowResizerRect();
1887 return gfx::Rect();
1888}
1889
[email protected]420ae012009-04-24 05:16:321890void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071891 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271892 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321893 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531894 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231895 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321896 if (!entry)
1897 return;
1898
1899 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351900 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561901 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581902 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321903
1904 if (entry->IsViewSourceMode()) {
1905 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581906 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1907 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321908 }
[email protected]0666aef2009-05-13 19:48:081909
[email protected]d487beefe2011-12-21 05:41:211910 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261911
1912 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251913 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321914}
1915
1916void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521917 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321918 // Don't notify the world, since this came from a renderer in the
1919 // background.
1920 return;
1921 }
1922
1923 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311924 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231925 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301926
1927 // Restore the focus to the tab (otherwise the focus will be on the top
1928 // window).
[email protected]484ae5912010-09-29 19:16:141929 if (was_crashed && !FocusLocationBarByDefault() &&
1930 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301931 Focus();
[email protected]484ae5912010-09-29 19:16:141932 }
[email protected]32ded2212011-11-10 18:51:431933
[email protected]d8c660432011-12-22 20:51:251934 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321935}
1936
[email protected]443b80e2010-12-14 00:42:231937void TabContents::RenderViewGone(RenderViewHost* rvh,
1938 base::TerminationStatus status,
1939 int error_code) {
[email protected]151a63d2011-12-20 22:32:521940 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321941 // The pending page's RenderViewHost is gone.
1942 return;
1943 }
1944
1945 SetIsLoading(false, NULL);
1946 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231947 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311948 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321949
[email protected]d8c660432011-12-22 20:51:251950 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271951 observers_,
[email protected]be1f56ab2011-12-22 06:55:311952 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321953}
1954
[email protected]2e4633c2009-07-09 16:58:061955void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481956 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251957 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061958}
1959
[email protected]420ae012009-04-24 05:16:321960void TabContents::DidNavigate(RenderViewHost* rvh,
1961 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581962 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321963 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371964
[email protected]434f69f2012-02-06 21:56:521965 // Update the site of the SiteInstance if it doesn't have one yet, unless
1966 // this is for about:blank. In that case, the SiteInstance can still be
1967 // considered unused until a navigation to a real page.
1968 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1969 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331970 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521971 }
[email protected]420ae012009-04-24 05:16:321972
1973 // Need to update MIME type here because it's referred to in
1974 // UpdateNavigationCommands() called by RendererDidNavigate() to
1975 // determine whether or not to enable the encoding menu.
1976 // It's updated only for the main frame. For a subframe,
1977 // RenderView::UpdateURL does not set params.contents_mime_type.
1978 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1979 // TODO(jungshik): Add a test for the encoding menu to avoid
1980 // regressing it again.
[email protected]2905f742011-10-13 03:51:581981 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321982 contents_mime_type_ = params.contents_mime_type;
1983
[email protected]8286f51a2011-05-31 17:39:131984 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001985 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391986
[email protected]a9c0bfe2010-09-17 08:35:221987 // Send notification about committed provisional loads. This notification is
1988 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1989 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081990 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071991 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1992 // that is not recorded in the navigation history. For the purpose of
1993 // tracking navigation events, we treat this event as a sub frame navigation
1994 // event.
1995 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581996 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221997 // Whether or not a page transition was triggered by going backward or
1998 // forward in the history is only stored in the navigation controller's
1999 // entry list.
2000 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512001 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582002 content::PAGE_TRANSITION_FORWARD_BACK)) {
2003 transition_type = content::PageTransitionFromInt(
2004 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222005 }
[email protected]0d60f0192011-04-14 12:40:102006 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252007 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102008 DidCommitProvisionalLoadForFrame(params.frame_id,
2009 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222010 }
2011
[email protected]76543b92009-08-31 17:27:452012 if (!did_navigate)
2013 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322014
2015 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2016 // for the appropriate notification (best) or you can add it to
2017 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2018 // necessary, please).
2019
2020 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002021 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322022 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512023 if (delegate_)
2024 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002025 }
[email protected]420ae012009-04-24 05:16:322026 DidNavigateAnyFramePostCommit(rvh, details, params);
2027}
2028
2029void TabContents::UpdateState(RenderViewHost* rvh,
2030 int32 page_id,
2031 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152032 // Ensure that this state update comes from either the active RVH or one of
2033 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522034 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322035
2036 // We must be prepared to handle state updates for any page, these occur
2037 // when the user is scrolling and entering form data, as well as when we're
2038 // leaving a page, in which case our state may have already been moved to
2039 // the next page. The navigation controller will look up the appropriate
2040 // NavigationEntry and update it when it is notified via the delegate.
2041
2042 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582043 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322044 if (entry_index < 0)
2045 return;
[email protected]10f417c52011-12-28 21:04:232046 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322047
[email protected]36fc0392011-12-25 03:59:512048 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322049 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512050 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322051 controller_.NotifyEntryChanged(entry, entry_index);
2052}
2053
2054void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572055 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462056 const string16& title,
2057 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322058 // If we have a title, that's a pretty good indication that we've started
2059 // getting useful data.
2060 SetNotWaitingForResponse();
2061
[email protected]73eb2602012-02-09 19:50:552062 // Try to find the navigation entry, which might not be the current one.
2063 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232064 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582065 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092066
[email protected]73eb2602012-02-09 19:50:552067 // We can handle title updates when we don't have an entry in
2068 // UpdateTitleForEntry, but only if the update is from the current RVH.
2069 if (!entry && rvh != GetRenderViewHost())
2070 return;
2071
[email protected]a49e10b2011-08-01 23:57:462072 // TODO(evan): make use of title_direction.
2073 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092074 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322075 return;
2076
2077 // Broadcast notifications when the UI should be updated.
2078 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462079 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322080}
2081
[email protected]420ae012009-04-24 05:16:322082void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402083 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312084 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322085}
2086
2087void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512088 if (delegate_)
2089 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322090}
2091
[email protected]420ae012009-04-24 05:16:322092void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292093 // The UI may be in an event-tracking loop, such as between the
2094 // mouse-down and mouse-up in text selection or a button click.
2095 // Defer the close until after tracking is complete, so that we
2096 // don't free objects out from under the UI.
2097 // TODO(shess): This could probably be integrated with the
2098 // IsDoingDrag() test below. Punting for now because I need more
2099 // research to understand how this impacts platforms other than Mac.
2100 // TODO(shess): This could get more fine-grained. For instance,
2101 // closing a tab in another window while selecting text in the
2102 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212103 if (GetView()->IsEventTracking()) {
2104 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292105 return;
2106 }
2107
[email protected]24a4d1062009-07-10 23:10:422108 // If we close the tab while we're in the middle of a drag, we'll crash.
2109 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212110 if (GetView()->IsDoingDrag()) {
2111 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422112 return;
2113 }
2114
[email protected]420ae012009-04-24 05:16:322115 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522116 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512117 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322118}
2119
[email protected]cd9ed79d2011-11-15 19:22:572120void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522121 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512122 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572123}
2124
[email protected]420ae012009-04-24 05:16:322125void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512126 if (delegate_ && delegate_->IsPopupOrPanel(this))
2127 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322128}
2129
[email protected]7ab1e7d62009-10-14 23:32:012130void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322131 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492132
[email protected]6934a702011-12-20 00:04:512133 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212134 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512135 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002136 }
[email protected]3c9e1872010-11-18 16:17:492137
2138 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252139 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322140}
2141
[email protected]7ab1e7d62009-10-14 23:32:012142void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322143 scoped_ptr<LoadNotificationDetails> details;
2144
[email protected]10f417c52011-12-28 21:04:232145 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322146 // An entry may not exist for a stop when loading an initial blank page or
2147 // if an iframe injected by script into a blank page finishes loading.
2148 if (entry) {
[email protected]420ae012009-04-24 05:16:322149 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2150
2151 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512152 entry->GetVirtualURL(),
2153 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322154 elapsed,
2155 &controller_,
2156 controller_.GetCurrentEntryIndex()));
2157 }
2158
[email protected]420ae012009-04-24 05:16:322159 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492160
2161 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252162 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322163}
2164
[email protected]c95fa8b2011-04-28 20:26:162165void TabContents::DidCancelLoading() {
2166 controller_.DiscardNonCommittedEntries();
2167
2168 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462169 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162170}
2171
[email protected]1a3c3cb2010-12-16 21:03:402172void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512173 if (delegate_)
2174 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402175}
2176
[email protected]952a68e2011-11-17 00:36:102177void TabContents::DocumentAvailableInMainFrame(
2178 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252179 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102180 DocumentAvailableInMainFrame());
2181}
2182
[email protected]25497492010-09-11 15:15:082183void TabContents::DocumentOnLoadCompletedInMainFrame(
2184 RenderViewHost* render_view_host,
2185 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072186 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272187 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322188 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532189 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082190}
2191
[email protected]ae5184d62011-10-06 19:25:582192void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152193 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582194 WindowOpenDisposition disposition,
2195 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482196 // Delegate to RequestTransferURL because this is just the generic
2197 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582198 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482199 GlobalRequestID());
2200}
2201
2202void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582203 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482204 WindowOpenDisposition disposition,
2205 int64 source_frame_id,
2206 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202207 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582208 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582209 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352210 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322211 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2212 // generated suggestions).
2213 //
[email protected]e0112912011-02-02 22:54:352214 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162215 // want web sites to see a referrer of "chrome://blah" (and some
2216 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322217 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432218 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222219 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482220 false /* is_renderer_initiated */);
2221 params.transferred_global_request_id = old_request_id;
2222 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222223 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322224 } else {
[email protected]6bf6a6b52012-02-03 15:41:432225 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482226 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2227 params.transferred_global_request_id = old_request_id;
2228 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582229 }
2230 if (new_contents) {
2231 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252232 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582233 DidOpenRequestedURL(new_contents,
2234 url,
2235 referrer,
2236 disposition,
2237 transition_type,
2238 source_frame_id));
[email protected]420ae012009-04-24 05:16:322239 }
2240}
2241
[email protected]420ae012009-04-24 05:16:322242void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342243 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412244 const string16& message,
2245 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322246 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472247 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322248 IPC::Message* reply_msg,
2249 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072250 // Suppress JavaScript dialogs when requested. Also suppress messages when
2251 // showing an interstitial as it's shown over the previous page and we don't
2252 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502253 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582254 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272255 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072256 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522257 delegate_->ShouldSuppressDialogs() ||
2258 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322259
2260 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432261 std::string accept_lang = content::GetContentClient()->browser()->
2262 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552263 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522264 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432265 this,
2266 frame_url.GetOrigin(),
2267 accept_lang,
2268 javascript_message_type,
2269 message,
[email protected]51da7e32012-01-30 19:24:522270 default_prompt,
2271 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432272 reply_msg),
[email protected]51da7e32012-01-30 19:24:522273 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322274 }
[email protected]3ab9cb82011-06-03 18:02:072275
2276 if (suppress_this_message) {
2277 // If we are suppressing messages, just reply as if the user immediately
2278 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342279 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072280 }
2281
2282 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322283}
2284
[email protected]fedec012012-01-28 03:09:342285void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412286 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322287 bool is_reload,
[email protected]420ae012009-04-24 05:16:322288 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582289 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512290 if (delegate_)
2291 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072292
2293 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582294 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072295 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522296 delegate_->ShouldSuppressDialogs() ||
2297 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152298 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342299 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582300 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502301 return;
2302 }
[email protected]3ab9cb82011-06-03 18:02:072303
[email protected]7ab1e7d62009-10-14 23:32:012304 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552305 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522306 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322307 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522308 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2309 reply_msg));
[email protected]420ae012009-04-24 05:16:322310}
2311
[email protected]420ae012009-04-24 05:16:322312WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542313 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322314}
2315
[email protected]7d472472011-01-22 01:30:252316void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272317 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252318 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222319
[email protected]ea114722012-03-12 01:11:252320 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172321 if (rdh) // NULL in unittests.
2322 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252323}
2324
[email protected]fa1cf0b82010-01-15 21:49:442325void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442326 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252327 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442328}
2329
[email protected]420ae012009-04-24 05:16:322330void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2331 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152332 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522333 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152334 return;
2335
[email protected]9f76c1e2012-03-05 15:15:582336 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2337
[email protected]e5fc1632011-08-08 07:51:532338 // Ignore renderer unresponsive event if debugger is attached to the tab
2339 // since the event may be a result of the renderer sitting on a breakpoint.
2340 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442341 DevToolsAgentHost* agent =
2342 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2343 if (agent &&
2344 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532345 return;
2346
[email protected]420ae012009-04-24 05:16:322347 if (is_during_unload) {
2348 // Hang occurred while firing the beforeunload/unload handler.
2349 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582350 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322351
2352 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2353 return;
2354
2355 // If the tab hangs in the beforeunload/unload handler there's really
2356 // nothing we can do to recover. Pretend the unload listeners have
2357 // all fired and close the tab. If the hang is in the beforeunload handler
2358 // then the user will not have the option of cancelling the close.
2359 Close(rvh);
2360 return;
2361 }
2362
[email protected]9f76c1e2012-03-05 15:15:582363 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472364 return;
2365
[email protected]6934a702011-12-20 00:04:512366 if (delegate_)
2367 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322368}
2369
2370void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512371 if (delegate_)
2372 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322373}
2374
2375void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212376 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562377 uint64 upload_position,
2378 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322379 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562380 upload_position_ = upload_position;
2381 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502382 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202383 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302384 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212385 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322386 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462387 if (IsLoading()) {
2388 NotifyNavigationStateChanged(
2389 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2390 }
[email protected]420ae012009-04-24 05:16:322391}
2392
[email protected]7d472472011-01-22 01:30:252393void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512394 if (delegate_)
2395 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252396}
2397
[email protected]420ae012009-04-24 05:16:322398void TabContents::BeforeUnloadFiredFromRenderManager(
2399 bool proceed,
2400 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512401 if (delegate_)
2402 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322403}
2404
[email protected]3a3d47472010-07-15 21:03:542405void TabContents::DidStartLoadingFromRenderManager(
2406 RenderViewHost* render_view_host) {
2407 DidStartLoading();
2408}
2409
2410void TabContents::RenderViewGoneFromRenderManager(
2411 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232412 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2413 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542414}
2415
[email protected]420ae012009-04-24 05:16:322416void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102417 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262418 gfx::Size size = view_->GetContainerSize();
2419 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2420 // here during container initialization and normal window size will be set
2421 // later. In case of tab duplication this resizing to 0x0 prevents setting
2422 // normal size later so just ignore it.
2423 if (!size.IsEmpty())
2424 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322425}
2426
[email protected]3a3d47472010-07-15 21:03:542427void TabContents::NotifySwappedFromRenderManager() {
2428 NotifySwapped();
2429}
2430
[email protected]d202a7c2012-01-04 07:53:472431NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202432 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542433}
2434
[email protected]d2353452012-01-19 19:53:562435WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2436 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322437}
2438
[email protected]10f417c52011-12-28 21:04:232439NavigationEntry*
2440 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322441 return controller_.GetLastCommittedEntry();
2442}
2443
2444bool TabContents::CreateRenderViewForRenderManager(
2445 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442446 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322447 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522448
[email protected]420ae012009-04-24 05:16:322449 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442450 if (rwh_view)
2451 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322452
[email protected]74ce1ad2011-12-16 21:51:462453 // Make sure we use the correct starting page_id in the new RenderView.
2454 UpdateMaxPageIDIfNecessary(render_view_host);
2455 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582456 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462457
[email protected]9f76c1e2012-03-05 15:15:582458 if (!static_cast<RenderViewHostImpl*>(
2459 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522460 return false;
2461
[email protected]e60c0232011-11-11 19:56:352462#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502463 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2464 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442465 if (rwh_view) {
2466 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2467 render_widget_host->WasResized();
2468 }
[email protected]f8233cc2011-05-31 20:24:502469#endif
2470
[email protected]420ae012009-04-24 05:16:322471 return true;
2472}
2473
[email protected]fedec012012-01-28 03:09:342474void TabContents::OnDialogClosed(RenderViewHost* rvh,
2475 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072476 bool success,
2477 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542478 if (is_showing_before_unload_dialog_ && !success) {
2479 // If a beforeunload dialog is canceled, we need to stop the throbber from
2480 // spinning, since we forced it to start spinning in Navigate.
2481 DidStopLoading();
2482
2483 tab_close_start_time_ = base::TimeTicks();
2484 }
2485 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582486 static_cast<RenderViewHostImpl*>(
2487 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542488}
2489
[email protected]be1f56ab2011-12-22 06:55:312490void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122491 encoding_ = content::GetContentClient()->browser()->
2492 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102493}
[email protected]f45d2a72010-03-08 23:28:352494
[email protected]e30d68d2012-02-09 00:06:262495void TabContents::SaveURL(const GURL& url,
2496 const GURL& referrer,
2497 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142498 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2499 if (!dlm)
2500 return;
2501 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262502 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142503 const NavigationEntry* entry = controller_.GetActiveEntry();
2504 if (entry)
2505 post_id = entry->GetPostID();
2506 }
2507 DownloadSaveInfo save_info;
2508 save_info.prompt_for_save_location = true;
2509 dlm->DownloadUrl(url,
2510 referrer,
2511 "",
2512 true, // prefer_cache
2513 post_id,
2514 save_info,
2515 this);
2516}
2517
[email protected]33f74972010-12-08 16:40:362518void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212519 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442520 // Can be NULL during tests.
2521 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212522 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362523}
[email protected]9f76c1e2012-03-05 15:15:582524
2525RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2526 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2527}