blob: ee370265809119197486d9dfea311afc8f1245b0 [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]686493142011-07-15 21:47:2230#include "content/browser/renderer_host/resource_dispatcher_host.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]adbfb8df2012-02-24 01:19:43133using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33134using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17135using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38136using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09137using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25138using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56139using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22140using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50141using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44142
[email protected]420ae012009-04-24 05:16:32143namespace {
144
145// Amount of time we wait between when a key event is received and the renderer
146// is queried for its state and pushed to the NavigationEntry.
147const int kQueryStateDelay = 5000;
148
[email protected]6ebdc9b2010-09-27 16:55:57149const int kSyncWaitDelay = 40;
150
[email protected]ca406032011-07-19 21:53:05151static const char kDotGoogleDotCom[] = ".google.com";
152
[email protected]420ae012009-04-24 05:16:32153#if defined(OS_WIN)
154
155BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
156 // Note: erase is required to properly paint some widgets borders. This can
157 // be seen with textfields.
158 InvalidateRect(hwnd, NULL, TRUE);
159 return TRUE;
160}
161#endif
162
[email protected]2c5569662011-03-22 20:45:02163ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23164 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50165 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16166 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47167 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02168 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47169 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02170 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47171 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16172 break; // Fall through to rest of function.
173 }
[email protected]5e369672009-11-03 23:48:30174
[email protected]59246c572012-02-10 13:32:13175 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
176 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23177 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13178 browser_context->DidLastSessionExitCleanly()) {
179 if (entry.GetHasPostData())
180 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02181 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13182 }
[email protected]5e369672009-11-03 23:48:30183
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30185}
186
[email protected]10f417c52011-12-28 21:04:23187void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47188 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42189 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50190 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16191 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51192 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54193 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55194 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
195 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51196 params->url = entry.GetURL();
197 params->referrer = entry.GetReferrer();
198 params->transition = entry.GetTransitionType();
199 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00200 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55201 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34202 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47203 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48204 params->transferred_request_child_id =
205 entry.transferred_global_request_id().child_id;
206 params->transferred_request_request_id =
207 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47208
209 if (delegate)
210 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34211}
212
[email protected]420ae012009-04-24 05:16:32213} // namespace
214
[email protected]a81343d232011-12-27 07:39:20215namespace content {
216
217WebContents* WebContents::Create(
218 BrowserContext* browser_context,
219 SiteInstance* site_instance,
220 int routing_id,
221 const WebContents* base_tab_contents,
222 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43223 return new TabContents(
224 browser_context,
225 site_instance,
226 routing_id,
227 static_cast<const TabContents*>(base_tab_contents),
228 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20229}
230}
[email protected]f4f50ef2011-01-21 19:01:19231
232// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32233
[email protected]3d7474ff2011-07-27 17:47:37234TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32235 SiteInstance* site_instance,
236 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07237 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43238 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42239 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07240 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37241 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13242 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10243 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22244 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34245 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23246 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
247 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34248 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21249 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56250 upload_size_(0),
251 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47252 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57253 capturing_contents_(false),
254 is_being_destroyed_(false),
255 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55256 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57257#if defined(OS_WIN)
258 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
259#endif
[email protected]7ab1e7d62009-10-14 23:32:01260 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56261 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38262 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25263 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01264 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25265 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01266 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00267 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43268 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50269 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
270 has_opener_(false) {
[email protected]3d7474ff2011-07-27 17:47:37271 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32272
[email protected]34ac70502009-09-25 17:07:23273 // We have the initial size of the view be based on the size of the passed in
274 // tab contents (normally a tab from the same window).
275 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21276 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00277
278#if defined(ENABLE_JAVA_BRIDGE)
279 java_bridge_dispatcher_host_manager_.reset(
280 new JavaBridgeDispatcherHostManager(this));
281#endif
[email protected]332af7732009-03-11 13:21:35282}
initial.commit09911bf2008-07-26 23:55:29283
284TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32285 is_being_destroyed_ = true;
286
[email protected]3ab9cb82011-06-03 18:02:07287 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55288 if (dialog_creator_)
289 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07290
[email protected]420ae012009-04-24 05:16:32291 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32292
[email protected]420ae012009-04-24 05:16:32293 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07294 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09295 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
296 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07297 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32298
299 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07300#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32301 // If we still have a window handle, destroy it. GetNativeView can return
302 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42303 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52304 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58305 if (host && host->GetView())
306 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42307 }
[email protected]420ae012009-04-24 05:16:32308#endif
[email protected]7ab1e7d62009-10-14 23:32:01309
310 // OnCloseStarted isn't called in unit tests.
311 if (!tab_close_start_time_.is_null()) {
312 UMA_HISTOGRAM_TIMES("Tab.Close",
313 base::TimeTicks::Now() - tab_close_start_time_);
314 }
[email protected]b5a1d11c2011-02-17 03:09:42315
[email protected]d8c660432011-12-22 20:51:25316 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08317
[email protected]6934a702011-12-20 00:04:51318 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42319}
320
[email protected]64d69de42012-02-06 00:19:54321WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
322 const GURL& url) {
323 WebPreferences prefs;
324
325 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
326
327 prefs.developer_extras_enabled = true;
328 prefs.javascript_enabled =
329 !command_line.HasSwitch(switches::kDisableJavaScript);
330 prefs.web_security_enabled =
331 !command_line.HasSwitch(switches::kDisableWebSecurity);
332 prefs.plugins_enabled =
333 !command_line.HasSwitch(switches::kDisablePlugins);
334 prefs.java_enabled =
335 !command_line.HasSwitch(switches::kDisableJava);
336
337 prefs.uses_page_cache =
338 command_line.HasSwitch(switches::kEnableFastback);
339 prefs.remote_fonts_enabled =
340 !command_line.HasSwitch(switches::kDisableRemoteFonts);
341 prefs.xss_auditor_enabled =
342 !command_line.HasSwitch(switches::kDisableXSSAuditor);
343 prefs.application_cache_enabled =
344 !command_line.HasSwitch(switches::kDisableApplicationCache);
345
346 prefs.local_storage_enabled =
347 !command_line.HasSwitch(switches::kDisableLocalStorage);
348 prefs.databases_enabled =
349 !command_line.HasSwitch(switches::kDisableDatabases);
350 prefs.webaudio_enabled =
351 !command_line.HasSwitch(switches::kDisableWebAudio);
352
353 prefs.experimental_webgl_enabled =
354 GpuProcessHost::gpu_enabled() &&
355 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
356 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
357
358 prefs.gl_multisampling_enabled =
359 !command_line.HasSwitch(switches::kDisableGLMultisampling);
360 prefs.privileged_webgl_extensions_enabled =
361 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
362 prefs.site_specific_quirks_enabled =
363 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
364 prefs.allow_file_access_from_file_urls =
365 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
366 prefs.show_composited_layer_borders =
367 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
368 prefs.show_composited_layer_tree =
369 command_line.HasSwitch(switches::kShowCompositedLayerTree);
370 prefs.show_fps_counter =
371 command_line.HasSwitch(switches::kShowFPSCounter);
372 prefs.accelerated_compositing_enabled =
373 GpuProcessHost::gpu_enabled() &&
374 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
375 prefs.threaded_compositing_enabled =
376 command_line.HasSwitch(switches::kEnableThreadedCompositing);
377 prefs.force_compositing_mode =
378 command_line.HasSwitch(switches::kForceCompositingMode);
379 prefs.fixed_position_compositing_enabled =
380 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
381 prefs.accelerated_2d_canvas_enabled =
382 GpuProcessHost::gpu_enabled() &&
383 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58384 prefs.deferred_2d_canvas_enabled =
385 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36386 prefs.threaded_animation_enabled =
387 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54388 prefs.accelerated_painting_enabled =
389 GpuProcessHost::gpu_enabled() &&
390 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
391 prefs.accelerated_filters_enabled =
392 GpuProcessHost::gpu_enabled() &&
393 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
394 prefs.accelerated_layers_enabled =
395 prefs.accelerated_animation_enabled =
396 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
397 prefs.composite_to_texture_enabled =
398 command_line.HasSwitch(switches::kEnableCompositeToTexture);
399 prefs.accelerated_plugins_enabled =
400 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
401 prefs.accelerated_video_enabled =
402 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
403 prefs.partial_swap_enabled =
404 command_line.HasSwitch(switches::kEnablePartialSwap);
405 prefs.interactive_form_validation_enabled =
406 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
407 prefs.fullscreen_enabled =
408 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16409 prefs.css_regions_enabled =
410 command_line.HasSwitch(switches::kEnableCssRegions);
411
[email protected]64d69de42012-02-06 00:19:54412
413#if defined(OS_MACOSX)
414 bool default_enable_scroll_animator = true;
415#else
416 // On CrOS, the launcher always passes in the --enable flag.
417 bool default_enable_scroll_animator = false;
418#endif
419 prefs.enable_scroll_animator = default_enable_scroll_animator;
420 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
421 prefs.enable_scroll_animator = true;
422 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
423 prefs.enable_scroll_animator = false;
424
425 prefs.visual_word_movement_enabled =
426 command_line.HasSwitch(switches::kEnableVisualWordMovement);
427 prefs.per_tile_painting_enabled =
428 command_line.HasSwitch(switches::kEnablePerTilePainting);
429
430 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32431 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54432 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11433 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
434 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54435 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11436 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54437 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11438 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54439 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11440 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54441 prefs.gl_multisampling_enabled = false;
442
443 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45444 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32445 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54446 prefs.accelerated_video_enabled = false;
447 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45448 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54449 }
450 }
451
[email protected]b9535422012-02-09 01:47:59452 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58453 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54454 prefs.loads_images_automatically = true;
455 prefs.javascript_enabled = true;
456 }
457
458 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
459
460 // Force accelerated compositing and 2d canvas off for chrome:, about: and
461 // chrome-devtools: pages (unless it's specifically allowed).
462 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54463 url.SchemeIs(chrome::kChromeUIScheme) ||
464 (url.SchemeIs(chrome::kAboutScheme) &&
465 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25466 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54467 prefs.accelerated_compositing_enabled = false;
468 prefs.accelerated_2d_canvas_enabled = false;
469 }
470
[email protected]43d9d782012-03-01 15:40:09471 int default_device_scale_factor;
472 base::StringToInt(command_line.GetSwitchValueASCII(
473 switches::kDefaultDeviceScaleFactor),
474 &default_device_scale_factor);
475
476 prefs.default_device_scale_factor = default_device_scale_factor;
477
[email protected]2e21fe292012-03-02 22:52:32478 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54479
480 return prefs;
481}
482
[email protected]d202a7c2012-01-04 07:53:47483NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20484 return controller_;
485}
486
[email protected]765187182012-01-11 23:59:28487RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
488 return &render_manager_;
489}
490
[email protected]724159a2010-12-30 01:11:18491bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56492 if (GetWebUI() &&
493 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17494 return true;
[email protected]d2353452012-01-19 19:53:56495 }
[email protected]f82d57b52011-04-27 19:13:17496
[email protected]d8c660432011-12-22 20:51:25497 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
498 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10499 while ((observer = it.GetNext()) != NULL)
500 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53501 return true;
[email protected]403415a2011-01-10 18:57:53502
[email protected]724159a2010-12-30 01:11:18503 bool handled = true;
504 bool message_is_ok = true;
505 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58506 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
507 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24508 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
509 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18510 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
511 OnDidStartProvisionalLoadForFrame)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
513 OnDidRedirectProvisionalLoad)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
515 OnDidFailProvisionalLoadWithError)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
517 OnDidLoadResourceFromMemoryCache)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
519 OnDidDisplayInsecureContent)
520 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
521 OnDidRunInsecureContent)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
523 OnDocumentLoadedInFrame)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17525 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
526 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25527 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26528 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59529 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21530 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20531 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
533 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16534 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45535 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10536 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18537 IPC_MESSAGE_UNHANDLED(handled = false)
538 IPC_END_MESSAGE_MAP_EX()
539
540 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38541 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18542 GetRenderProcessHost()->ReceivedBadMessage();
543 }
544
545 return handled;
546}
547
[email protected]6c2e472f2011-08-24 23:26:18548void TabContents::RunFileChooser(
549 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23550 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51551 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18552}
553
[email protected]c5eed492012-01-04 17:07:50554NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56555 return controller_;
556}
557
[email protected]c5eed492012-01-04 17:07:50558const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56559 return controller_;
560}
561
[email protected]627e0512011-12-21 22:55:30562content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55563 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30564}
565
[email protected]f5fa20e2011-12-21 22:35:56566void TabContents::SetViewType(content::ViewType type) {
567 view_type_ = type;
568}
569
[email protected]ea049a02011-12-25 21:37:09570content::ViewType TabContents::GetViewType() const {
571 return view_type_;
572}
573
[email protected]be1f56ab2011-12-22 06:55:31574const GURL& TabContents::GetURL() const {
575 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23576 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51577 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31578}
579
580
581const base::PropertyBag* TabContents::GetPropertyBag() const {
582 return &property_bag_;
583}
584
585base::PropertyBag* TabContents::GetPropertyBag() {
586 return &property_bag_;
587}
588
589content::WebContentsDelegate* TabContents::GetDelegate() {
590 return delegate_;
591}
592
593void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
594 // TODO(cbentzel): remove this debugging code?
595 if (delegate == delegate_)
596 return;
597 if (delegate_)
598 delegate_->Detach(this);
599 delegate_ = delegate;
600 if (delegate_)
601 delegate_->Attach(this);
602}
603
[email protected]f3b1a082011-11-18 00:34:30604content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03605 if (render_manager_.current_host())
[email protected]9f76c1e2012-03-05 15:15:58606 return render_manager_.current_host()->GetProcess();
[email protected]4d0df262011-10-03 20:05:03607 else
608 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16609}
610
[email protected]be1f56ab2011-12-22 06:55:31611RenderViewHost* TabContents::GetRenderViewHost() const {
612 return render_manager_.current_host();
613}
614
615RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
616 return render_manager_.GetRenderWidgetHostView();
617}
618
[email protected]8643e6d2012-01-18 20:26:10619content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31620 return view_.get();
621}
622
[email protected]01ec4ec2012-01-18 04:13:47623content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50624 WebUIControllerFactory* factory =
625 content::GetContentClient()->browser()->GetWebUIControllerFactory();
626 if (!factory)
627 return NULL;
[email protected]d2353452012-01-19 19:53:56628 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22629 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50630 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22631 if (controller) {
632 web_ui->SetController(controller);
633 return web_ui;
634 }
635
636 delete web_ui;
637 return NULL;
638}
639
[email protected]01ec4ec2012-01-18 04:13:47640content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31641 return render_manager_.web_ui() ? render_manager_.web_ui()
642 : render_manager_.pending_web_ui();
643}
644
[email protected]01ec4ec2012-01-18 04:13:47645content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31646 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34647}
648
[email protected]96d185d2009-04-24 03:28:54649const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55650 // Transient entries take precedence. They are used for interstitial pages
651 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23652 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08653 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20654 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30655 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23656 if (entry) {
[email protected]b5cca982011-05-26 04:42:08657 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23658 }
[email protected]7ade2732011-02-10 00:13:58659 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
660 render_manager_.pending_web_ui() : render_manager_.web_ui();
661 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54662 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55663 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54664 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35665 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22666 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54667 if (!title.empty())
668 return title;
669 }
670 }
671
672 // We use the title for the last committed entry rather than a pending
673 // navigation entry. For example, when the user types in a URL, we want to
674 // keep the old page's title until the new load has committed and we get a new
675 // title.
[email protected]96d185d2009-04-24 03:28:54676 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23677 if (entry) {
[email protected]b5cca982011-05-26 04:42:08678 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23679 }
[email protected]987fc3a2011-05-26 14:18:09680
681 // |page_title_when_no_navigation_entry_| is finally used
682 // if no title cannot be retrieved.
683 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54684}
685
[email protected]d5f942ba2008-09-26 19:30:34686int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46687 return GetMaxPageIDForSiteInstance(GetSiteInstance());
688}
689
690int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33691 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
692 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46693
[email protected]b6583592012-01-25 19:52:33694 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34695}
696
697void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46698 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
699}
700
[email protected]b6583592012-01-25 19:52:33701void TabContents::UpdateMaxPageIDForSiteInstance(
702 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46703 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33704 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34705}
706
[email protected]91854cd2012-01-10 19:43:57707void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
708 max_page_ids_ = tab_contents->max_page_ids_;
709}
710
[email protected]96d185d2009-04-24 03:28:54711SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58712 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54713}
714
[email protected]77362eb2011-08-01 17:18:38715SiteInstance* TabContents::GetPendingSiteInstance() const {
716 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
717 render_manager_.pending_render_view_host() :
718 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58719 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38720}
721
[email protected]be1f56ab2011-12-22 06:55:31722bool TabContents::IsLoading() const {
723 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49724}
725
[email protected]be1f56ab2011-12-22 06:55:31726bool TabContents::IsWaitingForResponse() const {
727 return waiting_for_response_;
728}
729
730const net::LoadStateWithParam& TabContents::GetLoadState() const {
731 return load_state_;
732}
733
734const string16& TabContents::GetLoadStateHost() const {
735 return load_state_host_;
736}
737
738uint64 TabContents::GetUploadSize() const {
739 return upload_size_;
740}
741
742uint64 TabContents::GetUploadPosition() const {
743 return upload_position_;
744}
745
746const std::string& TabContents::GetEncoding() const {
747 return encoding_;
748}
749
750bool TabContents::DisplayedInsecureContent() const {
751 return displayed_insecure_content_;
752}
753
754void TabContents::SetCapturingContents(bool cap) {
755 capturing_contents_ = cap;
756}
757
758bool TabContents::IsCrashed() const {
759 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
760 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
761 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49762}
763
[email protected]443b80e2010-12-14 00:42:23764void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
765 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34766 return;
767
[email protected]443b80e2010-12-14 00:42:23768 crashed_status_ = status;
769 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46770 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34771}
772
[email protected]be1f56ab2011-12-22 06:55:31773base::TerminationStatus TabContents::GetCrashedStatus() const {
774 return crashed_status_;
775}
776
777bool TabContents::IsBeingDestroyed() const {
778 return is_being_destroyed_;
779}
780
[email protected]d5f942ba2008-09-26 19:30:34781void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
782 if (delegate_)
783 delegate_->NavigationStateChanged(this, changed_flags);
784}
785
[email protected]96d185d2009-04-24 03:28:54786void TabContents::DidBecomeSelected() {
787 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04788 RenderWidgetHostViewPort* rwhv =
789 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16790 if (rwhv) {
791 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43792#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16793 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43794#endif
795 }
[email protected]96d185d2009-04-24 03:28:54796
[email protected]5ac20162010-11-24 23:33:11797 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38798
[email protected]d8c660432011-12-22 20:51:25799 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59800
801 // The resize rect might have changed while this was inactive -- send the new
802 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58803 RenderViewHostImpl* rvh =
804 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59805 if (rvh) {
806 rvh->ResizeRectChanged(GetRootWindowResizerRect());
807 }
[email protected]96d185d2009-04-24 03:28:54808}
809
[email protected]be1f56ab2011-12-22 06:55:31810
811base::TimeTicks TabContents::GetLastSelectedTime() const {
812 return last_selected_time_;
813}
814
[email protected]96d185d2009-04-24 03:28:54815void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31816 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52817 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
818 // open a tab in then background, then closes the tab before selecting it.
819 // This is because closing the tab calls TabContents::Destroy(), which
820 // removes the |GetRenderViewHost()|; then when we actually destroy the
821 // window, OnWindowPosChanged() notices and calls HideContents() (which
822 // calls us).
[email protected]c30585c2012-02-16 15:02:04823 RenderWidgetHostViewPort* rwhv =
824 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16825 if (rwhv)
826 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54827 }
828
[email protected]ad50def52011-10-19 23:17:07829 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09830 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
831 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07832 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54833}
834
[email protected]be1f56ab2011-12-22 06:55:31835void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04836 RenderWidgetHostViewPort* rwhv =
837 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31838 if (rwhv)
839 rwhv->DidBecomeSelected();
840}
841
842void TabContents::HideContents() {
843 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
844 // our superclass HideContents(), because some callers want to be very picky
845 // about the order in which these get called. In addition to making the code
846 // here practically impossible to understand, this also means we end up
847 // calling TabContents::WasHidden() twice if callers call both versions of
848 // HideContents() on a TabContents.
849 WasHidden();
850}
851
852bool TabContents::NeedToFireBeforeUnload() {
853 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27854 return WillNotifyDisconnection() &&
855 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58856 !static_cast<RenderViewHostImpl*>(
857 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31858}
859
[email protected]0bfbf882011-12-22 18:19:27860void TabContents::Stop() {
861 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25862 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27863}
864
[email protected]d9083482012-01-06 00:38:46865WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27866 // We create a new SiteInstance so that the new tab won't share processes
867 // with the old one. This can be changed in the future if we need it to share
868 // processes for some reason.
869 TabContents* tc = new TabContents(
870 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33871 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27872 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20873 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27874 return tc;
875}
876
[email protected]2a6bc3e2011-12-28 23:51:33877void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27878 WindowOpenDisposition disposition,
879 const gfx::Rect& initial_pos,
880 bool user_gesture) {
881 if (!delegate_)
882 return;
883
884 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
885 user_gesture);
886}
887
888gfx::NativeView TabContents::GetContentNativeView() const {
889 return view_->GetContentNativeView();
890}
891
892gfx::NativeView TabContents::GetNativeView() const {
893 return view_->GetNativeView();
894}
895
896void TabContents::GetContainerBounds(gfx::Rect* out) const {
897 view_->GetContainerBounds(out);
898}
899
900void TabContents::Focus() {
901 view_->Focus();
902}
903
[email protected]d8c660432011-12-22 20:51:25904void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31905 observers_.AddObserver(observer);
906}
907
[email protected]d8c660432011-12-22 20:51:25908void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31909 observers_.RemoveObserver(observer);
910}
911
[email protected]d5f942ba2008-09-26 19:30:34912void TabContents::Activate() {
913 if (delegate_)
914 delegate_->ActivateContents(this);
915}
916
[email protected]ea42e7782010-08-23 23:58:12917void TabContents::Deactivate() {
918 if (delegate_)
919 delegate_->DeactivateContents(this);
920}
921
[email protected]63954792011-07-11 04:17:48922void TabContents::LostCapture() {
923 if (delegate_)
924 delegate_->LostCapture();
925}
926
927bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
928 bool* is_keyboard_shortcut) {
929 return delegate_ &&
930 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
931}
932
933void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
934 if (delegate_)
935 delegate_->HandleKeyboardEvent(event);
936}
937
[email protected]32ded2212011-11-10 18:51:43938void TabContents::HandleMouseDown() {
939 if (delegate_)
940 delegate_->HandleMouseDown();
941}
942
[email protected]63954792011-07-11 04:17:48943void TabContents::HandleMouseUp() {
944 if (delegate_)
945 delegate_->HandleMouseUp();
946}
947
948void TabContents::HandleMouseActivate() {
949 if (delegate_)
950 delegate_->HandleMouseActivate();
951}
952
[email protected]8a5e0ca2011-08-25 06:30:47953void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
954 if (delegate_)
955 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
956}
957
[email protected]5d5f7af2011-10-01 01:38:12958bool TabContents::IsFullscreenForCurrentTab() const {
959 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
960}
961
[email protected]e9621112011-10-17 05:38:37962void TabContents::RequestToLockMouse() {
963 if (delegate_) {
964 delegate_->RequestToLockMouse(this);
965 } else {
966 GotResponseToLockMouseRequest(false);
967 }
968}
969
970void TabContents::LostMouseLock() {
971 if (delegate_)
972 delegate_->LostMouseLock();
973}
974
[email protected]0548c5352011-09-07 00:33:33975void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23976 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33977 if (delegate_)
978 delegate_->UpdatePreferredSize(this, pref_size);
979}
980
[email protected]61e2b3cc2012-03-02 16:13:34981void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
982 if (delegate_)
983 delegate_->ResizeDueToAutoResize(this, new_size);
984}
985
[email protected]32ded2212011-11-10 18:51:43986void TabContents::WebUISend(RenderViewHost* render_view_host,
987 const GURL& source_url,
988 const std::string& name,
989 const base::ListValue& args) {
990 if (delegate_)
991 delegate_->WebUISend(this, source_url, name, args);
992}
993
[email protected]e5d549d2011-12-28 01:29:20994WebContents* TabContents::OpenURL(const OpenURLParams& params) {
995 if (!delegate_)
996 return NULL;
[email protected]00c37fc2011-08-02 00:22:50997
[email protected]e5d549d2011-12-28 01:29:20998 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
999 // Notify observers.
1000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1001 DidOpenURL(params.url, params.referrer,
1002 params.disposition, params.transition));
1003 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341004}
1005
[email protected]1ccb3568d2010-02-19 10:51:161006bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501007 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251008 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231009 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251010 reload_type);
[email protected]876bc832010-09-07 16:29:541011}
[email protected]96d185d2009-04-24 03:28:541012
[email protected]876bc832010-09-07 16:29:541013bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231014 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501015 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401016 // The renderer will reject IPC messages with URLs longer than
1017 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511018 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401019 return false;
1020
[email protected]9f76c1e2012-03-05 15:15:581021 RenderViewHostImpl* dest_render_view_host =
1022 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401023 if (!dest_render_view_host)
1024 return false; // Unable to create the desired render view host.
1025
[email protected]80a8fad2011-01-29 04:02:381026 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071027 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581028 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501029 WebUIControllerFactory* factory =
1030 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1031 bool is_allowed_in_web_ui_renderer =
1032 factory &&
1033 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431034#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511035 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431036#endif
[email protected]e091df82011-10-11 18:13:211037 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551038 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581039
[email protected]96d185d2009-04-24 03:28:541040 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441041 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521042 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441043 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511044 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541045
1046 // Used for page load time metrics.
1047 current_load_start_ = base::TimeTicks::Now();
1048
1049 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341050 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271051 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471052 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341053 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541054
[email protected]36fc0392011-12-25 03:59:511055 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541056 // HACK!! This code suppresses javascript: URLs from being added to
1057 // session history, which is what we want to do for javascript: URLs that
1058 // do not generate content. What we really need is a message from the
1059 // renderer telling us that a new page was not created. The same message
1060 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511061 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541062 return false;
1063 }
1064
[email protected]3c9e1872010-11-18 16:17:491065 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251066 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041067 observers_,
[email protected]36fc0392011-12-25 03:59:511068 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541069
[email protected]09b29342011-06-24 19:18:481070 if (delegate_)
1071 delegate_->DidNavigateToPendingEntry(this);
1072
[email protected]d5f942ba2008-09-26 19:30:341073 return true;
1074}
1075
[email protected]b6583592012-01-25 19:52:331076void TabContents::SetHistoryLengthAndPrune(
1077 const SiteInstance* site_instance,
1078 int history_length,
1079 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411080 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1081 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191082 if (render_manager_.pending_render_view_host()) {
1083 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141084 return;
[email protected]9e1ad4b2011-08-14 16:49:191085 }
[email protected]9f76c1e2012-03-05 15:15:581086 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191087 if (!rvh) {
1088 NOTREACHED();
1089 return;
1090 }
[email protected]9f76c1e2012-03-05 15:15:581091 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191092 NOTREACHED();
1093 return;
1094 }
[email protected]9f76c1e2012-03-05 15:15:581095 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191096 history_length,
1097 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141098}
1099
[email protected]90daadb42009-06-08 21:27:281100void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271101 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541102 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1103 return;
1104 }
[email protected]9f76c1e2012-03-05 15:15:581105 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541106}
1107
[email protected]0bfbf882011-12-22 18:19:271108bool TabContents::ShowingInterstitialPage() const {
1109 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541110}
1111
[email protected]0bfbf882011-12-22 18:19:271112InterstitialPage* TabContents::GetInterstitialPage() const {
1113 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221114}
1115
[email protected]a53209b2012-01-20 16:48:161116bool TabContents::IsSavable() {
1117 // WebKit creates Document object when MIME type is application/xhtml+xml,
1118 // so we also support this MIME type.
1119 return contents_mime_type_ == "text/html" ||
1120 contents_mime_type_ == "text/xml" ||
1121 contents_mime_type_ == "application/xhtml+xml" ||
1122 contents_mime_type_ == "text/plain" ||
1123 contents_mime_type_ == "text/css" ||
1124 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1125}
1126
[email protected]c7dd2f62011-07-18 15:57:591127void TabContents::OnSavePage() {
1128 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161129 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481130 download_stats::RecordDownloadSource(
1131 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261132 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141133 return;
[email protected]c7dd2f62011-07-18 15:57:591134 }
1135
1136 Stop();
1137
1138 // Create the save package and possibly prompt the user for the name to save
1139 // the page as. The user prompt is an asynchronous operation that runs on
1140 // another thread.
1141 save_package_ = new SavePackage(this);
1142 save_package_->GetSaveInfo();
1143}
1144
1145// Used in automated testing to bypass prompting the user for file names.
1146// Instead, the names and paths are hard coded rather than running them through
1147// file name sanitation and extension / mime checking.
1148bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161149 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591150 // Stop the page from navigating.
1151 Stop();
1152
1153 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1154 return save_package_->Init();
1155}
1156
[email protected]aa4f3972012-03-01 18:12:121157void TabContents::GenerateMHTML(
1158 const FilePath& file,
1159 const base::Callback<void(const FilePath&, int64)>& callback) {
1160 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1161}
1162
[email protected]420ae012009-04-24 05:16:321163bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231164 NavigationEntryImpl* active_entry =
1165 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321166 return (active_entry != NULL &&
1167 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511168 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321169}
1170
[email protected]0bfbf882011-12-22 18:19:271171const std::string& TabContents::GetContentsMimeType() const {
1172 return contents_mime_type_;
1173}
1174
1175bool TabContents::WillNotifyDisconnection() const {
1176 return notify_disconnection_;
1177}
1178
[email protected]b2fe07d12010-02-09 14:38:081179void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311180 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581181 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1182 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161183}
1184
[email protected]b2fe07d12010-02-09 14:38:081185void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311186 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581187 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1188 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161189}
1190
[email protected]0bfbf882011-12-22 18:19:271191content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1192 return &renderer_preferences_;
1193}
1194
1195void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1196 new_tab_start_time_ = time;
1197}
1198
1199base::TimeTicks TabContents::GetNewTabStartTime() const {
1200 return new_tab_start_time_;
1201}
1202
[email protected]7ab1e7d62009-10-14 23:32:011203void TabContents::OnCloseStarted() {
1204 if (tab_close_start_time_.is_null())
1205 tab_close_start_time_ = base::TimeTicks::Now();
1206}
1207
[email protected]46624bf2010-06-09 16:04:191208bool TabContents::ShouldAcceptDragAndDrop() const {
1209#if defined(OS_CHROMEOS)
1210 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1211 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511212 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201213 return false;
1214 return true;
[email protected]46624bf2010-06-09 16:04:191215#else
1216 return true;
1217#endif
1218}
1219
[email protected]7813bd72011-02-05 02:19:341220void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521221 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581222 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511223 if (delegate_)
1224 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341225}
1226
[email protected]0bfbf882011-12-22 18:19:271227void TabContents::SetClosedByUserGesture(bool value) {
1228 closed_by_user_gesture_ = value;
1229}
1230
1231bool TabContents::GetClosedByUserGesture() const {
1232 return closed_by_user_gesture_;
1233}
1234
[email protected]d0b8d092010-10-25 04:05:171235double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051236 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561237 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251238 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171239 return 0;
[email protected]b75b8292010-10-01 07:28:251240
1241 double zoom_level;
1242 if (temporary_zoom_settings_) {
1243 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581244 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251245 } else {
[email protected]2ae88d12011-10-14 09:11:191246 GURL url;
[email protected]10f417c52011-12-28 21:04:231247 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191248 // Since zoom map is updated using rewritten URL, use rewritten URL
1249 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511250 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191251 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251252 }
[email protected]d0b8d092010-10-25 04:05:171253 return zoom_level;
1254}
[email protected]b75b8292010-10-01 07:28:251255
[email protected]d0b8d092010-10-25 04:05:171256int TabContents::GetZoomPercent(bool* enable_increment,
1257 bool* enable_decrement) {
1258 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011259 // Calculate the zoom percent from the factor. Round up to the nearest whole
1260 // number.
[email protected]b75b8292010-10-01 07:28:251261 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011262 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251263 *enable_decrement = percent > minimum_zoom_percent_;
1264 *enable_increment = percent < maximum_zoom_percent_;
1265 return percent;
1266}
1267
[email protected]3c733bde2010-12-21 19:56:311268void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501269 if (!delegate_)
1270 return;
1271
[email protected]10f417c52011-12-28 21:04:231272 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501273 if (!active_entry)
1274 return;
1275
[email protected]36fc0392011-12-25 03:59:511276 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121277}
1278
[email protected]932b7a12011-03-09 12:50:271279void TabContents::ViewFrameSource(const GURL& url,
1280 const std::string& content_state) {
1281 if (!delegate_)
1282 return;
1283
1284 delegate_->ViewSourceForFrame(this, url, content_state);
1285}
1286
[email protected]0bfbf882011-12-22 18:19:271287int TabContents::GetMinimumZoomPercent() const {
1288 return minimum_zoom_percent_;
1289}
1290
1291int TabContents::GetMaximumZoomPercent() const {
1292 return maximum_zoom_percent_;
1293}
1294
[email protected]bcd2815602012-01-14 18:17:231295gfx::Size TabContents::GetPreferredSize() const {
1296 return preferred_size_;
1297}
1298
[email protected]0bfbf882011-12-22 18:19:271299int TabContents::GetContentRestrictions() const {
1300 return content_restrictions_;
1301}
1302
1303WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501304 WebUIControllerFactory* factory =
1305 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1306 if (!factory)
1307 return WebUI::kNoWebUI;
1308 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271309}
1310
[email protected]01ec4ec2012-01-18 04:13:471311content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271312 // When there is a pending navigation entry, we want to use the pending WebUI
1313 // that goes along with it to control the basic flags. For example, we want to
1314 // show the pending URL in the URL bar, so we want the display_url flag to
1315 // be from the pending entry.
1316 //
1317 // The confusion comes because there are multiple possibilities for the
1318 // initial load in a tab as a side effect of the way the RenderViewHostManager
1319 // works.
1320 //
1321 // - For the very first tab the load looks "normal". The new tab Web UI is
1322 // the pending one, and we want it to apply here.
1323 //
1324 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1325 // get switched to the one previously associated with the new tab pages.
1326 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1327 // have a committed Web UI in this case.
1328 //
1329 // This condition handles all of these cases:
1330 //
1331 // - First load in first tab: no committed nav entry + pending nav entry +
1332 // pending dom ui:
1333 // -> Use pending Web UI if any.
1334 //
1335 // - First load in second tab: no committed nav entry + pending nav entry +
1336 // no pending Web UI:
1337 // -> Use the committed Web UI if any.
1338 //
1339 // - Second navigation in any tab: committed nav entry + pending nav entry:
1340 // -> Use pending Web UI if any.
1341 //
1342 // - Normal state with no load: committed nav entry + no pending nav entry:
1343 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251344 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271345 (controller_.GetLastCommittedEntry() ||
1346 render_manager_.pending_web_ui()))
1347 return render_manager_.pending_web_ui();
1348 return render_manager_.web_ui();
1349}
1350
1351bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1352 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581353 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271354}
1355
[email protected]a0358d72012-03-09 14:06:501356bool TabContents::HasOpener() const {
1357 return has_opener_;
1358}
1359
[email protected]0bfbf882011-12-22 18:19:271360bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471361 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271362 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221363 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231364 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511365 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271366 return true;
1367 return false;
1368}
1369
1370void TabContents::SetFocusToLocationBar(bool select_all) {
1371 if (delegate_)
1372 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211373}
1374
[email protected]8b5af492011-11-28 21:50:581375void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301376 const string16& type,
1377 const string16& href,
1378 const string16& title,
1379 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511380 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301381 this, action, type, href, title, disposition);
1382}
1383
[email protected]678105012011-12-09 04:01:211384void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301385 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001386 WebIntentsDispatcherImpl* intents_dispatcher =
1387 new WebIntentsDispatcherImpl(this, intent, intent_id);
1388 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301389}
1390
[email protected]724159a2010-12-30 01:11:181391void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1392 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591393 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181394 const GURL& url) {
1395 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1396 GURL validated_url(url);
[email protected]9f76c1e2012-03-05 15:15:581397 GetRenderViewHostImpl()->FilterURL(
1398 ChildProcessSecurityPolicyImpl::GetInstance(),
1399 GetRenderProcessHost()->GetID(),
1400 &validated_url);
[email protected]724159a2010-12-30 01:11:181401
[email protected]8093a542011-05-13 07:29:321402 RenderViewHost* rvh =
1403 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521404 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101405 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251406 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101407 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321408 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101409
[email protected]724159a2010-12-30 01:11:181410 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591411 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251412 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591413 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181414 }
1415}
1416
1417void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591418 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181419 const GURL& source_url,
1420 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491421 // TODO(creis): Remove this method and have the pre-rendering code listen to
1422 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1423 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231424 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181425 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251426 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181427 else
1428 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511429 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181430 return;
[email protected]e7d50892011-01-19 21:47:381431
[email protected]4850a7f2011-03-08 23:36:591432 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251433 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261434 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591435 opener_url));
[email protected]724159a2010-12-30 01:11:181436}
1437
1438void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581439 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1440 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1441 << ", error_code: " << params.error_code
1442 << ", error_description: " << params.error_description
1443 << ", is_main_frame: " << params.is_main_frame
1444 << ", showing_repost_interstitial: " <<
1445 params.showing_repost_interstitial
1446 << ", frame_id: " << params.frame_id;
1447 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581448 GetRenderViewHostImpl()->FilterURL(
1449 ChildProcessSecurityPolicyImpl::GetInstance(),
1450 GetRenderProcessHost()->GetID(),
1451 &validated_url);
[email protected]724159a2010-12-30 01:11:181452
[email protected]d7b175e2011-10-11 15:31:581453 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181454 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1455 // This means that the interstitial won't be torn down properly, which is
1456 // bad. But if we have an interstitial, go back to another tab type, and
1457 // then load the same interstitial again, we could end up getting the first
1458 // interstitial's "failed" message (as a result of the cancel) when we're on
1459 // the second one.
1460 //
1461 // We can't tell this apart, so we think we're tearing down the current page
1462 // which will cause a crash later one. There is also some code in
1463 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1464 // out because of this problem.
1465 //
1466 // http://code.google.com/p/chromium/issues/detail?id=2855
1467 // Because this will not tear down the interstitial properly, if "back" is
1468 // back to another tab type, the interstitial will still be somewhat alive
1469 // in the previous tab type. If you navigate somewhere that activates the
1470 // tab with the interstitial again, you'll see a flash before the new load
1471 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271472 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181473 LOG(WARNING) << "Discarding message during interstitial.";
1474 return;
1475 }
1476
[email protected]02102f82011-06-13 20:37:021477 // Discard our pending entry if the load canceled (e.g. if we decided to
1478 // download the file instead of load it). We do not verify that the URL
1479 // being canceled matches the pending entry's URL because they will not
1480 // match if a redirect occurred (in which case we do not want to leave a
1481 // stale redirect URL showing). This means that we also cancel the pending
1482 // entry if the user started a new navigation. As a result, the navigation
1483 // controller may not remember that a load is in progress, but the
1484 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251485 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161486 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181487
[email protected]151a63d2011-12-20 22:32:521488 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181489 }
1490
1491 // Send out a notification that we failed a provisional load with an error.
1492 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581493 params.is_main_frame,
1494 controller_.IsURLInPageNavigation(validated_url),
1495 validated_url,
1496 std::string(),
1497 false,
1498 params.frame_id);
1499 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181500
[email protected]ad50def52011-10-19 23:17:071501 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271502 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501503 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531504 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101505
[email protected]d8c660432011-12-22 20:51:251506 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581507 observers_,
1508 DidFailProvisionalLoad(params.frame_id,
1509 params.is_main_frame,
1510 validated_url,
1511 params.error_code,
1512 params.error_description));
[email protected]724159a2010-12-30 01:11:181513}
1514
1515void TabContents::OnDidLoadResourceFromMemoryCache(
1516 const GURL& url,
[email protected]70435962011-08-02 20:13:281517 const std::string& security_info,
1518 const std::string& http_method,
1519 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191520 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181521 cache.Increment();
1522
1523 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081524 int cert_id = 0;
1525 net::CertStatus cert_status = 0;
1526 int security_bits = -1;
1527 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511528 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1529 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301530 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161531 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181532
[email protected]ad50def52011-10-19 23:17:071533 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271534 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501535 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531536 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181537}
1538
1539void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381540 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181541 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201542 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181543}
1544
1545void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021546 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231547 LOG(INFO) << security_origin << " ran insecure content from "
1548 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381549 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051550 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381551 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051552 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1553 }
[email protected]330614de2012-02-13 17:07:181554 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411555 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201556 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181557}
1558
1559void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1560 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251561 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101562 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181563}
1564
[email protected]1a55c5be2011-11-29 11:36:311565void TabContents::OnDidFinishLoad(
1566 int64 frame_id,
1567 const GURL& validated_url,
1568 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251569 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311570 DidFinishLoad(frame_id, validated_url, is_main_frame));
1571}
1572
1573void TabContents::OnDidFailLoadWithError(int64 frame_id,
1574 const GURL& validated_url,
1575 bool is_main_frame,
1576 int error_code,
1577 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251578 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311579 DidFailLoad(frame_id, validated_url, is_main_frame,
1580 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181581}
1582
[email protected]c8f73ab2011-01-22 00:05:171583void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271584 content_restrictions_ = restrictions;
1585 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171586}
1587
[email protected]216813952011-05-19 22:21:261588void TabContents::OnGoToEntryAtOffset(int offset) {
1589 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231590 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251591 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261592 if (!entry)
1593 return;
1594 // Note that we don't call NavigationController::GotToOffset() as we don't
1595 // want to create a pending navigation entry (it might end up lingering
1596 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251597 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581598 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511599 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581600 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471601 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571602
1603 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1604 // it in now that we know. This allows us to find the entry when it commits.
1605 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231606 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331607 entry->set_site_instance(
1608 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571609 }
[email protected]216813952011-05-19 22:21:261610 }
1611}
1612
1613void TabContents::OnUpdateZoomLimits(int minimum_percent,
1614 int maximum_percent,
1615 bool remember) {
1616 minimum_zoom_percent_ = minimum_percent;
1617 maximum_zoom_percent_ = maximum_percent;
1618 temporary_zoom_settings_ = !remember;
1619}
1620
[email protected]0bfbf882011-12-22 18:19:271621void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481622 download_stats::RecordDownloadSource(
1623 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261624 // Check if the URL to save matches the URL of the main frame. Since this
1625 // message originates from Pepper plugins, it may not be the case if the
1626 // plugin is an embedded element.
1627 GURL main_frame_url = GetURL();
1628 if (!main_frame_url.is_valid())
1629 return;
1630 bool is_main_frame = (url == main_frame_url);
1631 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271632}
1633
[email protected]3a29a6e2011-08-24 18:26:211634void TabContents::OnEnumerateDirectory(int request_id,
1635 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591636 ChildProcessSecurityPolicyImpl* policy =
1637 ChildProcessSecurityPolicyImpl::GetInstance();
1638 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1639 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211640}
1641
[email protected]7d189022011-08-25 22:54:201642void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511643 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201644}
1645
1646void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1647 const GURL& url,
1648 const string16& title) {
[email protected]b9535422012-02-09 01:47:591649 ChildProcessSecurityPolicyImpl* policy =
1650 ChildProcessSecurityPolicyImpl::GetInstance();
1651 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1652 return;
[email protected]6934a702011-12-20 00:04:511653 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201654}
1655
[email protected]b888919c2011-09-02 00:32:161656void TabContents::OnFindReply(int request_id,
1657 int number_of_matches,
1658 const gfx::Rect& selection_rect,
1659 int active_match_ordinal,
1660 bool final_update) {
[email protected]6934a702011-12-20 00:04:511661 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1662 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001663 // Send a notification to the renderer that we are ready to receive more
1664 // results from the scoping effort of the Find operation. The FindInPage
1665 // scoping is asynchronous and periodically sends results back up to the
1666 // browser using IPC. In an effort to not spam the browser we have the
1667 // browser send an ACK for each FindReply message and have the renderer
1668 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581669 GetRenderViewHostImpl()->Send(
1670 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161671}
1672
[email protected]d952a052011-09-06 18:42:451673void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511674 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451675}
1676
[email protected]7fc4bbb2011-09-08 21:23:101677void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1678 bool blocked_by_policy) {
1679 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251680 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101681 AppCacheAccessed(manifest_url, blocked_by_policy));
1682}
1683
[email protected]96d185d2009-04-24 03:28:541684// Notifies the RenderWidgetHost instance about the fact that the page is
1685// loading, or done loading and calls the base implementation.
1686void TabContents::SetIsLoading(bool is_loading,
1687 LoadNotificationDetails* details) {
1688 if (is_loading == is_loading_)
1689 return;
1690
1691 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211692 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541693 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561694 upload_size_ = 0;
1695 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541696 }
1697
1698 render_manager_.SetIsLoading(is_loading);
1699
1700 is_loading_ = is_loading;
1701 waiting_for_response_ = is_loading;
1702
[email protected]6ebdc9b2010-09-27 16:55:571703 if (delegate_)
1704 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461705 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541706
[email protected]432115822011-07-10 15:52:271707 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1708 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071709 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541710 if (details)
[email protected]6c2381d2011-10-19 02:52:531711 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071712 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501713 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541714 det);
1715}
1716
[email protected]420ae012009-04-24 05:16:321717void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131718 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321719 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561720 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381721 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441722 // that opened the window, as long as both renderers have the same
1723 // privileges.
[email protected]1fd1a502011-03-30 16:55:561724 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561725 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581726 // web_ui might be NULL if the URL refers to a non-existent extension.
1727 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401728 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521729 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441730 }
1731 }
[email protected]1fd1a502011-03-30 16:55:561732 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441733 }
1734
[email protected]4e697b042011-07-08 06:44:561735 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321736 // Clear the status bubble. This is a workaround for a bug where WebKit
1737 // doesn't let us know that the cursor left an element during a
1738 // transition (this is also why the mouse cursor remains as a hand after
1739 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1740 // clear the bubble when a user navigates to a named anchor in the same
1741 // page.
[email protected]36fc0392011-12-25 03:59:511742 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321743 }
1744
[email protected]a6e82fc2010-02-24 22:28:141745 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471746 // Once the main frame is navigated, we're no longer considered to have
1747 // displayed insecure content.
1748 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171749 }
[email protected]ce5c4502009-05-06 16:46:111750
[email protected]3c9e1872010-11-18 16:17:491751 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251752 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041753 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321754}
1755
1756void TabContents::DidNavigateAnyFramePostCommit(
1757 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131758 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321759 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061760 // If we navigate off the page, reset JavaScript state. This does nothing
1761 // to prevent a malicious script from spamming messages, since the script
1762 // could just reload the page to stop blocking.
1763 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551764 dialog_creator_->ResetJavaScriptState(this);
1765 dialog_creator_ = NULL;
1766 }
[email protected]420ae012009-04-24 05:16:321767
[email protected]3c9e1872010-11-18 16:17:491768 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251769 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041770 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321771}
1772
[email protected]74ce1ad2011-12-16 21:51:461773void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1774 // If we are creating a RVH for a restored controller, then we need to make
1775 // sure the RenderView starts with a next_page_id_ larger than the number
1776 // of restored entries. This must be called before the RenderView starts
1777 // navigating (to avoid a race between the browser updating max_page_id and
1778 // the renderer updating next_page_id_). Because of this, we only call this
1779 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561780 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581781 if (max_restored_page_id >
1782 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1783 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1784 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321785}
1786
[email protected]10f417c52011-12-28 21:04:231787bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571788 const string16& title) {
[email protected]420ae012009-04-24 05:16:321789 // For file URLs without a title, use the pathname instead. In the case of a
1790 // synthesized title, we don't want the update to count toward the "one set
1791 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511792 string16 final_title;
[email protected]420ae012009-04-24 05:16:321793 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511794 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1795 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321796 explicit_set = false; // Don't count synthetic titles toward the set limit.
1797 } else {
[email protected]acafd272011-07-26 17:35:571798 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321799 explicit_set = true;
1800 }
1801
[email protected]987fc3a2011-05-26 14:18:091802 // If a page is created via window.open and never navigated,
1803 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551804 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091805 if (entry) {
[email protected]36fc0392011-12-25 03:59:511806 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091807 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321808
[email protected]36fc0392011-12-25 03:59:511809 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091810 } else {
1811 if (page_title_when_no_navigation_entry_ == final_title)
1812 return false; // Nothing changed, don't bother.
1813
1814 page_title_when_no_navigation_entry_ = final_title;
1815 }
[email protected]420ae012009-04-24 05:16:321816
[email protected]420ae012009-04-24 05:16:321817 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231818 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321819
[email protected]2bb171882012-03-07 02:09:461820 std::pair<content::NavigationEntry*, bool> details =
1821 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141822
[email protected]ad50def52011-10-19 23:17:071823 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441824 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1825 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461826 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041827
[email protected]420ae012009-04-24 05:16:321828 return true;
1829}
1830
1831void TabContents::NotifySwapped() {
1832 // After sending out a swap notification, we need to send a disconnect
1833 // notification so that clients that pick up a pointer to |this| can NULL the
1834 // pointer. See Bug 1230284.
1835 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071836 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201837 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1838 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071839 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321840}
1841
1842void TabContents::NotifyConnected() {
1843 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071844 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121845 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1846 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071847 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321848}
1849
1850void TabContents::NotifyDisconnected() {
1851 if (!notify_disconnection_)
1852 return;
1853
1854 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071855 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321856 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1857 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071858 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321859}
1860
[email protected]8d3347f2009-07-09 22:00:211861RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321862 return view_.get();
1863}
1864
[email protected]8d3347f2009-07-09 22:00:211865RenderViewHostDelegate::RendererManagement*
1866TabContents::GetRendererManagementDelegate() {
1867 return &render_manager_;
1868}
1869
[email protected]daf82f82011-10-31 22:35:311870content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371871 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461872 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511873}
1874
[email protected]768c5472011-12-26 19:06:171875WebContents* TabContents::GetAsWebContents() {
1876 return this;
1877}
1878
[email protected]da4dfc42011-10-12 15:53:561879content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431880 return view_type_;
[email protected]7b291f92009-08-14 05:43:531881}
1882
[email protected]b7a756d42012-01-23 18:08:171883gfx::Rect TabContents::GetRootWindowResizerRect() const {
1884 if (delegate_)
1885 return delegate_->GetRootWindowResizerRect();
1886 return gfx::Rect();
1887}
1888
[email protected]420ae012009-04-24 05:16:321889void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071890 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271891 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321892 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531893 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231894 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321895 if (!entry)
1896 return;
1897
1898 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351899 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561900 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581901 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321902
1903 if (entry->IsViewSourceMode()) {
1904 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581905 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1906 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321907 }
[email protected]0666aef2009-05-13 19:48:081908
[email protected]d487beefe2011-12-21 05:41:211909 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261910
1911 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251912 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321913}
1914
1915void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521916 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321917 // Don't notify the world, since this came from a renderer in the
1918 // background.
1919 return;
1920 }
1921
1922 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311923 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231924 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301925
1926 // Restore the focus to the tab (otherwise the focus will be on the top
1927 // window).
[email protected]484ae5912010-09-29 19:16:141928 if (was_crashed && !FocusLocationBarByDefault() &&
1929 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301930 Focus();
[email protected]484ae5912010-09-29 19:16:141931 }
[email protected]32ded2212011-11-10 18:51:431932
[email protected]d8c660432011-12-22 20:51:251933 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321934}
1935
[email protected]443b80e2010-12-14 00:42:231936void TabContents::RenderViewGone(RenderViewHost* rvh,
1937 base::TerminationStatus status,
1938 int error_code) {
[email protected]151a63d2011-12-20 22:32:521939 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321940 // The pending page's RenderViewHost is gone.
1941 return;
1942 }
1943
1944 SetIsLoading(false, NULL);
1945 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231946 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311947 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321948
[email protected]d8c660432011-12-22 20:51:251949 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271950 observers_,
[email protected]be1f56ab2011-12-22 06:55:311951 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321952}
1953
[email protected]2e4633c2009-07-09 16:58:061954void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481955 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251956 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061957}
1958
[email protected]420ae012009-04-24 05:16:321959void TabContents::DidNavigate(RenderViewHost* rvh,
1960 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581961 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321962 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371963
[email protected]434f69f2012-02-06 21:56:521964 // Update the site of the SiteInstance if it doesn't have one yet, unless
1965 // this is for about:blank. In that case, the SiteInstance can still be
1966 // considered unused until a navigation to a real page.
1967 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1968 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331969 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521970 }
[email protected]420ae012009-04-24 05:16:321971
1972 // Need to update MIME type here because it's referred to in
1973 // UpdateNavigationCommands() called by RendererDidNavigate() to
1974 // determine whether or not to enable the encoding menu.
1975 // It's updated only for the main frame. For a subframe,
1976 // RenderView::UpdateURL does not set params.contents_mime_type.
1977 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1978 // TODO(jungshik): Add a test for the encoding menu to avoid
1979 // regressing it again.
[email protected]2905f742011-10-13 03:51:581980 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321981 contents_mime_type_ = params.contents_mime_type;
1982
[email protected]8286f51a2011-05-31 17:39:131983 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001984 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391985
[email protected]a9c0bfe2010-09-17 08:35:221986 // Send notification about committed provisional loads. This notification is
1987 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1988 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081989 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071990 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1991 // that is not recorded in the navigation history. For the purpose of
1992 // tracking navigation events, we treat this event as a sub frame navigation
1993 // event.
1994 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581995 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221996 // Whether or not a page transition was triggered by going backward or
1997 // forward in the history is only stored in the navigation controller's
1998 // entry list.
1999 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512000 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582001 content::PAGE_TRANSITION_FORWARD_BACK)) {
2002 transition_type = content::PageTransitionFromInt(
2003 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222004 }
[email protected]0d60f0192011-04-14 12:40:102005 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252006 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102007 DidCommitProvisionalLoadForFrame(params.frame_id,
2008 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222009 }
2010
[email protected]76543b92009-08-31 17:27:452011 if (!did_navigate)
2012 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322013
2014 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2015 // for the appropriate notification (best) or you can add it to
2016 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2017 // necessary, please).
2018
2019 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002020 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322021 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512022 if (delegate_)
2023 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002024 }
[email protected]420ae012009-04-24 05:16:322025 DidNavigateAnyFramePostCommit(rvh, details, params);
2026}
2027
2028void TabContents::UpdateState(RenderViewHost* rvh,
2029 int32 page_id,
2030 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152031 // Ensure that this state update comes from either the active RVH or one of
2032 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522033 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322034
2035 // We must be prepared to handle state updates for any page, these occur
2036 // when the user is scrolling and entering form data, as well as when we're
2037 // leaving a page, in which case our state may have already been moved to
2038 // the next page. The navigation controller will look up the appropriate
2039 // NavigationEntry and update it when it is notified via the delegate.
2040
2041 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582042 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322043 if (entry_index < 0)
2044 return;
[email protected]10f417c52011-12-28 21:04:232045 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322046
[email protected]36fc0392011-12-25 03:59:512047 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322048 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512049 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322050 controller_.NotifyEntryChanged(entry, entry_index);
2051}
2052
2053void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572054 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462055 const string16& title,
2056 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322057 // If we have a title, that's a pretty good indication that we've started
2058 // getting useful data.
2059 SetNotWaitingForResponse();
2060
[email protected]73eb2602012-02-09 19:50:552061 // Try to find the navigation entry, which might not be the current one.
2062 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232063 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582064 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092065
[email protected]73eb2602012-02-09 19:50:552066 // We can handle title updates when we don't have an entry in
2067 // UpdateTitleForEntry, but only if the update is from the current RVH.
2068 if (!entry && rvh != GetRenderViewHost())
2069 return;
2070
[email protected]a49e10b2011-08-01 23:57:462071 // TODO(evan): make use of title_direction.
2072 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092073 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322074 return;
2075
2076 // Broadcast notifications when the UI should be updated.
2077 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462078 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322079}
2080
[email protected]420ae012009-04-24 05:16:322081void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402082 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312083 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322084}
2085
2086void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512087 if (delegate_)
2088 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322089}
2090
[email protected]420ae012009-04-24 05:16:322091void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292092 // The UI may be in an event-tracking loop, such as between the
2093 // mouse-down and mouse-up in text selection or a button click.
2094 // Defer the close until after tracking is complete, so that we
2095 // don't free objects out from under the UI.
2096 // TODO(shess): This could probably be integrated with the
2097 // IsDoingDrag() test below. Punting for now because I need more
2098 // research to understand how this impacts platforms other than Mac.
2099 // TODO(shess): This could get more fine-grained. For instance,
2100 // closing a tab in another window while selecting text in the
2101 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212102 if (GetView()->IsEventTracking()) {
2103 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292104 return;
2105 }
2106
[email protected]24a4d1062009-07-10 23:10:422107 // If we close the tab while we're in the middle of a drag, we'll crash.
2108 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212109 if (GetView()->IsDoingDrag()) {
2110 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422111 return;
2112 }
2113
[email protected]420ae012009-04-24 05:16:322114 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522115 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512116 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322117}
2118
[email protected]cd9ed79d2011-11-15 19:22:572119void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522120 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512121 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572122}
2123
[email protected]420ae012009-04-24 05:16:322124void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512125 if (delegate_ && delegate_->IsPopupOrPanel(this))
2126 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322127}
2128
[email protected]7ab1e7d62009-10-14 23:32:012129void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322130 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492131
[email protected]6934a702011-12-20 00:04:512132 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212133 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512134 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002135 }
[email protected]3c9e1872010-11-18 16:17:492136
2137 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252138 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322139}
2140
[email protected]7ab1e7d62009-10-14 23:32:012141void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322142 scoped_ptr<LoadNotificationDetails> details;
2143
[email protected]10f417c52011-12-28 21:04:232144 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322145 // An entry may not exist for a stop when loading an initial blank page or
2146 // if an iframe injected by script into a blank page finishes loading.
2147 if (entry) {
[email protected]420ae012009-04-24 05:16:322148 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2149
2150 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512151 entry->GetVirtualURL(),
2152 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322153 elapsed,
2154 &controller_,
2155 controller_.GetCurrentEntryIndex()));
2156 }
2157
[email protected]420ae012009-04-24 05:16:322158 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492159
2160 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252161 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322162}
2163
[email protected]c95fa8b2011-04-28 20:26:162164void TabContents::DidCancelLoading() {
2165 controller_.DiscardNonCommittedEntries();
2166
2167 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462168 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162169}
2170
[email protected]1a3c3cb2010-12-16 21:03:402171void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512172 if (delegate_)
2173 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402174}
2175
[email protected]952a68e2011-11-17 00:36:102176void TabContents::DocumentAvailableInMainFrame(
2177 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252178 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102179 DocumentAvailableInMainFrame());
2180}
2181
[email protected]25497492010-09-11 15:15:082182void TabContents::DocumentOnLoadCompletedInMainFrame(
2183 RenderViewHost* render_view_host,
2184 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072185 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272186 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322187 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532188 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082189}
2190
[email protected]ae5184d62011-10-06 19:25:582191void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152192 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582193 WindowOpenDisposition disposition,
2194 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482195 // Delegate to RequestTransferURL because this is just the generic
2196 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582197 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482198 GlobalRequestID());
2199}
2200
2201void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582202 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482203 WindowOpenDisposition disposition,
2204 int64 source_frame_id,
2205 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202206 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582207 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582208 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352209 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322210 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2211 // generated suggestions).
2212 //
[email protected]e0112912011-02-02 22:54:352213 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162214 // want web sites to see a referrer of "chrome://blah" (and some
2215 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322216 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432217 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222218 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482219 false /* is_renderer_initiated */);
2220 params.transferred_global_request_id = old_request_id;
2221 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222222 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322223 } else {
[email protected]6bf6a6b52012-02-03 15:41:432224 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482225 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2226 params.transferred_global_request_id = old_request_id;
2227 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582228 }
2229 if (new_contents) {
2230 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252231 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582232 DidOpenRequestedURL(new_contents,
2233 url,
2234 referrer,
2235 disposition,
2236 transition_type,
2237 source_frame_id));
[email protected]420ae012009-04-24 05:16:322238 }
2239}
2240
[email protected]420ae012009-04-24 05:16:322241void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342242 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412243 const string16& message,
2244 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322245 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472246 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322247 IPC::Message* reply_msg,
2248 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072249 // Suppress JavaScript dialogs when requested. Also suppress messages when
2250 // showing an interstitial as it's shown over the previous page and we don't
2251 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502252 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582253 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272254 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072255 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522256 delegate_->ShouldSuppressDialogs() ||
2257 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322258
2259 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432260 std::string accept_lang = content::GetContentClient()->browser()->
2261 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552262 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522263 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432264 this,
2265 frame_url.GetOrigin(),
2266 accept_lang,
2267 javascript_message_type,
2268 message,
[email protected]51da7e32012-01-30 19:24:522269 default_prompt,
2270 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432271 reply_msg),
[email protected]51da7e32012-01-30 19:24:522272 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322273 }
[email protected]3ab9cb82011-06-03 18:02:072274
2275 if (suppress_this_message) {
2276 // If we are suppressing messages, just reply as if the user immediately
2277 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342278 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072279 }
2280
2281 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322282}
2283
[email protected]fedec012012-01-28 03:09:342284void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412285 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322286 bool is_reload,
[email protected]420ae012009-04-24 05:16:322287 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582288 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512289 if (delegate_)
2290 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072291
2292 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582293 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072294 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522295 delegate_->ShouldSuppressDialogs() ||
2296 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152297 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342298 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582299 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502300 return;
2301 }
[email protected]3ab9cb82011-06-03 18:02:072302
[email protected]7ab1e7d62009-10-14 23:32:012303 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552304 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522305 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322306 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522307 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2308 reply_msg));
[email protected]420ae012009-04-24 05:16:322309}
2310
[email protected]420ae012009-04-24 05:16:322311WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542312 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322313}
2314
[email protected]7d472472011-01-22 01:30:252315void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272316 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252317 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222318
[email protected]99907362012-01-11 05:41:402319 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172320 if (rdh) // NULL in unittests.
2321 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252322}
2323
[email protected]fa1cf0b82010-01-15 21:49:442324void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442325 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252326 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442327}
2328
[email protected]420ae012009-04-24 05:16:322329void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2330 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152331 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522332 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152333 return;
2334
[email protected]9f76c1e2012-03-05 15:15:582335 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2336
[email protected]e5fc1632011-08-08 07:51:532337 // Ignore renderer unresponsive event if debugger is attached to the tab
2338 // since the event may be a result of the renderer sitting on a breakpoint.
2339 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442340 DevToolsAgentHost* agent =
2341 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2342 if (agent &&
2343 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532344 return;
2345
[email protected]420ae012009-04-24 05:16:322346 if (is_during_unload) {
2347 // Hang occurred while firing the beforeunload/unload handler.
2348 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582349 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322350
2351 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2352 return;
2353
2354 // If the tab hangs in the beforeunload/unload handler there's really
2355 // nothing we can do to recover. Pretend the unload listeners have
2356 // all fired and close the tab. If the hang is in the beforeunload handler
2357 // then the user will not have the option of cancelling the close.
2358 Close(rvh);
2359 return;
2360 }
2361
[email protected]9f76c1e2012-03-05 15:15:582362 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472363 return;
2364
[email protected]6934a702011-12-20 00:04:512365 if (delegate_)
2366 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322367}
2368
2369void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512370 if (delegate_)
2371 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322372}
2373
2374void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212375 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562376 uint64 upload_position,
2377 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322378 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562379 upload_position_ = upload_position;
2380 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502381 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202382 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302383 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212384 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322385 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462386 if (IsLoading()) {
2387 NotifyNavigationStateChanged(
2388 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2389 }
[email protected]420ae012009-04-24 05:16:322390}
2391
[email protected]7d472472011-01-22 01:30:252392void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512393 if (delegate_)
2394 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252395}
2396
[email protected]420ae012009-04-24 05:16:322397void TabContents::BeforeUnloadFiredFromRenderManager(
2398 bool proceed,
2399 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512400 if (delegate_)
2401 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322402}
2403
[email protected]3a3d47472010-07-15 21:03:542404void TabContents::DidStartLoadingFromRenderManager(
2405 RenderViewHost* render_view_host) {
2406 DidStartLoading();
2407}
2408
2409void TabContents::RenderViewGoneFromRenderManager(
2410 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232411 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2412 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542413}
2414
[email protected]420ae012009-04-24 05:16:322415void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102416 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262417 gfx::Size size = view_->GetContainerSize();
2418 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2419 // here during container initialization and normal window size will be set
2420 // later. In case of tab duplication this resizing to 0x0 prevents setting
2421 // normal size later so just ignore it.
2422 if (!size.IsEmpty())
2423 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322424}
2425
[email protected]3a3d47472010-07-15 21:03:542426void TabContents::NotifySwappedFromRenderManager() {
2427 NotifySwapped();
2428}
2429
[email protected]d202a7c2012-01-04 07:53:472430NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202431 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542432}
2433
[email protected]d2353452012-01-19 19:53:562434WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2435 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322436}
2437
[email protected]10f417c52011-12-28 21:04:232438NavigationEntry*
2439 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322440 return controller_.GetLastCommittedEntry();
2441}
2442
2443bool TabContents::CreateRenderViewForRenderManager(
2444 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442445 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322446 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522447
[email protected]420ae012009-04-24 05:16:322448 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442449 if (rwh_view)
2450 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322451
[email protected]74ce1ad2011-12-16 21:51:462452 // Make sure we use the correct starting page_id in the new RenderView.
2453 UpdateMaxPageIDIfNecessary(render_view_host);
2454 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582455 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462456
[email protected]9f76c1e2012-03-05 15:15:582457 if (!static_cast<RenderViewHostImpl*>(
2458 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522459 return false;
2460
[email protected]e60c0232011-11-11 19:56:352461#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502462 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2463 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442464 if (rwh_view) {
2465 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2466 render_widget_host->WasResized();
2467 }
[email protected]f8233cc2011-05-31 20:24:502468#endif
2469
[email protected]420ae012009-04-24 05:16:322470 return true;
2471}
2472
[email protected]fedec012012-01-28 03:09:342473void TabContents::OnDialogClosed(RenderViewHost* rvh,
2474 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072475 bool success,
2476 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542477 if (is_showing_before_unload_dialog_ && !success) {
2478 // If a beforeunload dialog is canceled, we need to stop the throbber from
2479 // spinning, since we forced it to start spinning in Navigate.
2480 DidStopLoading();
2481
2482 tab_close_start_time_ = base::TimeTicks();
2483 }
2484 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582485 static_cast<RenderViewHostImpl*>(
2486 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542487}
2488
[email protected]be1f56ab2011-12-22 06:55:312489void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122490 encoding_ = content::GetContentClient()->browser()->
2491 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102492}
[email protected]f45d2a72010-03-08 23:28:352493
[email protected]e30d68d2012-02-09 00:06:262494void TabContents::SaveURL(const GURL& url,
2495 const GURL& referrer,
2496 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142497 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2498 if (!dlm)
2499 return;
2500 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262501 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142502 const NavigationEntry* entry = controller_.GetActiveEntry();
2503 if (entry)
2504 post_id = entry->GetPostID();
2505 }
2506 DownloadSaveInfo save_info;
2507 save_info.prompt_for_save_location = true;
2508 dlm->DownloadUrl(url,
2509 referrer,
2510 "",
2511 true, // prefer_cache
2512 post_id,
2513 save_info,
2514 this);
2515}
2516
[email protected]33f74972010-12-08 16:40:362517void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212518 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442519 // Can be NULL during tests.
2520 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212521 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362522}
[email protected]9f76c1e2012-03-05 15:15:582523
2524RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2525 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2526}