blob: 239ec8e563a12c32a38b09ea9d5a437fa7bda632 [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]35e251d2011-05-24 21:01:0428#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]686493142011-07-15 21:47:2231#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5032#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1334#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2335#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4436#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4443#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4444#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1745#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4646#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1547#include "content/public/browser/javascript_dialogs.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]c5eed492012-01-04 17:07:50122using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23123using content::NavigationEntry;
124using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20125using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11126using content::RenderViewHost;
127using content::RenderViewHostImpl;
[email protected]b0b67cf2012-01-18 21:59:57128using content::RenderViewHostDelegate;
[email protected]eaabba22012-03-07 15:02:11129using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58130using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04131using content::RenderWidgetHostViewPort;
[email protected]adbfb8df2012-02-24 01:19:43132using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33133using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17134using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38135using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09136using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25137using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56138using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22139using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50140using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44141
[email protected]420ae012009-04-24 05:16:32142namespace {
143
144// Amount of time we wait between when a key event is received and the renderer
145// is queried for its state and pushed to the NavigationEntry.
146const int kQueryStateDelay = 5000;
147
[email protected]6ebdc9b2010-09-27 16:55:57148const int kSyncWaitDelay = 40;
149
[email protected]ca406032011-07-19 21:53:05150static const char kDotGoogleDotCom[] = ".google.com";
151
[email protected]420ae012009-04-24 05:16:32152#if defined(OS_WIN)
153
154BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
155 // Note: erase is required to properly paint some widgets borders. This can
156 // be seen with textfields.
157 InvalidateRect(hwnd, NULL, TRUE);
158 return TRUE;
159}
160#endif
161
[email protected]2c5569662011-03-22 20:45:02162ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23163 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50164 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16165 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47166 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02167 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47168 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02169 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47170 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16171 break; // Fall through to rest of function.
172 }
[email protected]5e369672009-11-03 23:48:30173
[email protected]59246c572012-02-10 13:32:13174 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
175 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23176 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13177 browser_context->DidLastSessionExitCleanly()) {
178 if (entry.GetHasPostData())
179 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13181 }
[email protected]5e369672009-11-03 23:48:30182
[email protected]2c5569662011-03-22 20:45:02183 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30184}
185
[email protected]10f417c52011-12-28 21:04:23186void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47187 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42188 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50189 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16190 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51191 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54192 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55193 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
194 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51195 params->url = entry.GetURL();
196 params->referrer = entry.GetReferrer();
197 params->transition = entry.GetTransitionType();
198 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00199 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55200 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34201 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47202 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48203 params->transferred_request_child_id =
204 entry.transferred_global_request_id().child_id;
205 params->transferred_request_request_id =
206 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47207
208 if (delegate)
209 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34210}
211
[email protected]420ae012009-04-24 05:16:32212} // namespace
213
[email protected]a81343d232011-12-27 07:39:20214namespace content {
215
216WebContents* WebContents::Create(
217 BrowserContext* browser_context,
218 SiteInstance* site_instance,
219 int routing_id,
220 const WebContents* base_tab_contents,
221 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43222 return new TabContents(
223 browser_context,
224 site_instance,
225 routing_id,
226 static_cast<const TabContents*>(base_tab_contents),
227 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20228}
229}
[email protected]f4f50ef2011-01-21 19:01:19230
231// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32232
[email protected]3d7474ff2011-07-27 17:47:37233TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32234 SiteInstance* site_instance,
235 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07236 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43237 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42238 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07239 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37240 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13241 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10242 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22243 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34244 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23245 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
246 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34247 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21248 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56249 upload_size_(0),
250 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47251 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57252 capturing_contents_(false),
253 is_being_destroyed_(false),
254 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55255 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57256#if defined(OS_WIN)
257 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
258#endif
[email protected]7ab1e7d62009-10-14 23:32:01259 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56260 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38261 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25262 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01263 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25264 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01265 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00266 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43267 content_restrictions_(0),
268 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37269 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32270
[email protected]34ac70502009-09-25 17:07:23271 // We have the initial size of the view be based on the size of the passed in
272 // tab contents (normally a tab from the same window).
273 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21274 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00275
276#if defined(ENABLE_JAVA_BRIDGE)
277 java_bridge_dispatcher_host_manager_.reset(
278 new JavaBridgeDispatcherHostManager(this));
279#endif
[email protected]332af7732009-03-11 13:21:35280}
initial.commit09911bf2008-07-26 23:55:29281
282TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32283 is_being_destroyed_ = true;
284
[email protected]3ab9cb82011-06-03 18:02:07285 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55286 if (dialog_creator_)
287 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07288
[email protected]420ae012009-04-24 05:16:32289 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32290
[email protected]420ae012009-04-24 05:16:32291 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07292 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09293 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
294 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07295 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32296
297 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07298#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32299 // If we still have a window handle, destroy it. GetNativeView can return
300 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42301 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52302 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58303 if (host && host->GetView())
304 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42305 }
[email protected]420ae012009-04-24 05:16:32306#endif
[email protected]7ab1e7d62009-10-14 23:32:01307
308 // OnCloseStarted isn't called in unit tests.
309 if (!tab_close_start_time_.is_null()) {
310 UMA_HISTOGRAM_TIMES("Tab.Close",
311 base::TimeTicks::Now() - tab_close_start_time_);
312 }
[email protected]b5a1d11c2011-02-17 03:09:42313
[email protected]d8c660432011-12-22 20:51:25314 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08315
[email protected]6934a702011-12-20 00:04:51316 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42317}
318
[email protected]64d69de42012-02-06 00:19:54319WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
320 const GURL& url) {
321 WebPreferences prefs;
322
323 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
324
325 prefs.developer_extras_enabled = true;
326 prefs.javascript_enabled =
327 !command_line.HasSwitch(switches::kDisableJavaScript);
328 prefs.web_security_enabled =
329 !command_line.HasSwitch(switches::kDisableWebSecurity);
330 prefs.plugins_enabled =
331 !command_line.HasSwitch(switches::kDisablePlugins);
332 prefs.java_enabled =
333 !command_line.HasSwitch(switches::kDisableJava);
334
335 prefs.uses_page_cache =
336 command_line.HasSwitch(switches::kEnableFastback);
337 prefs.remote_fonts_enabled =
338 !command_line.HasSwitch(switches::kDisableRemoteFonts);
339 prefs.xss_auditor_enabled =
340 !command_line.HasSwitch(switches::kDisableXSSAuditor);
341 prefs.application_cache_enabled =
342 !command_line.HasSwitch(switches::kDisableApplicationCache);
343
344 prefs.local_storage_enabled =
345 !command_line.HasSwitch(switches::kDisableLocalStorage);
346 prefs.databases_enabled =
347 !command_line.HasSwitch(switches::kDisableDatabases);
348 prefs.webaudio_enabled =
349 !command_line.HasSwitch(switches::kDisableWebAudio);
350
351 prefs.experimental_webgl_enabled =
352 GpuProcessHost::gpu_enabled() &&
353 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
354 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
355
356 prefs.gl_multisampling_enabled =
357 !command_line.HasSwitch(switches::kDisableGLMultisampling);
358 prefs.privileged_webgl_extensions_enabled =
359 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
360 prefs.site_specific_quirks_enabled =
361 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
362 prefs.allow_file_access_from_file_urls =
363 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
364 prefs.show_composited_layer_borders =
365 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
366 prefs.show_composited_layer_tree =
367 command_line.HasSwitch(switches::kShowCompositedLayerTree);
368 prefs.show_fps_counter =
369 command_line.HasSwitch(switches::kShowFPSCounter);
370 prefs.accelerated_compositing_enabled =
371 GpuProcessHost::gpu_enabled() &&
372 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
373 prefs.threaded_compositing_enabled =
374 command_line.HasSwitch(switches::kEnableThreadedCompositing);
375 prefs.force_compositing_mode =
376 command_line.HasSwitch(switches::kForceCompositingMode);
377 prefs.fixed_position_compositing_enabled =
378 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
379 prefs.accelerated_2d_canvas_enabled =
380 GpuProcessHost::gpu_enabled() &&
381 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58382 prefs.deferred_2d_canvas_enabled =
383 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36384 prefs.threaded_animation_enabled =
385 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54386 prefs.accelerated_painting_enabled =
387 GpuProcessHost::gpu_enabled() &&
388 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
389 prefs.accelerated_filters_enabled =
390 GpuProcessHost::gpu_enabled() &&
391 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
392 prefs.accelerated_layers_enabled =
393 prefs.accelerated_animation_enabled =
394 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
395 prefs.composite_to_texture_enabled =
396 command_line.HasSwitch(switches::kEnableCompositeToTexture);
397 prefs.accelerated_plugins_enabled =
398 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
399 prefs.accelerated_video_enabled =
400 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
401 prefs.partial_swap_enabled =
402 command_line.HasSwitch(switches::kEnablePartialSwap);
403 prefs.interactive_form_validation_enabled =
404 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
405 prefs.fullscreen_enabled =
406 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16407 prefs.css_regions_enabled =
408 command_line.HasSwitch(switches::kEnableCssRegions);
409
[email protected]64d69de42012-02-06 00:19:54410
411#if defined(OS_MACOSX)
412 bool default_enable_scroll_animator = true;
413#else
414 // On CrOS, the launcher always passes in the --enable flag.
415 bool default_enable_scroll_animator = false;
416#endif
417 prefs.enable_scroll_animator = default_enable_scroll_animator;
418 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
419 prefs.enable_scroll_animator = true;
420 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
421 prefs.enable_scroll_animator = false;
422
423 prefs.visual_word_movement_enabled =
424 command_line.HasSwitch(switches::kEnableVisualWordMovement);
425 prefs.per_tile_painting_enabled =
426 command_line.HasSwitch(switches::kEnablePerTilePainting);
427
428 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32429 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54430 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11431 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
432 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54433 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11434 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54435 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11436 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54437 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11438 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54439 prefs.gl_multisampling_enabled = false;
440
441 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45442 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32443 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54444 prefs.accelerated_video_enabled = false;
445 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45446 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54447 }
448 }
449
[email protected]b9535422012-02-09 01:47:59450 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58451 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54452 prefs.loads_images_automatically = true;
453 prefs.javascript_enabled = true;
454 }
455
456 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
457
458 // Force accelerated compositing and 2d canvas off for chrome:, about: and
459 // chrome-devtools: pages (unless it's specifically allowed).
460 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54461 url.SchemeIs(chrome::kChromeUIScheme) ||
462 (url.SchemeIs(chrome::kAboutScheme) &&
463 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25464 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54465 prefs.accelerated_compositing_enabled = false;
466 prefs.accelerated_2d_canvas_enabled = false;
467 }
468
[email protected]43d9d782012-03-01 15:40:09469 int default_device_scale_factor;
470 base::StringToInt(command_line.GetSwitchValueASCII(
471 switches::kDefaultDeviceScaleFactor),
472 &default_device_scale_factor);
473
474 prefs.default_device_scale_factor = default_device_scale_factor;
475
[email protected]2e21fe292012-03-02 22:52:32476 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54477
478 return prefs;
479}
480
[email protected]d202a7c2012-01-04 07:53:47481NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20482 return controller_;
483}
484
[email protected]765187182012-01-11 23:59:28485RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
486 return &render_manager_;
487}
488
[email protected]724159a2010-12-30 01:11:18489bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56490 if (GetWebUI() &&
491 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17492 return true;
[email protected]d2353452012-01-19 19:53:56493 }
[email protected]f82d57b52011-04-27 19:13:17494
[email protected]d8c660432011-12-22 20:51:25495 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
496 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10497 while ((observer = it.GetNext()) != NULL)
498 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53499 return true;
[email protected]403415a2011-01-10 18:57:53500
[email protected]724159a2010-12-30 01:11:18501 bool handled = true;
502 bool message_is_ok = true;
503 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58504 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
505 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24506 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
507 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18508 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
509 OnDidStartProvisionalLoadForFrame)
510 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
511 OnDidRedirectProvisionalLoad)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
513 OnDidFailProvisionalLoadWithError)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
515 OnDidLoadResourceFromMemoryCache)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
517 OnDidDisplayInsecureContent)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
519 OnDidRunInsecureContent)
520 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
521 OnDocumentLoadedInFrame)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17523 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
524 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25525 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26526 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59527 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21528 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20529 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
531 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16532 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45533 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10534 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18535 IPC_MESSAGE_UNHANDLED(handled = false)
536 IPC_END_MESSAGE_MAP_EX()
537
538 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38539 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18540 GetRenderProcessHost()->ReceivedBadMessage();
541 }
542
543 return handled;
544}
545
[email protected]6c2e472f2011-08-24 23:26:18546void TabContents::RunFileChooser(
547 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23548 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51549 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18550}
551
[email protected]c5eed492012-01-04 17:07:50552NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56553 return controller_;
554}
555
[email protected]c5eed492012-01-04 17:07:50556const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56557 return controller_;
558}
559
[email protected]627e0512011-12-21 22:55:30560content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55561 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30562}
563
[email protected]f5fa20e2011-12-21 22:35:56564void TabContents::SetViewType(content::ViewType type) {
565 view_type_ = type;
566}
567
[email protected]ea049a02011-12-25 21:37:09568content::ViewType TabContents::GetViewType() const {
569 return view_type_;
570}
571
[email protected]be1f56ab2011-12-22 06:55:31572const GURL& TabContents::GetURL() const {
573 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23574 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51575 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31576}
577
578
579const base::PropertyBag* TabContents::GetPropertyBag() const {
580 return &property_bag_;
581}
582
583base::PropertyBag* TabContents::GetPropertyBag() {
584 return &property_bag_;
585}
586
587content::WebContentsDelegate* TabContents::GetDelegate() {
588 return delegate_;
589}
590
591void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
592 // TODO(cbentzel): remove this debugging code?
593 if (delegate == delegate_)
594 return;
595 if (delegate_)
596 delegate_->Detach(this);
597 delegate_ = delegate;
598 if (delegate_)
599 delegate_->Attach(this);
600}
601
[email protected]f3b1a082011-11-18 00:34:30602content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03603 if (render_manager_.current_host())
[email protected]9f76c1e2012-03-05 15:15:58604 return render_manager_.current_host()->GetProcess();
[email protected]4d0df262011-10-03 20:05:03605 else
606 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16607}
608
[email protected]be1f56ab2011-12-22 06:55:31609RenderViewHost* TabContents::GetRenderViewHost() const {
610 return render_manager_.current_host();
611}
612
613RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
614 return render_manager_.GetRenderWidgetHostView();
615}
616
[email protected]8643e6d2012-01-18 20:26:10617content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31618 return view_.get();
619}
620
[email protected]01ec4ec2012-01-18 04:13:47621content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50622 WebUIControllerFactory* factory =
623 content::GetContentClient()->browser()->GetWebUIControllerFactory();
624 if (!factory)
625 return NULL;
[email protected]d2353452012-01-19 19:53:56626 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22627 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50628 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22629 if (controller) {
630 web_ui->SetController(controller);
631 return web_ui;
632 }
633
634 delete web_ui;
635 return NULL;
636}
637
[email protected]01ec4ec2012-01-18 04:13:47638content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31639 return render_manager_.web_ui() ? render_manager_.web_ui()
640 : render_manager_.pending_web_ui();
641}
642
[email protected]01ec4ec2012-01-18 04:13:47643content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31644 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34645}
646
[email protected]96d185d2009-04-24 03:28:54647const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55648 // Transient entries take precedence. They are used for interstitial pages
649 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23650 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08651 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20652 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30653 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23654 if (entry) {
[email protected]b5cca982011-05-26 04:42:08655 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23656 }
[email protected]7ade2732011-02-10 00:13:58657 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
658 render_manager_.pending_web_ui() : render_manager_.web_ui();
659 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54660 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55661 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54662 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35663 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22664 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54665 if (!title.empty())
666 return title;
667 }
668 }
669
670 // We use the title for the last committed entry rather than a pending
671 // navigation entry. For example, when the user types in a URL, we want to
672 // keep the old page's title until the new load has committed and we get a new
673 // title.
[email protected]96d185d2009-04-24 03:28:54674 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23675 if (entry) {
[email protected]b5cca982011-05-26 04:42:08676 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23677 }
[email protected]987fc3a2011-05-26 14:18:09678
679 // |page_title_when_no_navigation_entry_| is finally used
680 // if no title cannot be retrieved.
681 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54682}
683
[email protected]d5f942ba2008-09-26 19:30:34684int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46685 return GetMaxPageIDForSiteInstance(GetSiteInstance());
686}
687
688int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33689 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
690 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46691
[email protected]b6583592012-01-25 19:52:33692 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34693}
694
695void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46696 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
697}
698
[email protected]b6583592012-01-25 19:52:33699void TabContents::UpdateMaxPageIDForSiteInstance(
700 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46701 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33702 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34703}
704
[email protected]91854cd2012-01-10 19:43:57705void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
706 max_page_ids_ = tab_contents->max_page_ids_;
707}
708
[email protected]96d185d2009-04-24 03:28:54709SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58710 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54711}
712
[email protected]77362eb2011-08-01 17:18:38713SiteInstance* TabContents::GetPendingSiteInstance() const {
714 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
715 render_manager_.pending_render_view_host() :
716 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58717 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38718}
719
[email protected]be1f56ab2011-12-22 06:55:31720bool TabContents::IsLoading() const {
721 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49722}
723
[email protected]be1f56ab2011-12-22 06:55:31724bool TabContents::IsWaitingForResponse() const {
725 return waiting_for_response_;
726}
727
728const net::LoadStateWithParam& TabContents::GetLoadState() const {
729 return load_state_;
730}
731
732const string16& TabContents::GetLoadStateHost() const {
733 return load_state_host_;
734}
735
736uint64 TabContents::GetUploadSize() const {
737 return upload_size_;
738}
739
740uint64 TabContents::GetUploadPosition() const {
741 return upload_position_;
742}
743
744const std::string& TabContents::GetEncoding() const {
745 return encoding_;
746}
747
748bool TabContents::DisplayedInsecureContent() const {
749 return displayed_insecure_content_;
750}
751
752void TabContents::SetCapturingContents(bool cap) {
753 capturing_contents_ = cap;
754}
755
756bool TabContents::IsCrashed() const {
757 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
758 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
759 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49760}
761
[email protected]443b80e2010-12-14 00:42:23762void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
763 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34764 return;
765
[email protected]443b80e2010-12-14 00:42:23766 crashed_status_ = status;
767 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46768 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34769}
770
[email protected]be1f56ab2011-12-22 06:55:31771base::TerminationStatus TabContents::GetCrashedStatus() const {
772 return crashed_status_;
773}
774
775bool TabContents::IsBeingDestroyed() const {
776 return is_being_destroyed_;
777}
778
[email protected]d5f942ba2008-09-26 19:30:34779void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
780 if (delegate_)
781 delegate_->NavigationStateChanged(this, changed_flags);
782}
783
[email protected]96d185d2009-04-24 03:28:54784void TabContents::DidBecomeSelected() {
785 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04786 RenderWidgetHostViewPort* rwhv =
787 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16788 if (rwhv) {
789 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43790#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16791 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43792#endif
793 }
[email protected]96d185d2009-04-24 03:28:54794
[email protected]5ac20162010-11-24 23:33:11795 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38796
[email protected]d8c660432011-12-22 20:51:25797 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59798
799 // The resize rect might have changed while this was inactive -- send the new
800 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58801 RenderViewHostImpl* rvh =
802 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59803 if (rvh) {
804 rvh->ResizeRectChanged(GetRootWindowResizerRect());
805 }
[email protected]96d185d2009-04-24 03:28:54806}
807
[email protected]be1f56ab2011-12-22 06:55:31808
809base::TimeTicks TabContents::GetLastSelectedTime() const {
810 return last_selected_time_;
811}
812
[email protected]96d185d2009-04-24 03:28:54813void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31814 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52815 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
816 // open a tab in then background, then closes the tab before selecting it.
817 // This is because closing the tab calls TabContents::Destroy(), which
818 // removes the |GetRenderViewHost()|; then when we actually destroy the
819 // window, OnWindowPosChanged() notices and calls HideContents() (which
820 // calls us).
[email protected]c30585c2012-02-16 15:02:04821 RenderWidgetHostViewPort* rwhv =
822 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16823 if (rwhv)
824 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54825 }
826
[email protected]ad50def52011-10-19 23:17:07827 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09828 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
829 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07830 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54831}
832
[email protected]be1f56ab2011-12-22 06:55:31833void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04834 RenderWidgetHostViewPort* rwhv =
835 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31836 if (rwhv)
837 rwhv->DidBecomeSelected();
838}
839
840void TabContents::HideContents() {
841 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
842 // our superclass HideContents(), because some callers want to be very picky
843 // about the order in which these get called. In addition to making the code
844 // here practically impossible to understand, this also means we end up
845 // calling TabContents::WasHidden() twice if callers call both versions of
846 // HideContents() on a TabContents.
847 WasHidden();
848}
849
850bool TabContents::NeedToFireBeforeUnload() {
851 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27852 return WillNotifyDisconnection() &&
853 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58854 !static_cast<RenderViewHostImpl*>(
855 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31856}
857
[email protected]0bfbf882011-12-22 18:19:27858void TabContents::Stop() {
859 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25860 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27861}
862
[email protected]d9083482012-01-06 00:38:46863WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27864 // We create a new SiteInstance so that the new tab won't share processes
865 // with the old one. This can be changed in the future if we need it to share
866 // processes for some reason.
867 TabContents* tc = new TabContents(
868 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33869 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27870 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20871 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27872 return tc;
873}
874
[email protected]2a6bc3e2011-12-28 23:51:33875void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27876 WindowOpenDisposition disposition,
877 const gfx::Rect& initial_pos,
878 bool user_gesture) {
879 if (!delegate_)
880 return;
881
882 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
883 user_gesture);
884}
885
886gfx::NativeView TabContents::GetContentNativeView() const {
887 return view_->GetContentNativeView();
888}
889
890gfx::NativeView TabContents::GetNativeView() const {
891 return view_->GetNativeView();
892}
893
894void TabContents::GetContainerBounds(gfx::Rect* out) const {
895 view_->GetContainerBounds(out);
896}
897
898void TabContents::Focus() {
899 view_->Focus();
900}
901
[email protected]d8c660432011-12-22 20:51:25902void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31903 observers_.AddObserver(observer);
904}
905
[email protected]d8c660432011-12-22 20:51:25906void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31907 observers_.RemoveObserver(observer);
908}
909
[email protected]d5f942ba2008-09-26 19:30:34910void TabContents::Activate() {
911 if (delegate_)
912 delegate_->ActivateContents(this);
913}
914
[email protected]ea42e7782010-08-23 23:58:12915void TabContents::Deactivate() {
916 if (delegate_)
917 delegate_->DeactivateContents(this);
918}
919
[email protected]63954792011-07-11 04:17:48920void TabContents::LostCapture() {
921 if (delegate_)
922 delegate_->LostCapture();
923}
924
925bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
926 bool* is_keyboard_shortcut) {
927 return delegate_ &&
928 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
929}
930
931void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
932 if (delegate_)
933 delegate_->HandleKeyboardEvent(event);
934}
935
[email protected]32ded2212011-11-10 18:51:43936void TabContents::HandleMouseDown() {
937 if (delegate_)
938 delegate_->HandleMouseDown();
939}
940
[email protected]63954792011-07-11 04:17:48941void TabContents::HandleMouseUp() {
942 if (delegate_)
943 delegate_->HandleMouseUp();
944}
945
946void TabContents::HandleMouseActivate() {
947 if (delegate_)
948 delegate_->HandleMouseActivate();
949}
950
[email protected]8a5e0ca2011-08-25 06:30:47951void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
952 if (delegate_)
953 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
954}
955
[email protected]5d5f7af2011-10-01 01:38:12956bool TabContents::IsFullscreenForCurrentTab() const {
957 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
958}
959
[email protected]e9621112011-10-17 05:38:37960void TabContents::RequestToLockMouse() {
961 if (delegate_) {
962 delegate_->RequestToLockMouse(this);
963 } else {
964 GotResponseToLockMouseRequest(false);
965 }
966}
967
968void TabContents::LostMouseLock() {
969 if (delegate_)
970 delegate_->LostMouseLock();
971}
972
[email protected]0548c5352011-09-07 00:33:33973void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23974 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33975 if (delegate_)
976 delegate_->UpdatePreferredSize(this, pref_size);
977}
978
[email protected]61e2b3cc2012-03-02 16:13:34979void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
980 if (delegate_)
981 delegate_->ResizeDueToAutoResize(this, new_size);
982}
983
[email protected]32ded2212011-11-10 18:51:43984void TabContents::WebUISend(RenderViewHost* render_view_host,
985 const GURL& source_url,
986 const std::string& name,
987 const base::ListValue& args) {
988 if (delegate_)
989 delegate_->WebUISend(this, source_url, name, args);
990}
991
[email protected]e5d549d2011-12-28 01:29:20992WebContents* TabContents::OpenURL(const OpenURLParams& params) {
993 if (!delegate_)
994 return NULL;
[email protected]00c37fc2011-08-02 00:22:50995
[email protected]e5d549d2011-12-28 01:29:20996 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
997 // Notify observers.
998 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
999 DidOpenURL(params.url, params.referrer,
1000 params.disposition, params.transition));
1001 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341002}
1003
[email protected]1ccb3568d2010-02-19 10:51:161004bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501005 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251006 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231007 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251008 reload_type);
[email protected]876bc832010-09-07 16:29:541009}
[email protected]96d185d2009-04-24 03:28:541010
[email protected]876bc832010-09-07 16:29:541011bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231012 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501013 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401014 // The renderer will reject IPC messages with URLs longer than
1015 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511016 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401017 return false;
1018
[email protected]9f76c1e2012-03-05 15:15:581019 RenderViewHostImpl* dest_render_view_host =
1020 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401021 if (!dest_render_view_host)
1022 return false; // Unable to create the desired render view host.
1023
[email protected]80a8fad2011-01-29 04:02:381024 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071025 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581026 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501027 WebUIControllerFactory* factory =
1028 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1029 bool is_allowed_in_web_ui_renderer =
1030 factory &&
1031 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431032#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511033 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431034#endif
[email protected]e091df82011-10-11 18:13:211035 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551036 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581037
[email protected]96d185d2009-04-24 03:28:541038 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441039 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521040 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441041 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511042 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541043
1044 // Used for page load time metrics.
1045 current_load_start_ = base::TimeTicks::Now();
1046
1047 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341048 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271049 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471050 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341051 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541052
[email protected]36fc0392011-12-25 03:59:511053 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541054 // HACK!! This code suppresses javascript: URLs from being added to
1055 // session history, which is what we want to do for javascript: URLs that
1056 // do not generate content. What we really need is a message from the
1057 // renderer telling us that a new page was not created. The same message
1058 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511059 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541060 return false;
1061 }
1062
[email protected]3c9e1872010-11-18 16:17:491063 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251064 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041065 observers_,
[email protected]36fc0392011-12-25 03:59:511066 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541067
[email protected]09b29342011-06-24 19:18:481068 if (delegate_)
1069 delegate_->DidNavigateToPendingEntry(this);
1070
[email protected]d5f942ba2008-09-26 19:30:341071 return true;
1072}
1073
[email protected]b6583592012-01-25 19:52:331074void TabContents::SetHistoryLengthAndPrune(
1075 const SiteInstance* site_instance,
1076 int history_length,
1077 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411078 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1079 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191080 if (render_manager_.pending_render_view_host()) {
1081 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141082 return;
[email protected]9e1ad4b2011-08-14 16:49:191083 }
[email protected]9f76c1e2012-03-05 15:15:581084 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191085 if (!rvh) {
1086 NOTREACHED();
1087 return;
1088 }
[email protected]9f76c1e2012-03-05 15:15:581089 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191090 NOTREACHED();
1091 return;
1092 }
[email protected]9f76c1e2012-03-05 15:15:581093 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191094 history_length,
1095 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141096}
1097
[email protected]90daadb42009-06-08 21:27:281098void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271099 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541100 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1101 return;
1102 }
[email protected]9f76c1e2012-03-05 15:15:581103 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541104}
1105
[email protected]0bfbf882011-12-22 18:19:271106bool TabContents::ShowingInterstitialPage() const {
1107 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541108}
1109
[email protected]0bfbf882011-12-22 18:19:271110InterstitialPage* TabContents::GetInterstitialPage() const {
1111 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221112}
1113
[email protected]a53209b2012-01-20 16:48:161114bool TabContents::IsSavable() {
1115 // WebKit creates Document object when MIME type is application/xhtml+xml,
1116 // so we also support this MIME type.
1117 return contents_mime_type_ == "text/html" ||
1118 contents_mime_type_ == "text/xml" ||
1119 contents_mime_type_ == "application/xhtml+xml" ||
1120 contents_mime_type_ == "text/plain" ||
1121 contents_mime_type_ == "text/css" ||
1122 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1123}
1124
[email protected]c7dd2f62011-07-18 15:57:591125void TabContents::OnSavePage() {
1126 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161127 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481128 download_stats::RecordDownloadSource(
1129 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261130 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141131 return;
[email protected]c7dd2f62011-07-18 15:57:591132 }
1133
1134 Stop();
1135
1136 // Create the save package and possibly prompt the user for the name to save
1137 // the page as. The user prompt is an asynchronous operation that runs on
1138 // another thread.
1139 save_package_ = new SavePackage(this);
1140 save_package_->GetSaveInfo();
1141}
1142
1143// Used in automated testing to bypass prompting the user for file names.
1144// Instead, the names and paths are hard coded rather than running them through
1145// file name sanitation and extension / mime checking.
1146bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161147 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591148 // Stop the page from navigating.
1149 Stop();
1150
1151 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1152 return save_package_->Init();
1153}
1154
[email protected]aa4f3972012-03-01 18:12:121155void TabContents::GenerateMHTML(
1156 const FilePath& file,
1157 const base::Callback<void(const FilePath&, int64)>& callback) {
1158 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1159}
1160
[email protected]420ae012009-04-24 05:16:321161bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231162 NavigationEntryImpl* active_entry =
1163 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321164 return (active_entry != NULL &&
1165 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511166 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321167}
1168
[email protected]0bfbf882011-12-22 18:19:271169const std::string& TabContents::GetContentsMimeType() const {
1170 return contents_mime_type_;
1171}
1172
1173bool TabContents::WillNotifyDisconnection() const {
1174 return notify_disconnection_;
1175}
1176
[email protected]b2fe07d12010-02-09 14:38:081177void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311178 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581179 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1180 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161181}
1182
[email protected]b2fe07d12010-02-09 14:38:081183void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311184 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581185 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1186 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161187}
1188
[email protected]0bfbf882011-12-22 18:19:271189content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1190 return &renderer_preferences_;
1191}
1192
1193void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1194 new_tab_start_time_ = time;
1195}
1196
1197base::TimeTicks TabContents::GetNewTabStartTime() const {
1198 return new_tab_start_time_;
1199}
1200
[email protected]7ab1e7d62009-10-14 23:32:011201void TabContents::OnCloseStarted() {
1202 if (tab_close_start_time_.is_null())
1203 tab_close_start_time_ = base::TimeTicks::Now();
1204}
1205
[email protected]46624bf2010-06-09 16:04:191206bool TabContents::ShouldAcceptDragAndDrop() const {
1207#if defined(OS_CHROMEOS)
1208 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1209 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511210 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201211 return false;
1212 return true;
[email protected]46624bf2010-06-09 16:04:191213#else
1214 return true;
1215#endif
1216}
1217
[email protected]7813bd72011-02-05 02:19:341218void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521219 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581220 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511221 if (delegate_)
1222 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341223}
1224
[email protected]0bfbf882011-12-22 18:19:271225void TabContents::SetClosedByUserGesture(bool value) {
1226 closed_by_user_gesture_ = value;
1227}
1228
1229bool TabContents::GetClosedByUserGesture() const {
1230 return closed_by_user_gesture_;
1231}
1232
[email protected]d0b8d092010-10-25 04:05:171233double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051234 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561235 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251236 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171237 return 0;
[email protected]b75b8292010-10-01 07:28:251238
1239 double zoom_level;
1240 if (temporary_zoom_settings_) {
1241 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581242 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251243 } else {
[email protected]2ae88d12011-10-14 09:11:191244 GURL url;
[email protected]10f417c52011-12-28 21:04:231245 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191246 // Since zoom map is updated using rewritten URL, use rewritten URL
1247 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511248 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191249 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251250 }
[email protected]d0b8d092010-10-25 04:05:171251 return zoom_level;
1252}
[email protected]b75b8292010-10-01 07:28:251253
[email protected]d0b8d092010-10-25 04:05:171254int TabContents::GetZoomPercent(bool* enable_increment,
1255 bool* enable_decrement) {
1256 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011257 // Calculate the zoom percent from the factor. Round up to the nearest whole
1258 // number.
[email protected]b75b8292010-10-01 07:28:251259 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011260 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251261 *enable_decrement = percent > minimum_zoom_percent_;
1262 *enable_increment = percent < maximum_zoom_percent_;
1263 return percent;
1264}
1265
[email protected]3c733bde2010-12-21 19:56:311266void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501267 if (!delegate_)
1268 return;
1269
[email protected]10f417c52011-12-28 21:04:231270 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501271 if (!active_entry)
1272 return;
1273
[email protected]36fc0392011-12-25 03:59:511274 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121275}
1276
[email protected]932b7a12011-03-09 12:50:271277void TabContents::ViewFrameSource(const GURL& url,
1278 const std::string& content_state) {
1279 if (!delegate_)
1280 return;
1281
1282 delegate_->ViewSourceForFrame(this, url, content_state);
1283}
1284
[email protected]0bfbf882011-12-22 18:19:271285int TabContents::GetMinimumZoomPercent() const {
1286 return minimum_zoom_percent_;
1287}
1288
1289int TabContents::GetMaximumZoomPercent() const {
1290 return maximum_zoom_percent_;
1291}
1292
[email protected]bcd2815602012-01-14 18:17:231293gfx::Size TabContents::GetPreferredSize() const {
1294 return preferred_size_;
1295}
1296
[email protected]0bfbf882011-12-22 18:19:271297int TabContents::GetContentRestrictions() const {
1298 return content_restrictions_;
1299}
1300
1301WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501302 WebUIControllerFactory* factory =
1303 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1304 if (!factory)
1305 return WebUI::kNoWebUI;
1306 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271307}
1308
[email protected]01ec4ec2012-01-18 04:13:471309content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271310 // When there is a pending navigation entry, we want to use the pending WebUI
1311 // that goes along with it to control the basic flags. For example, we want to
1312 // show the pending URL in the URL bar, so we want the display_url flag to
1313 // be from the pending entry.
1314 //
1315 // The confusion comes because there are multiple possibilities for the
1316 // initial load in a tab as a side effect of the way the RenderViewHostManager
1317 // works.
1318 //
1319 // - For the very first tab the load looks "normal". The new tab Web UI is
1320 // the pending one, and we want it to apply here.
1321 //
1322 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1323 // get switched to the one previously associated with the new tab pages.
1324 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1325 // have a committed Web UI in this case.
1326 //
1327 // This condition handles all of these cases:
1328 //
1329 // - First load in first tab: no committed nav entry + pending nav entry +
1330 // pending dom ui:
1331 // -> Use pending Web UI if any.
1332 //
1333 // - First load in second tab: no committed nav entry + pending nav entry +
1334 // no pending Web UI:
1335 // -> Use the committed Web UI if any.
1336 //
1337 // - Second navigation in any tab: committed nav entry + pending nav entry:
1338 // -> Use pending Web UI if any.
1339 //
1340 // - Normal state with no load: committed nav entry + no pending nav entry:
1341 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251342 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271343 (controller_.GetLastCommittedEntry() ||
1344 render_manager_.pending_web_ui()))
1345 return render_manager_.pending_web_ui();
1346 return render_manager_.web_ui();
1347}
1348
1349bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1350 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581351 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271352}
1353
1354bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471355 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271356 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221357 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231358 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511359 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271360 return true;
1361 return false;
1362}
1363
1364void TabContents::SetFocusToLocationBar(bool select_all) {
1365 if (delegate_)
1366 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211367}
1368
[email protected]8b5af492011-11-28 21:50:581369void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301370 const string16& type,
1371 const string16& href,
1372 const string16& title,
1373 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511374 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301375 this, action, type, href, title, disposition);
1376}
1377
[email protected]678105012011-12-09 04:01:211378void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301379 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001380 WebIntentsDispatcherImpl* intents_dispatcher =
1381 new WebIntentsDispatcherImpl(this, intent, intent_id);
1382 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301383}
1384
[email protected]724159a2010-12-30 01:11:181385void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1386 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591387 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181388 const GURL& url) {
1389 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1390 GURL validated_url(url);
[email protected]9f76c1e2012-03-05 15:15:581391 GetRenderViewHostImpl()->FilterURL(
1392 ChildProcessSecurityPolicyImpl::GetInstance(),
1393 GetRenderProcessHost()->GetID(),
1394 &validated_url);
[email protected]724159a2010-12-30 01:11:181395
[email protected]8093a542011-05-13 07:29:321396 RenderViewHost* rvh =
1397 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521398 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101399 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251400 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101401 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321402 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101403
[email protected]724159a2010-12-30 01:11:181404 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591405 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251406 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591407 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181408 }
1409}
1410
1411void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591412 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181413 const GURL& source_url,
1414 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491415 // TODO(creis): Remove this method and have the pre-rendering code listen to
1416 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1417 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231418 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181419 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251420 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181421 else
1422 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511423 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181424 return;
[email protected]e7d50892011-01-19 21:47:381425
[email protected]4850a7f2011-03-08 23:36:591426 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251427 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261428 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591429 opener_url));
[email protected]724159a2010-12-30 01:11:181430}
1431
1432void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581433 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1434 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1435 << ", error_code: " << params.error_code
1436 << ", error_description: " << params.error_description
1437 << ", is_main_frame: " << params.is_main_frame
1438 << ", showing_repost_interstitial: " <<
1439 params.showing_repost_interstitial
1440 << ", frame_id: " << params.frame_id;
1441 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581442 GetRenderViewHostImpl()->FilterURL(
1443 ChildProcessSecurityPolicyImpl::GetInstance(),
1444 GetRenderProcessHost()->GetID(),
1445 &validated_url);
[email protected]724159a2010-12-30 01:11:181446
[email protected]d7b175e2011-10-11 15:31:581447 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181448 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1449 // This means that the interstitial won't be torn down properly, which is
1450 // bad. But if we have an interstitial, go back to another tab type, and
1451 // then load the same interstitial again, we could end up getting the first
1452 // interstitial's "failed" message (as a result of the cancel) when we're on
1453 // the second one.
1454 //
1455 // We can't tell this apart, so we think we're tearing down the current page
1456 // which will cause a crash later one. There is also some code in
1457 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1458 // out because of this problem.
1459 //
1460 // http://code.google.com/p/chromium/issues/detail?id=2855
1461 // Because this will not tear down the interstitial properly, if "back" is
1462 // back to another tab type, the interstitial will still be somewhat alive
1463 // in the previous tab type. If you navigate somewhere that activates the
1464 // tab with the interstitial again, you'll see a flash before the new load
1465 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271466 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181467 LOG(WARNING) << "Discarding message during interstitial.";
1468 return;
1469 }
1470
[email protected]02102f82011-06-13 20:37:021471 // Discard our pending entry if the load canceled (e.g. if we decided to
1472 // download the file instead of load it). We do not verify that the URL
1473 // being canceled matches the pending entry's URL because they will not
1474 // match if a redirect occurred (in which case we do not want to leave a
1475 // stale redirect URL showing). This means that we also cancel the pending
1476 // entry if the user started a new navigation. As a result, the navigation
1477 // controller may not remember that a load is in progress, but the
1478 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251479 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161480 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181481
[email protected]151a63d2011-12-20 22:32:521482 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181483 }
1484
1485 // Send out a notification that we failed a provisional load with an error.
1486 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581487 params.is_main_frame,
1488 controller_.IsURLInPageNavigation(validated_url),
1489 validated_url,
1490 std::string(),
1491 false,
1492 params.frame_id);
1493 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181494
[email protected]ad50def52011-10-19 23:17:071495 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271496 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501497 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531498 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101499
[email protected]d8c660432011-12-22 20:51:251500 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581501 observers_,
1502 DidFailProvisionalLoad(params.frame_id,
1503 params.is_main_frame,
1504 validated_url,
1505 params.error_code,
1506 params.error_description));
[email protected]724159a2010-12-30 01:11:181507}
1508
1509void TabContents::OnDidLoadResourceFromMemoryCache(
1510 const GURL& url,
[email protected]70435962011-08-02 20:13:281511 const std::string& security_info,
1512 const std::string& http_method,
1513 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191514 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181515 cache.Increment();
1516
1517 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081518 int cert_id = 0;
1519 net::CertStatus cert_status = 0;
1520 int security_bits = -1;
1521 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511522 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1523 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301524 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161525 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181526
[email protected]ad50def52011-10-19 23:17:071527 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271528 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501529 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531530 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181531}
1532
1533void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381534 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181535 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201536 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181537}
1538
1539void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021540 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231541 LOG(INFO) << security_origin << " ran insecure content from "
1542 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381543 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051544 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381545 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051546 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1547 }
[email protected]330614de2012-02-13 17:07:181548 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411549 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201550 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181551}
1552
1553void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1554 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251555 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101556 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181557}
1558
[email protected]1a55c5be2011-11-29 11:36:311559void TabContents::OnDidFinishLoad(
1560 int64 frame_id,
1561 const GURL& validated_url,
1562 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251563 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311564 DidFinishLoad(frame_id, validated_url, is_main_frame));
1565}
1566
1567void TabContents::OnDidFailLoadWithError(int64 frame_id,
1568 const GURL& validated_url,
1569 bool is_main_frame,
1570 int error_code,
1571 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251572 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311573 DidFailLoad(frame_id, validated_url, is_main_frame,
1574 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181575}
1576
[email protected]c8f73ab2011-01-22 00:05:171577void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271578 content_restrictions_ = restrictions;
1579 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171580}
1581
[email protected]216813952011-05-19 22:21:261582void TabContents::OnGoToEntryAtOffset(int offset) {
1583 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231584 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251585 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261586 if (!entry)
1587 return;
1588 // Note that we don't call NavigationController::GotToOffset() as we don't
1589 // want to create a pending navigation entry (it might end up lingering
1590 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251591 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581592 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511593 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581594 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471595 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571596
1597 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1598 // it in now that we know. This allows us to find the entry when it commits.
1599 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231600 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331601 entry->set_site_instance(
1602 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571603 }
[email protected]216813952011-05-19 22:21:261604 }
1605}
1606
1607void TabContents::OnUpdateZoomLimits(int minimum_percent,
1608 int maximum_percent,
1609 bool remember) {
1610 minimum_zoom_percent_ = minimum_percent;
1611 maximum_zoom_percent_ = maximum_percent;
1612 temporary_zoom_settings_ = !remember;
1613}
1614
[email protected]0bfbf882011-12-22 18:19:271615void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481616 download_stats::RecordDownloadSource(
1617 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261618 // Check if the URL to save matches the URL of the main frame. Since this
1619 // message originates from Pepper plugins, it may not be the case if the
1620 // plugin is an embedded element.
1621 GURL main_frame_url = GetURL();
1622 if (!main_frame_url.is_valid())
1623 return;
1624 bool is_main_frame = (url == main_frame_url);
1625 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271626}
1627
[email protected]3a29a6e2011-08-24 18:26:211628void TabContents::OnEnumerateDirectory(int request_id,
1629 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591630 ChildProcessSecurityPolicyImpl* policy =
1631 ChildProcessSecurityPolicyImpl::GetInstance();
1632 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1633 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211634}
1635
[email protected]7d189022011-08-25 22:54:201636void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511637 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201638}
1639
1640void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1641 const GURL& url,
1642 const string16& title) {
[email protected]b9535422012-02-09 01:47:591643 ChildProcessSecurityPolicyImpl* policy =
1644 ChildProcessSecurityPolicyImpl::GetInstance();
1645 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1646 return;
[email protected]6934a702011-12-20 00:04:511647 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201648}
1649
[email protected]b888919c2011-09-02 00:32:161650void TabContents::OnFindReply(int request_id,
1651 int number_of_matches,
1652 const gfx::Rect& selection_rect,
1653 int active_match_ordinal,
1654 bool final_update) {
[email protected]6934a702011-12-20 00:04:511655 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1656 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001657 // Send a notification to the renderer that we are ready to receive more
1658 // results from the scoping effort of the Find operation. The FindInPage
1659 // scoping is asynchronous and periodically sends results back up to the
1660 // browser using IPC. In an effort to not spam the browser we have the
1661 // browser send an ACK for each FindReply message and have the renderer
1662 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581663 GetRenderViewHostImpl()->Send(
1664 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161665}
1666
[email protected]d952a052011-09-06 18:42:451667void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511668 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451669}
1670
[email protected]7fc4bbb2011-09-08 21:23:101671void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1672 bool blocked_by_policy) {
1673 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251674 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101675 AppCacheAccessed(manifest_url, blocked_by_policy));
1676}
1677
[email protected]96d185d2009-04-24 03:28:541678// Notifies the RenderWidgetHost instance about the fact that the page is
1679// loading, or done loading and calls the base implementation.
1680void TabContents::SetIsLoading(bool is_loading,
1681 LoadNotificationDetails* details) {
1682 if (is_loading == is_loading_)
1683 return;
1684
1685 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211686 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541687 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561688 upload_size_ = 0;
1689 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541690 }
1691
1692 render_manager_.SetIsLoading(is_loading);
1693
1694 is_loading_ = is_loading;
1695 waiting_for_response_ = is_loading;
1696
[email protected]6ebdc9b2010-09-27 16:55:571697 if (delegate_)
1698 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461699 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541700
[email protected]432115822011-07-10 15:52:271701 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1702 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071703 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541704 if (details)
[email protected]6c2381d2011-10-19 02:52:531705 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071706 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501707 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541708 det);
1709}
1710
[email protected]420ae012009-04-24 05:16:321711void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131712 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321713 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561714 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381715 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441716 // that opened the window, as long as both renderers have the same
1717 // privileges.
[email protected]1fd1a502011-03-30 16:55:561718 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561719 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581720 // web_ui might be NULL if the URL refers to a non-existent extension.
1721 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401722 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521723 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441724 }
1725 }
[email protected]1fd1a502011-03-30 16:55:561726 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441727 }
1728
[email protected]4e697b042011-07-08 06:44:561729 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321730 // Clear the status bubble. This is a workaround for a bug where WebKit
1731 // doesn't let us know that the cursor left an element during a
1732 // transition (this is also why the mouse cursor remains as a hand after
1733 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1734 // clear the bubble when a user navigates to a named anchor in the same
1735 // page.
[email protected]36fc0392011-12-25 03:59:511736 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321737 }
1738
[email protected]a6e82fc2010-02-24 22:28:141739 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471740 // Once the main frame is navigated, we're no longer considered to have
1741 // displayed insecure content.
1742 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171743 }
[email protected]ce5c4502009-05-06 16:46:111744
[email protected]3c9e1872010-11-18 16:17:491745 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251746 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041747 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321748}
1749
1750void TabContents::DidNavigateAnyFramePostCommit(
1751 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131752 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321753 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061754 // If we navigate off the page, reset JavaScript state. This does nothing
1755 // to prevent a malicious script from spamming messages, since the script
1756 // could just reload the page to stop blocking.
1757 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551758 dialog_creator_->ResetJavaScriptState(this);
1759 dialog_creator_ = NULL;
1760 }
[email protected]420ae012009-04-24 05:16:321761
[email protected]3c9e1872010-11-18 16:17:491762 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251763 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041764 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321765}
1766
[email protected]74ce1ad2011-12-16 21:51:461767void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1768 // If we are creating a RVH for a restored controller, then we need to make
1769 // sure the RenderView starts with a next_page_id_ larger than the number
1770 // of restored entries. This must be called before the RenderView starts
1771 // navigating (to avoid a race between the browser updating max_page_id and
1772 // the renderer updating next_page_id_). Because of this, we only call this
1773 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561774 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581775 if (max_restored_page_id >
1776 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1777 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1778 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321779}
1780
[email protected]10f417c52011-12-28 21:04:231781bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571782 const string16& title) {
[email protected]420ae012009-04-24 05:16:321783 // For file URLs without a title, use the pathname instead. In the case of a
1784 // synthesized title, we don't want the update to count toward the "one set
1785 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511786 string16 final_title;
[email protected]420ae012009-04-24 05:16:321787 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511788 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1789 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321790 explicit_set = false; // Don't count synthetic titles toward the set limit.
1791 } else {
[email protected]acafd272011-07-26 17:35:571792 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321793 explicit_set = true;
1794 }
1795
[email protected]987fc3a2011-05-26 14:18:091796 // If a page is created via window.open and never navigated,
1797 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551798 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091799 if (entry) {
[email protected]36fc0392011-12-25 03:59:511800 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091801 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321802
[email protected]36fc0392011-12-25 03:59:511803 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091804 } else {
1805 if (page_title_when_no_navigation_entry_ == final_title)
1806 return false; // Nothing changed, don't bother.
1807
1808 page_title_when_no_navigation_entry_ = final_title;
1809 }
[email protected]420ae012009-04-24 05:16:321810
[email protected]420ae012009-04-24 05:16:321811 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231812 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321813
[email protected]2bb171882012-03-07 02:09:461814 std::pair<content::NavigationEntry*, bool> details =
1815 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141816
[email protected]ad50def52011-10-19 23:17:071817 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441818 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1819 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461820 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041821
[email protected]420ae012009-04-24 05:16:321822 return true;
1823}
1824
1825void TabContents::NotifySwapped() {
1826 // After sending out a swap notification, we need to send a disconnect
1827 // notification so that clients that pick up a pointer to |this| can NULL the
1828 // pointer. See Bug 1230284.
1829 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071830 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201831 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1832 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071833 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321834}
1835
1836void TabContents::NotifyConnected() {
1837 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071838 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121839 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1840 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071841 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321842}
1843
1844void TabContents::NotifyDisconnected() {
1845 if (!notify_disconnection_)
1846 return;
1847
1848 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071849 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321850 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1851 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071852 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321853}
1854
[email protected]8d3347f2009-07-09 22:00:211855RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321856 return view_.get();
1857}
1858
[email protected]8d3347f2009-07-09 22:00:211859RenderViewHostDelegate::RendererManagement*
1860TabContents::GetRendererManagementDelegate() {
1861 return &render_manager_;
1862}
1863
[email protected]daf82f82011-10-31 22:35:311864content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371865 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461866 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511867}
1868
[email protected]768c5472011-12-26 19:06:171869WebContents* TabContents::GetAsWebContents() {
1870 return this;
1871}
1872
[email protected]da4dfc42011-10-12 15:53:561873content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431874 return view_type_;
[email protected]7b291f92009-08-14 05:43:531875}
1876
[email protected]b7a756d42012-01-23 18:08:171877gfx::Rect TabContents::GetRootWindowResizerRect() const {
1878 if (delegate_)
1879 return delegate_->GetRootWindowResizerRect();
1880 return gfx::Rect();
1881}
1882
[email protected]420ae012009-04-24 05:16:321883void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071884 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271885 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321886 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531887 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231888 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321889 if (!entry)
1890 return;
1891
1892 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351893 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561894 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581895 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321896
1897 if (entry->IsViewSourceMode()) {
1898 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581899 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1900 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321901 }
[email protected]0666aef2009-05-13 19:48:081902
[email protected]d487beefe2011-12-21 05:41:211903 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261904
1905 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251906 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321907}
1908
1909void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521910 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321911 // Don't notify the world, since this came from a renderer in the
1912 // background.
1913 return;
1914 }
1915
1916 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311917 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231918 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301919
1920 // Restore the focus to the tab (otherwise the focus will be on the top
1921 // window).
[email protected]484ae5912010-09-29 19:16:141922 if (was_crashed && !FocusLocationBarByDefault() &&
1923 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301924 Focus();
[email protected]484ae5912010-09-29 19:16:141925 }
[email protected]32ded2212011-11-10 18:51:431926
[email protected]d8c660432011-12-22 20:51:251927 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321928}
1929
[email protected]443b80e2010-12-14 00:42:231930void TabContents::RenderViewGone(RenderViewHost* rvh,
1931 base::TerminationStatus status,
1932 int error_code) {
[email protected]151a63d2011-12-20 22:32:521933 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321934 // The pending page's RenderViewHost is gone.
1935 return;
1936 }
1937
1938 SetIsLoading(false, NULL);
1939 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231940 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311941 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321942
[email protected]d8c660432011-12-22 20:51:251943 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271944 observers_,
[email protected]be1f56ab2011-12-22 06:55:311945 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321946}
1947
[email protected]2e4633c2009-07-09 16:58:061948void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481949 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251950 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061951}
1952
[email protected]420ae012009-04-24 05:16:321953void TabContents::DidNavigate(RenderViewHost* rvh,
1954 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581955 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321956 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371957
[email protected]434f69f2012-02-06 21:56:521958 // Update the site of the SiteInstance if it doesn't have one yet, unless
1959 // this is for about:blank. In that case, the SiteInstance can still be
1960 // considered unused until a navigation to a real page.
1961 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1962 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331963 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521964 }
[email protected]420ae012009-04-24 05:16:321965
1966 // Need to update MIME type here because it's referred to in
1967 // UpdateNavigationCommands() called by RendererDidNavigate() to
1968 // determine whether or not to enable the encoding menu.
1969 // It's updated only for the main frame. For a subframe,
1970 // RenderView::UpdateURL does not set params.contents_mime_type.
1971 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1972 // TODO(jungshik): Add a test for the encoding menu to avoid
1973 // regressing it again.
[email protected]2905f742011-10-13 03:51:581974 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321975 contents_mime_type_ = params.contents_mime_type;
1976
[email protected]8286f51a2011-05-31 17:39:131977 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001978 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391979
[email protected]a9c0bfe2010-09-17 08:35:221980 // Send notification about committed provisional loads. This notification is
1981 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1982 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081983 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071984 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1985 // that is not recorded in the navigation history. For the purpose of
1986 // tracking navigation events, we treat this event as a sub frame navigation
1987 // event.
1988 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581989 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221990 // Whether or not a page transition was triggered by going backward or
1991 // forward in the history is only stored in the navigation controller's
1992 // entry list.
1993 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511994 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581995 content::PAGE_TRANSITION_FORWARD_BACK)) {
1996 transition_type = content::PageTransitionFromInt(
1997 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221998 }
[email protected]0d60f0192011-04-14 12:40:101999 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102001 DidCommitProvisionalLoadForFrame(params.frame_id,
2002 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222003 }
2004
[email protected]76543b92009-08-31 17:27:452005 if (!did_navigate)
2006 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322007
2008 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2009 // for the appropriate notification (best) or you can add it to
2010 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2011 // necessary, please).
2012
2013 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002014 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322015 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512016 if (delegate_)
2017 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002018 }
[email protected]420ae012009-04-24 05:16:322019 DidNavigateAnyFramePostCommit(rvh, details, params);
2020}
2021
2022void TabContents::UpdateState(RenderViewHost* rvh,
2023 int32 page_id,
2024 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152025 // Ensure that this state update comes from either the active RVH or one of
2026 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522027 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322028
2029 // We must be prepared to handle state updates for any page, these occur
2030 // when the user is scrolling and entering form data, as well as when we're
2031 // leaving a page, in which case our state may have already been moved to
2032 // the next page. The navigation controller will look up the appropriate
2033 // NavigationEntry and update it when it is notified via the delegate.
2034
2035 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582036 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322037 if (entry_index < 0)
2038 return;
[email protected]10f417c52011-12-28 21:04:232039 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322040
[email protected]36fc0392011-12-25 03:59:512041 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322042 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512043 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322044 controller_.NotifyEntryChanged(entry, entry_index);
2045}
2046
2047void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572048 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462049 const string16& title,
2050 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322051 // If we have a title, that's a pretty good indication that we've started
2052 // getting useful data.
2053 SetNotWaitingForResponse();
2054
[email protected]73eb2602012-02-09 19:50:552055 // Try to find the navigation entry, which might not be the current one.
2056 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232057 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582058 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092059
[email protected]73eb2602012-02-09 19:50:552060 // We can handle title updates when we don't have an entry in
2061 // UpdateTitleForEntry, but only if the update is from the current RVH.
2062 if (!entry && rvh != GetRenderViewHost())
2063 return;
2064
[email protected]a49e10b2011-08-01 23:57:462065 // TODO(evan): make use of title_direction.
2066 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092067 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322068 return;
2069
2070 // Broadcast notifications when the UI should be updated.
2071 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462072 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322073}
2074
[email protected]420ae012009-04-24 05:16:322075void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402076 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312077 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322078}
2079
2080void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512081 if (delegate_)
2082 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322083}
2084
[email protected]420ae012009-04-24 05:16:322085void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292086 // The UI may be in an event-tracking loop, such as between the
2087 // mouse-down and mouse-up in text selection or a button click.
2088 // Defer the close until after tracking is complete, so that we
2089 // don't free objects out from under the UI.
2090 // TODO(shess): This could probably be integrated with the
2091 // IsDoingDrag() test below. Punting for now because I need more
2092 // research to understand how this impacts platforms other than Mac.
2093 // TODO(shess): This could get more fine-grained. For instance,
2094 // closing a tab in another window while selecting text in the
2095 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212096 if (GetView()->IsEventTracking()) {
2097 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292098 return;
2099 }
2100
[email protected]24a4d1062009-07-10 23:10:422101 // If we close the tab while we're in the middle of a drag, we'll crash.
2102 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212103 if (GetView()->IsDoingDrag()) {
2104 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422105 return;
2106 }
2107
[email protected]420ae012009-04-24 05:16:322108 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522109 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512110 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322111}
2112
[email protected]cd9ed79d2011-11-15 19:22:572113void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522114 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512115 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572116}
2117
[email protected]420ae012009-04-24 05:16:322118void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512119 if (delegate_ && delegate_->IsPopupOrPanel(this))
2120 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322121}
2122
[email protected]7ab1e7d62009-10-14 23:32:012123void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322124 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492125
[email protected]6934a702011-12-20 00:04:512126 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212127 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512128 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002129 }
[email protected]3c9e1872010-11-18 16:17:492130
2131 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252132 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322133}
2134
[email protected]7ab1e7d62009-10-14 23:32:012135void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322136 scoped_ptr<LoadNotificationDetails> details;
2137
[email protected]10f417c52011-12-28 21:04:232138 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322139 // An entry may not exist for a stop when loading an initial blank page or
2140 // if an iframe injected by script into a blank page finishes loading.
2141 if (entry) {
[email protected]420ae012009-04-24 05:16:322142 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2143
2144 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512145 entry->GetVirtualURL(),
2146 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322147 elapsed,
2148 &controller_,
2149 controller_.GetCurrentEntryIndex()));
2150 }
2151
[email protected]420ae012009-04-24 05:16:322152 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492153
2154 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252155 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322156}
2157
[email protected]c95fa8b2011-04-28 20:26:162158void TabContents::DidCancelLoading() {
2159 controller_.DiscardNonCommittedEntries();
2160
2161 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462162 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162163}
2164
[email protected]1a3c3cb2010-12-16 21:03:402165void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512166 if (delegate_)
2167 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402168}
2169
[email protected]952a68e2011-11-17 00:36:102170void TabContents::DocumentAvailableInMainFrame(
2171 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252172 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102173 DocumentAvailableInMainFrame());
2174}
2175
[email protected]25497492010-09-11 15:15:082176void TabContents::DocumentOnLoadCompletedInMainFrame(
2177 RenderViewHost* render_view_host,
2178 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072179 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272180 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322181 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532182 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082183}
2184
[email protected]ae5184d62011-10-06 19:25:582185void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152186 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582187 WindowOpenDisposition disposition,
2188 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482189 // Delegate to RequestTransferURL because this is just the generic
2190 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582191 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482192 GlobalRequestID());
2193}
2194
2195void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582196 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482197 WindowOpenDisposition disposition,
2198 int64 source_frame_id,
2199 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202200 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582201 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582202 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352203 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322204 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2205 // generated suggestions).
2206 //
[email protected]e0112912011-02-02 22:54:352207 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162208 // want web sites to see a referrer of "chrome://blah" (and some
2209 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322210 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432211 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222212 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482213 false /* is_renderer_initiated */);
2214 params.transferred_global_request_id = old_request_id;
2215 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222216 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322217 } else {
[email protected]6bf6a6b52012-02-03 15:41:432218 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482219 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2220 params.transferred_global_request_id = old_request_id;
2221 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582222 }
2223 if (new_contents) {
2224 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252225 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582226 DidOpenRequestedURL(new_contents,
2227 url,
2228 referrer,
2229 disposition,
2230 transition_type,
2231 source_frame_id));
[email protected]420ae012009-04-24 05:16:322232 }
2233}
2234
[email protected]420ae012009-04-24 05:16:322235void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342236 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412237 const string16& message,
2238 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322239 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472240 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322241 IPC::Message* reply_msg,
2242 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072243 // Suppress JavaScript dialogs when requested. Also suppress messages when
2244 // showing an interstitial as it's shown over the previous page and we don't
2245 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502246 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582247 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272248 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072249 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522250 delegate_->ShouldSuppressDialogs() ||
2251 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322252
2253 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432254 std::string accept_lang = content::GetContentClient()->browser()->
2255 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552256 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522257 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432258 this,
2259 frame_url.GetOrigin(),
2260 accept_lang,
2261 javascript_message_type,
2262 message,
[email protected]51da7e32012-01-30 19:24:522263 default_prompt,
2264 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432265 reply_msg),
[email protected]51da7e32012-01-30 19:24:522266 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322267 }
[email protected]3ab9cb82011-06-03 18:02:072268
2269 if (suppress_this_message) {
2270 // If we are suppressing messages, just reply as if the user immediately
2271 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342272 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072273 }
2274
2275 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322276}
2277
[email protected]fedec012012-01-28 03:09:342278void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412279 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322280 bool is_reload,
[email protected]420ae012009-04-24 05:16:322281 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582282 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512283 if (delegate_)
2284 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072285
2286 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582287 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072288 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522289 delegate_->ShouldSuppressDialogs() ||
2290 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152291 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342292 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582293 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502294 return;
2295 }
[email protected]3ab9cb82011-06-03 18:02:072296
[email protected]7ab1e7d62009-10-14 23:32:012297 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552298 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522299 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322300 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522301 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2302 reply_msg));
[email protected]420ae012009-04-24 05:16:322303}
2304
[email protected]420ae012009-04-24 05:16:322305WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542306 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322307}
2308
[email protected]7d472472011-01-22 01:30:252309void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272310 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252311 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222312
[email protected]99907362012-01-11 05:41:402313 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172314 if (rdh) // NULL in unittests.
2315 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252316}
2317
[email protected]fa1cf0b82010-01-15 21:49:442318void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442319 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252320 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442321}
2322
[email protected]420ae012009-04-24 05:16:322323void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2324 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152325 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522326 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152327 return;
2328
[email protected]9f76c1e2012-03-05 15:15:582329 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2330
[email protected]e5fc1632011-08-08 07:51:532331 // Ignore renderer unresponsive event if debugger is attached to the tab
2332 // since the event may be a result of the renderer sitting on a breakpoint.
2333 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442334 DevToolsAgentHost* agent =
2335 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2336 if (agent &&
2337 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532338 return;
2339
[email protected]420ae012009-04-24 05:16:322340 if (is_during_unload) {
2341 // Hang occurred while firing the beforeunload/unload handler.
2342 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582343 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322344
2345 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2346 return;
2347
2348 // If the tab hangs in the beforeunload/unload handler there's really
2349 // nothing we can do to recover. Pretend the unload listeners have
2350 // all fired and close the tab. If the hang is in the beforeunload handler
2351 // then the user will not have the option of cancelling the close.
2352 Close(rvh);
2353 return;
2354 }
2355
[email protected]9f76c1e2012-03-05 15:15:582356 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472357 return;
2358
[email protected]6934a702011-12-20 00:04:512359 if (delegate_)
2360 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322361}
2362
2363void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512364 if (delegate_)
2365 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322366}
2367
2368void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212369 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562370 uint64 upload_position,
2371 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322372 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562373 upload_position_ = upload_position;
2374 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502375 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202376 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302377 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212378 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322379 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462380 if (IsLoading()) {
2381 NotifyNavigationStateChanged(
2382 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2383 }
[email protected]420ae012009-04-24 05:16:322384}
2385
[email protected]7d472472011-01-22 01:30:252386void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512387 if (delegate_)
2388 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252389}
2390
[email protected]420ae012009-04-24 05:16:322391void TabContents::BeforeUnloadFiredFromRenderManager(
2392 bool proceed,
2393 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512394 if (delegate_)
2395 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322396}
2397
[email protected]3a3d47472010-07-15 21:03:542398void TabContents::DidStartLoadingFromRenderManager(
2399 RenderViewHost* render_view_host) {
2400 DidStartLoading();
2401}
2402
2403void TabContents::RenderViewGoneFromRenderManager(
2404 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232405 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2406 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542407}
2408
[email protected]420ae012009-04-24 05:16:322409void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102410 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262411 gfx::Size size = view_->GetContainerSize();
2412 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2413 // here during container initialization and normal window size will be set
2414 // later. In case of tab duplication this resizing to 0x0 prevents setting
2415 // normal size later so just ignore it.
2416 if (!size.IsEmpty())
2417 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322418}
2419
[email protected]3a3d47472010-07-15 21:03:542420void TabContents::NotifySwappedFromRenderManager() {
2421 NotifySwapped();
2422}
2423
[email protected]d202a7c2012-01-04 07:53:472424NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202425 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542426}
2427
[email protected]d2353452012-01-19 19:53:562428WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2429 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322430}
2431
[email protected]10f417c52011-12-28 21:04:232432NavigationEntry*
2433 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322434 return controller_.GetLastCommittedEntry();
2435}
2436
2437bool TabContents::CreateRenderViewForRenderManager(
2438 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442439 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322440 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522441
[email protected]420ae012009-04-24 05:16:322442 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442443 if (rwh_view)
2444 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322445
[email protected]74ce1ad2011-12-16 21:51:462446 // Make sure we use the correct starting page_id in the new RenderView.
2447 UpdateMaxPageIDIfNecessary(render_view_host);
2448 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582449 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462450
[email protected]9f76c1e2012-03-05 15:15:582451 if (!static_cast<RenderViewHostImpl*>(
2452 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522453 return false;
2454
[email protected]e60c0232011-11-11 19:56:352455#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502456 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2457 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442458 if (rwh_view) {
2459 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2460 render_widget_host->WasResized();
2461 }
[email protected]f8233cc2011-05-31 20:24:502462#endif
2463
[email protected]420ae012009-04-24 05:16:322464 return true;
2465}
2466
[email protected]fedec012012-01-28 03:09:342467void TabContents::OnDialogClosed(RenderViewHost* rvh,
2468 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072469 bool success,
2470 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542471 if (is_showing_before_unload_dialog_ && !success) {
2472 // If a beforeunload dialog is canceled, we need to stop the throbber from
2473 // spinning, since we forced it to start spinning in Navigate.
2474 DidStopLoading();
2475
2476 tab_close_start_time_ = base::TimeTicks();
2477 }
2478 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582479 static_cast<RenderViewHostImpl*>(
2480 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542481}
2482
[email protected]be1f56ab2011-12-22 06:55:312483void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122484 encoding_ = content::GetContentClient()->browser()->
2485 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102486}
[email protected]f45d2a72010-03-08 23:28:352487
[email protected]e30d68d2012-02-09 00:06:262488void TabContents::SaveURL(const GURL& url,
2489 const GURL& referrer,
2490 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142491 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2492 if (!dlm)
2493 return;
2494 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262495 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142496 const NavigationEntry* entry = controller_.GetActiveEntry();
2497 if (entry)
2498 post_id = entry->GetPostID();
2499 }
2500 DownloadSaveInfo save_info;
2501 save_info.prompt_for_save_location = true;
2502 dlm->DownloadUrl(url,
2503 referrer,
2504 "",
2505 true, // prefer_cache
2506 post_id,
2507 save_info,
2508 this);
2509}
2510
[email protected]33f74972010-12-08 16:40:362511void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212512 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442513 // Can be NULL during tests.
2514 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212515 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362516}
[email protected]9f76c1e2012-03-05 15:15:582517
2518RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2519 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2520}