blob: b4dc70e688d7735a0651e97f53f12b7972e3e6f8 [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>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4619#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1220#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1621#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3222#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5423#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0524#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0025#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0126#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0427#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/render_view_host.h"
[email protected]686493142011-07-15 21:47:2230#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5031#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1333#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2334#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4435#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1436#include "content/browser/tab_contents/title_updated_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]b0b67cf2012-01-18 21:59:57126using content::RenderViewHostDelegate;
[email protected]5626b0892012-02-20 14:46:58127using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04128using content::RenderWidgetHostViewPort;
[email protected]adbfb8df2012-02-24 01:19:43129using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33130using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17131using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38132using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09133using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25134using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56135using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22136using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50137using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44138
[email protected]420ae012009-04-24 05:16:32139namespace {
140
141// Amount of time we wait between when a key event is received and the renderer
142// is queried for its state and pushed to the NavigationEntry.
143const int kQueryStateDelay = 5000;
144
[email protected]6ebdc9b2010-09-27 16:55:57145const int kSyncWaitDelay = 40;
146
[email protected]ca406032011-07-19 21:53:05147static const char kDotGoogleDotCom[] = ".google.com";
148
[email protected]420ae012009-04-24 05:16:32149#if defined(OS_WIN)
150
151BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
152 // Note: erase is required to properly paint some widgets borders. This can
153 // be seen with textfields.
154 InvalidateRect(hwnd, NULL, TRUE);
155 return TRUE;
156}
157#endif
158
[email protected]2c5569662011-03-22 20:45:02159ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23160 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50161 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16162 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47163 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02164 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47165 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02166 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47167 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16168 break; // Fall through to rest of function.
169 }
[email protected]5e369672009-11-03 23:48:30170
[email protected]59246c572012-02-10 13:32:13171 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
172 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23173 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13174 browser_context->DidLastSessionExitCleanly()) {
175 if (entry.GetHasPostData())
176 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02177 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13178 }
[email protected]5e369672009-11-03 23:48:30179
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30181}
182
[email protected]10f417c52011-12-28 21:04:23183void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47184 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42185 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50186 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16187 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51188 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54189 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55190 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
191 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51192 params->url = entry.GetURL();
193 params->referrer = entry.GetReferrer();
194 params->transition = entry.GetTransitionType();
195 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00196 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55197 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34198 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47199 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48200 params->transferred_request_child_id =
201 entry.transferred_global_request_id().child_id;
202 params->transferred_request_request_id =
203 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47204
205 if (delegate)
206 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34207}
208
[email protected]420ae012009-04-24 05:16:32209} // namespace
210
[email protected]a81343d232011-12-27 07:39:20211namespace content {
212
213WebContents* WebContents::Create(
214 BrowserContext* browser_context,
215 SiteInstance* site_instance,
216 int routing_id,
217 const WebContents* base_tab_contents,
218 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43219 return new TabContents(
220 browser_context,
221 site_instance,
222 routing_id,
223 static_cast<const TabContents*>(base_tab_contents),
224 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20225}
226}
[email protected]f4f50ef2011-01-21 19:01:19227
228// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32229
[email protected]3d7474ff2011-07-27 17:47:37230TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32231 SiteInstance* site_instance,
232 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07233 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43234 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42235 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07236 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37237 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13238 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10239 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22240 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34241 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23242 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
243 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34244 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21245 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56246 upload_size_(0),
247 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47248 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57249 capturing_contents_(false),
250 is_being_destroyed_(false),
251 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55252 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57253#if defined(OS_WIN)
254 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
255#endif
[email protected]7ab1e7d62009-10-14 23:32:01256 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56257 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38258 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25259 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01260 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25261 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01262 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00263 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43264 content_restrictions_(0),
265 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37266 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32267
[email protected]34ac70502009-09-25 17:07:23268 // We have the initial size of the view be based on the size of the passed in
269 // tab contents (normally a tab from the same window).
270 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21271 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00272
273#if defined(ENABLE_JAVA_BRIDGE)
274 java_bridge_dispatcher_host_manager_.reset(
275 new JavaBridgeDispatcherHostManager(this));
276#endif
[email protected]332af7732009-03-11 13:21:35277}
initial.commit09911bf2008-07-26 23:55:29278
279TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32280 is_being_destroyed_ = true;
281
[email protected]3ab9cb82011-06-03 18:02:07282 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55283 if (dialog_creator_)
284 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07285
[email protected]420ae012009-04-24 05:16:32286 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32287
[email protected]420ae012009-04-24 05:16:32288 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07289 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09290 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
291 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07292 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32293
294 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07295#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32296 // If we still have a window handle, destroy it. GetNativeView can return
297 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42298 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52299 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58300 if (host && host->GetView())
301 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42302 }
[email protected]420ae012009-04-24 05:16:32303#endif
[email protected]7ab1e7d62009-10-14 23:32:01304
305 // OnCloseStarted isn't called in unit tests.
306 if (!tab_close_start_time_.is_null()) {
307 UMA_HISTOGRAM_TIMES("Tab.Close",
308 base::TimeTicks::Now() - tab_close_start_time_);
309 }
[email protected]b5a1d11c2011-02-17 03:09:42310
[email protected]d8c660432011-12-22 20:51:25311 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08312
[email protected]6934a702011-12-20 00:04:51313 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42314}
315
[email protected]64d69de42012-02-06 00:19:54316WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
317 const GURL& url) {
318 WebPreferences prefs;
319
320 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
321
322 prefs.developer_extras_enabled = true;
323 prefs.javascript_enabled =
324 !command_line.HasSwitch(switches::kDisableJavaScript);
325 prefs.web_security_enabled =
326 !command_line.HasSwitch(switches::kDisableWebSecurity);
327 prefs.plugins_enabled =
328 !command_line.HasSwitch(switches::kDisablePlugins);
329 prefs.java_enabled =
330 !command_line.HasSwitch(switches::kDisableJava);
331
332 prefs.uses_page_cache =
333 command_line.HasSwitch(switches::kEnableFastback);
334 prefs.remote_fonts_enabled =
335 !command_line.HasSwitch(switches::kDisableRemoteFonts);
336 prefs.xss_auditor_enabled =
337 !command_line.HasSwitch(switches::kDisableXSSAuditor);
338 prefs.application_cache_enabled =
339 !command_line.HasSwitch(switches::kDisableApplicationCache);
340
341 prefs.local_storage_enabled =
342 !command_line.HasSwitch(switches::kDisableLocalStorage);
343 prefs.databases_enabled =
344 !command_line.HasSwitch(switches::kDisableDatabases);
345 prefs.webaudio_enabled =
346 !command_line.HasSwitch(switches::kDisableWebAudio);
347
348 prefs.experimental_webgl_enabled =
349 GpuProcessHost::gpu_enabled() &&
350 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
351 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
352
353 prefs.gl_multisampling_enabled =
354 !command_line.HasSwitch(switches::kDisableGLMultisampling);
355 prefs.privileged_webgl_extensions_enabled =
356 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
357 prefs.site_specific_quirks_enabled =
358 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
359 prefs.allow_file_access_from_file_urls =
360 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
361 prefs.show_composited_layer_borders =
362 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
363 prefs.show_composited_layer_tree =
364 command_line.HasSwitch(switches::kShowCompositedLayerTree);
365 prefs.show_fps_counter =
366 command_line.HasSwitch(switches::kShowFPSCounter);
367 prefs.accelerated_compositing_enabled =
368 GpuProcessHost::gpu_enabled() &&
369 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
370 prefs.threaded_compositing_enabled =
371 command_line.HasSwitch(switches::kEnableThreadedCompositing);
372 prefs.force_compositing_mode =
373 command_line.HasSwitch(switches::kForceCompositingMode);
374 prefs.fixed_position_compositing_enabled =
375 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
376 prefs.accelerated_2d_canvas_enabled =
377 GpuProcessHost::gpu_enabled() &&
378 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58379 prefs.deferred_2d_canvas_enabled =
380 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36381 prefs.threaded_animation_enabled =
382 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54383 prefs.accelerated_painting_enabled =
384 GpuProcessHost::gpu_enabled() &&
385 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
386 prefs.accelerated_filters_enabled =
387 GpuProcessHost::gpu_enabled() &&
388 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
389 prefs.accelerated_layers_enabled =
390 prefs.accelerated_animation_enabled =
391 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
392 prefs.composite_to_texture_enabled =
393 command_line.HasSwitch(switches::kEnableCompositeToTexture);
394 prefs.accelerated_plugins_enabled =
395 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
396 prefs.accelerated_video_enabled =
397 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
398 prefs.partial_swap_enabled =
399 command_line.HasSwitch(switches::kEnablePartialSwap);
400 prefs.interactive_form_validation_enabled =
401 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
402 prefs.fullscreen_enabled =
403 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16404 prefs.css_regions_enabled =
405 command_line.HasSwitch(switches::kEnableCssRegions);
406
[email protected]64d69de42012-02-06 00:19:54407
408#if defined(OS_MACOSX)
409 bool default_enable_scroll_animator = true;
410#else
411 // On CrOS, the launcher always passes in the --enable flag.
412 bool default_enable_scroll_animator = false;
413#endif
414 prefs.enable_scroll_animator = default_enable_scroll_animator;
415 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
416 prefs.enable_scroll_animator = true;
417 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
418 prefs.enable_scroll_animator = false;
419
420 prefs.visual_word_movement_enabled =
421 command_line.HasSwitch(switches::kEnableVisualWordMovement);
422 prefs.per_tile_painting_enabled =
423 command_line.HasSwitch(switches::kEnablePerTilePainting);
424
425 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32426 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54427 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11428 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
429 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54430 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11431 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54432 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11433 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54434 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11435 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54436 prefs.gl_multisampling_enabled = false;
437
438 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45439 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32440 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54441 prefs.accelerated_video_enabled = false;
442 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45443 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54444 }
445 }
446
[email protected]b9535422012-02-09 01:47:59447 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58448 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54449 prefs.loads_images_automatically = true;
450 prefs.javascript_enabled = true;
451 }
452
453 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
454
455 // Force accelerated compositing and 2d canvas off for chrome:, about: and
456 // chrome-devtools: pages (unless it's specifically allowed).
457 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54458 url.SchemeIs(chrome::kChromeUIScheme) ||
459 (url.SchemeIs(chrome::kAboutScheme) &&
460 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25461 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54462 prefs.accelerated_compositing_enabled = false;
463 prefs.accelerated_2d_canvas_enabled = false;
464 }
465
[email protected]43d9d782012-03-01 15:40:09466 int default_device_scale_factor;
467 base::StringToInt(command_line.GetSwitchValueASCII(
468 switches::kDefaultDeviceScaleFactor),
469 &default_device_scale_factor);
470
471 prefs.default_device_scale_factor = default_device_scale_factor;
472
[email protected]2e21fe292012-03-02 22:52:32473 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54474
475 return prefs;
476}
477
[email protected]d202a7c2012-01-04 07:53:47478NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20479 return controller_;
480}
481
[email protected]765187182012-01-11 23:59:28482RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
483 return &render_manager_;
484}
485
[email protected]724159a2010-12-30 01:11:18486bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56487 if (GetWebUI() &&
488 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17489 return true;
[email protected]d2353452012-01-19 19:53:56490 }
[email protected]f82d57b52011-04-27 19:13:17491
[email protected]d8c660432011-12-22 20:51:25492 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
493 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10494 while ((observer = it.GetNext()) != NULL)
495 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53496 return true;
[email protected]403415a2011-01-10 18:57:53497
[email protected]724159a2010-12-30 01:11:18498 bool handled = true;
499 bool message_is_ok = true;
500 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58501 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
502 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24503 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
504 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18505 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
506 OnDidStartProvisionalLoadForFrame)
507 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
508 OnDidRedirectProvisionalLoad)
509 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
510 OnDidFailProvisionalLoadWithError)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
512 OnDidLoadResourceFromMemoryCache)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
514 OnDidDisplayInsecureContent)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
516 OnDidRunInsecureContent)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
518 OnDocumentLoadedInFrame)
519 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17520 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
521 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25522 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26523 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59524 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21525 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20526 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
527 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
528 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16529 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45530 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10531 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18532 IPC_MESSAGE_UNHANDLED(handled = false)
533 IPC_END_MESSAGE_MAP_EX()
534
535 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38536 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18537 GetRenderProcessHost()->ReceivedBadMessage();
538 }
539
540 return handled;
541}
542
[email protected]6c2e472f2011-08-24 23:26:18543void TabContents::RunFileChooser(
544 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23545 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51546 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18547}
548
[email protected]c5eed492012-01-04 17:07:50549NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56550 return controller_;
551}
552
[email protected]c5eed492012-01-04 17:07:50553const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56554 return controller_;
555}
556
[email protected]627e0512011-12-21 22:55:30557content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55558 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30559}
560
[email protected]f5fa20e2011-12-21 22:35:56561void TabContents::SetViewType(content::ViewType type) {
562 view_type_ = type;
563}
564
[email protected]ea049a02011-12-25 21:37:09565content::ViewType TabContents::GetViewType() const {
566 return view_type_;
567}
568
[email protected]be1f56ab2011-12-22 06:55:31569const GURL& TabContents::GetURL() const {
570 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23571 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51572 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31573}
574
575
576const base::PropertyBag* TabContents::GetPropertyBag() const {
577 return &property_bag_;
578}
579
580base::PropertyBag* TabContents::GetPropertyBag() {
581 return &property_bag_;
582}
583
584content::WebContentsDelegate* TabContents::GetDelegate() {
585 return delegate_;
586}
587
588void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
589 // TODO(cbentzel): remove this debugging code?
590 if (delegate == delegate_)
591 return;
592 if (delegate_)
593 delegate_->Detach(this);
594 delegate_ = delegate;
595 if (delegate_)
596 delegate_->Attach(this);
597}
598
[email protected]f3b1a082011-11-18 00:34:30599content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03600 if (render_manager_.current_host())
[email protected]9f76c1e2012-03-05 15:15:58601 return render_manager_.current_host()->GetProcess();
[email protected]4d0df262011-10-03 20:05:03602 else
603 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16604}
605
[email protected]be1f56ab2011-12-22 06:55:31606RenderViewHost* TabContents::GetRenderViewHost() const {
607 return render_manager_.current_host();
608}
609
610RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
611 return render_manager_.GetRenderWidgetHostView();
612}
613
[email protected]8643e6d2012-01-18 20:26:10614content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31615 return view_.get();
616}
617
[email protected]01ec4ec2012-01-18 04:13:47618content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50619 WebUIControllerFactory* factory =
620 content::GetContentClient()->browser()->GetWebUIControllerFactory();
621 if (!factory)
622 return NULL;
[email protected]d2353452012-01-19 19:53:56623 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22624 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50625 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22626 if (controller) {
627 web_ui->SetController(controller);
628 return web_ui;
629 }
630
631 delete web_ui;
632 return NULL;
633}
634
[email protected]01ec4ec2012-01-18 04:13:47635content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31636 return render_manager_.web_ui() ? render_manager_.web_ui()
637 : render_manager_.pending_web_ui();
638}
639
[email protected]01ec4ec2012-01-18 04:13:47640content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31641 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34642}
643
[email protected]96d185d2009-04-24 03:28:54644const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55645 // Transient entries take precedence. They are used for interstitial pages
646 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23647 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08648 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20649 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30650 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23651 if (entry) {
[email protected]b5cca982011-05-26 04:42:08652 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23653 }
[email protected]7ade2732011-02-10 00:13:58654 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
655 render_manager_.pending_web_ui() : render_manager_.web_ui();
656 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54657 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55658 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54659 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35660 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22661 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54662 if (!title.empty())
663 return title;
664 }
665 }
666
667 // We use the title for the last committed entry rather than a pending
668 // navigation entry. For example, when the user types in a URL, we want to
669 // keep the old page's title until the new load has committed and we get a new
670 // title.
[email protected]96d185d2009-04-24 03:28:54671 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23672 if (entry) {
[email protected]b5cca982011-05-26 04:42:08673 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23674 }
[email protected]987fc3a2011-05-26 14:18:09675
676 // |page_title_when_no_navigation_entry_| is finally used
677 // if no title cannot be retrieved.
678 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54679}
680
[email protected]d5f942ba2008-09-26 19:30:34681int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46682 return GetMaxPageIDForSiteInstance(GetSiteInstance());
683}
684
685int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33686 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
687 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46688
[email protected]b6583592012-01-25 19:52:33689 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34690}
691
692void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46693 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
694}
695
[email protected]b6583592012-01-25 19:52:33696void TabContents::UpdateMaxPageIDForSiteInstance(
697 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46698 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33699 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34700}
701
[email protected]91854cd2012-01-10 19:43:57702void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
703 max_page_ids_ = tab_contents->max_page_ids_;
704}
705
[email protected]96d185d2009-04-24 03:28:54706SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58707 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54708}
709
[email protected]77362eb2011-08-01 17:18:38710SiteInstance* TabContents::GetPendingSiteInstance() const {
711 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
712 render_manager_.pending_render_view_host() :
713 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58714 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38715}
716
[email protected]be1f56ab2011-12-22 06:55:31717bool TabContents::IsLoading() const {
718 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49719}
720
[email protected]be1f56ab2011-12-22 06:55:31721bool TabContents::IsWaitingForResponse() const {
722 return waiting_for_response_;
723}
724
725const net::LoadStateWithParam& TabContents::GetLoadState() const {
726 return load_state_;
727}
728
729const string16& TabContents::GetLoadStateHost() const {
730 return load_state_host_;
731}
732
733uint64 TabContents::GetUploadSize() const {
734 return upload_size_;
735}
736
737uint64 TabContents::GetUploadPosition() const {
738 return upload_position_;
739}
740
741const std::string& TabContents::GetEncoding() const {
742 return encoding_;
743}
744
745bool TabContents::DisplayedInsecureContent() const {
746 return displayed_insecure_content_;
747}
748
749void TabContents::SetCapturingContents(bool cap) {
750 capturing_contents_ = cap;
751}
752
753bool TabContents::IsCrashed() const {
754 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
755 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
756 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49757}
758
[email protected]443b80e2010-12-14 00:42:23759void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
760 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34761 return;
762
[email protected]443b80e2010-12-14 00:42:23763 crashed_status_ = status;
764 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46765 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34766}
767
[email protected]be1f56ab2011-12-22 06:55:31768base::TerminationStatus TabContents::GetCrashedStatus() const {
769 return crashed_status_;
770}
771
772bool TabContents::IsBeingDestroyed() const {
773 return is_being_destroyed_;
774}
775
[email protected]d5f942ba2008-09-26 19:30:34776void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
777 if (delegate_)
778 delegate_->NavigationStateChanged(this, changed_flags);
779}
780
[email protected]96d185d2009-04-24 03:28:54781void TabContents::DidBecomeSelected() {
782 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04783 RenderWidgetHostViewPort* rwhv =
784 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16785 if (rwhv) {
786 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43787#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16788 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43789#endif
790 }
[email protected]96d185d2009-04-24 03:28:54791
[email protected]5ac20162010-11-24 23:33:11792 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38793
[email protected]d8c660432011-12-22 20:51:25794 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59795
796 // The resize rect might have changed while this was inactive -- send the new
797 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58798 RenderViewHostImpl* rvh =
799 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59800 if (rvh) {
801 rvh->ResizeRectChanged(GetRootWindowResizerRect());
802 }
[email protected]96d185d2009-04-24 03:28:54803}
804
[email protected]be1f56ab2011-12-22 06:55:31805
806base::TimeTicks TabContents::GetLastSelectedTime() const {
807 return last_selected_time_;
808}
809
[email protected]96d185d2009-04-24 03:28:54810void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31811 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52812 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
813 // open a tab in then background, then closes the tab before selecting it.
814 // This is because closing the tab calls TabContents::Destroy(), which
815 // removes the |GetRenderViewHost()|; then when we actually destroy the
816 // window, OnWindowPosChanged() notices and calls HideContents() (which
817 // calls us).
[email protected]c30585c2012-02-16 15:02:04818 RenderWidgetHostViewPort* rwhv =
819 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16820 if (rwhv)
821 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54822 }
823
[email protected]ad50def52011-10-19 23:17:07824 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09825 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
826 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07827 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54828}
829
[email protected]be1f56ab2011-12-22 06:55:31830void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04831 RenderWidgetHostViewPort* rwhv =
832 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31833 if (rwhv)
834 rwhv->DidBecomeSelected();
835}
836
837void TabContents::HideContents() {
838 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
839 // our superclass HideContents(), because some callers want to be very picky
840 // about the order in which these get called. In addition to making the code
841 // here practically impossible to understand, this also means we end up
842 // calling TabContents::WasHidden() twice if callers call both versions of
843 // HideContents() on a TabContents.
844 WasHidden();
845}
846
847bool TabContents::NeedToFireBeforeUnload() {
848 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27849 return WillNotifyDisconnection() &&
850 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58851 !static_cast<RenderViewHostImpl*>(
852 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31853}
854
[email protected]0bfbf882011-12-22 18:19:27855void TabContents::Stop() {
856 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25857 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27858}
859
[email protected]d9083482012-01-06 00:38:46860WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27861 // We create a new SiteInstance so that the new tab won't share processes
862 // with the old one. This can be changed in the future if we need it to share
863 // processes for some reason.
864 TabContents* tc = new TabContents(
865 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33866 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27867 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20868 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27869 return tc;
870}
871
[email protected]2a6bc3e2011-12-28 23:51:33872void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27873 WindowOpenDisposition disposition,
874 const gfx::Rect& initial_pos,
875 bool user_gesture) {
876 if (!delegate_)
877 return;
878
879 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
880 user_gesture);
881}
882
883gfx::NativeView TabContents::GetContentNativeView() const {
884 return view_->GetContentNativeView();
885}
886
887gfx::NativeView TabContents::GetNativeView() const {
888 return view_->GetNativeView();
889}
890
891void TabContents::GetContainerBounds(gfx::Rect* out) const {
892 view_->GetContainerBounds(out);
893}
894
895void TabContents::Focus() {
896 view_->Focus();
897}
898
[email protected]d8c660432011-12-22 20:51:25899void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31900 observers_.AddObserver(observer);
901}
902
[email protected]d8c660432011-12-22 20:51:25903void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31904 observers_.RemoveObserver(observer);
905}
906
[email protected]d5f942ba2008-09-26 19:30:34907void TabContents::Activate() {
908 if (delegate_)
909 delegate_->ActivateContents(this);
910}
911
[email protected]ea42e7782010-08-23 23:58:12912void TabContents::Deactivate() {
913 if (delegate_)
914 delegate_->DeactivateContents(this);
915}
916
[email protected]63954792011-07-11 04:17:48917void TabContents::LostCapture() {
918 if (delegate_)
919 delegate_->LostCapture();
920}
921
922bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
923 bool* is_keyboard_shortcut) {
924 return delegate_ &&
925 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
926}
927
928void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
929 if (delegate_)
930 delegate_->HandleKeyboardEvent(event);
931}
932
[email protected]32ded2212011-11-10 18:51:43933void TabContents::HandleMouseDown() {
934 if (delegate_)
935 delegate_->HandleMouseDown();
936}
937
[email protected]63954792011-07-11 04:17:48938void TabContents::HandleMouseUp() {
939 if (delegate_)
940 delegate_->HandleMouseUp();
941}
942
943void TabContents::HandleMouseActivate() {
944 if (delegate_)
945 delegate_->HandleMouseActivate();
946}
947
[email protected]8a5e0ca2011-08-25 06:30:47948void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
949 if (delegate_)
950 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
951}
952
[email protected]5d5f7af2011-10-01 01:38:12953bool TabContents::IsFullscreenForCurrentTab() const {
954 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
955}
956
[email protected]e9621112011-10-17 05:38:37957void TabContents::RequestToLockMouse() {
958 if (delegate_) {
959 delegate_->RequestToLockMouse(this);
960 } else {
961 GotResponseToLockMouseRequest(false);
962 }
963}
964
965void TabContents::LostMouseLock() {
966 if (delegate_)
967 delegate_->LostMouseLock();
968}
969
[email protected]0548c5352011-09-07 00:33:33970void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23971 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33972 if (delegate_)
973 delegate_->UpdatePreferredSize(this, pref_size);
974}
975
[email protected]61e2b3cc2012-03-02 16:13:34976void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
977 if (delegate_)
978 delegate_->ResizeDueToAutoResize(this, new_size);
979}
980
[email protected]32ded2212011-11-10 18:51:43981void TabContents::WebUISend(RenderViewHost* render_view_host,
982 const GURL& source_url,
983 const std::string& name,
984 const base::ListValue& args) {
985 if (delegate_)
986 delegate_->WebUISend(this, source_url, name, args);
987}
988
[email protected]e5d549d2011-12-28 01:29:20989WebContents* TabContents::OpenURL(const OpenURLParams& params) {
990 if (!delegate_)
991 return NULL;
[email protected]00c37fc2011-08-02 00:22:50992
[email protected]e5d549d2011-12-28 01:29:20993 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
994 // Notify observers.
995 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
996 DidOpenURL(params.url, params.referrer,
997 params.disposition, params.transition));
998 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34999}
1000
[email protected]1ccb3568d2010-02-19 10:51:161001bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501002 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251003 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231004 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251005 reload_type);
[email protected]876bc832010-09-07 16:29:541006}
[email protected]96d185d2009-04-24 03:28:541007
[email protected]876bc832010-09-07 16:29:541008bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231009 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501010 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401011 // The renderer will reject IPC messages with URLs longer than
1012 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511013 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401014 return false;
1015
[email protected]9f76c1e2012-03-05 15:15:581016 RenderViewHostImpl* dest_render_view_host =
1017 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401018 if (!dest_render_view_host)
1019 return false; // Unable to create the desired render view host.
1020
[email protected]80a8fad2011-01-29 04:02:381021 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071022 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581023 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501024 WebUIControllerFactory* factory =
1025 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1026 bool is_allowed_in_web_ui_renderer =
1027 factory &&
1028 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431029#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511030 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431031#endif
[email protected]e091df82011-10-11 18:13:211032 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551033 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581034
[email protected]96d185d2009-04-24 03:28:541035 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441036 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521037 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441038 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511039 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541040
1041 // Used for page load time metrics.
1042 current_load_start_ = base::TimeTicks::Now();
1043
1044 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341045 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271046 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471047 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341048 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541049
[email protected]36fc0392011-12-25 03:59:511050 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541051 // HACK!! This code suppresses javascript: URLs from being added to
1052 // session history, which is what we want to do for javascript: URLs that
1053 // do not generate content. What we really need is a message from the
1054 // renderer telling us that a new page was not created. The same message
1055 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511056 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541057 return false;
1058 }
1059
[email protected]3c9e1872010-11-18 16:17:491060 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251061 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041062 observers_,
[email protected]36fc0392011-12-25 03:59:511063 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541064
[email protected]09b29342011-06-24 19:18:481065 if (delegate_)
1066 delegate_->DidNavigateToPendingEntry(this);
1067
[email protected]d5f942ba2008-09-26 19:30:341068 return true;
1069}
1070
[email protected]b6583592012-01-25 19:52:331071void TabContents::SetHistoryLengthAndPrune(
1072 const SiteInstance* site_instance,
1073 int history_length,
1074 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411075 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1076 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191077 if (render_manager_.pending_render_view_host()) {
1078 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141079 return;
[email protected]9e1ad4b2011-08-14 16:49:191080 }
[email protected]9f76c1e2012-03-05 15:15:581081 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191082 if (!rvh) {
1083 NOTREACHED();
1084 return;
1085 }
[email protected]9f76c1e2012-03-05 15:15:581086 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191087 NOTREACHED();
1088 return;
1089 }
[email protected]9f76c1e2012-03-05 15:15:581090 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191091 history_length,
1092 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141093}
1094
[email protected]90daadb42009-06-08 21:27:281095void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271096 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541097 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1098 return;
1099 }
[email protected]9f76c1e2012-03-05 15:15:581100 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541101}
1102
[email protected]0bfbf882011-12-22 18:19:271103bool TabContents::ShowingInterstitialPage() const {
1104 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541105}
1106
[email protected]0bfbf882011-12-22 18:19:271107InterstitialPage* TabContents::GetInterstitialPage() const {
1108 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221109}
1110
[email protected]a53209b2012-01-20 16:48:161111bool TabContents::IsSavable() {
1112 // WebKit creates Document object when MIME type is application/xhtml+xml,
1113 // so we also support this MIME type.
1114 return contents_mime_type_ == "text/html" ||
1115 contents_mime_type_ == "text/xml" ||
1116 contents_mime_type_ == "application/xhtml+xml" ||
1117 contents_mime_type_ == "text/plain" ||
1118 contents_mime_type_ == "text/css" ||
1119 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1120}
1121
[email protected]c7dd2f62011-07-18 15:57:591122void TabContents::OnSavePage() {
1123 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161124 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481125 download_stats::RecordDownloadSource(
1126 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261127 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141128 return;
[email protected]c7dd2f62011-07-18 15:57:591129 }
1130
1131 Stop();
1132
1133 // Create the save package and possibly prompt the user for the name to save
1134 // the page as. The user prompt is an asynchronous operation that runs on
1135 // another thread.
1136 save_package_ = new SavePackage(this);
1137 save_package_->GetSaveInfo();
1138}
1139
1140// Used in automated testing to bypass prompting the user for file names.
1141// Instead, the names and paths are hard coded rather than running them through
1142// file name sanitation and extension / mime checking.
1143bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161144 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591145 // Stop the page from navigating.
1146 Stop();
1147
1148 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1149 return save_package_->Init();
1150}
1151
[email protected]aa4f3972012-03-01 18:12:121152void TabContents::GenerateMHTML(
1153 const FilePath& file,
1154 const base::Callback<void(const FilePath&, int64)>& callback) {
1155 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1156}
1157
[email protected]420ae012009-04-24 05:16:321158bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231159 NavigationEntryImpl* active_entry =
1160 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321161 return (active_entry != NULL &&
1162 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511163 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321164}
1165
[email protected]0bfbf882011-12-22 18:19:271166const std::string& TabContents::GetContentsMimeType() const {
1167 return contents_mime_type_;
1168}
1169
1170bool TabContents::WillNotifyDisconnection() const {
1171 return notify_disconnection_;
1172}
1173
[email protected]b2fe07d12010-02-09 14:38:081174void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311175 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581176 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1177 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161178}
1179
[email protected]b2fe07d12010-02-09 14:38:081180void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311181 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581182 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1183 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161184}
1185
[email protected]0bfbf882011-12-22 18:19:271186content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1187 return &renderer_preferences_;
1188}
1189
1190void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1191 new_tab_start_time_ = time;
1192}
1193
1194base::TimeTicks TabContents::GetNewTabStartTime() const {
1195 return new_tab_start_time_;
1196}
1197
[email protected]7ab1e7d62009-10-14 23:32:011198void TabContents::OnCloseStarted() {
1199 if (tab_close_start_time_.is_null())
1200 tab_close_start_time_ = base::TimeTicks::Now();
1201}
1202
[email protected]46624bf2010-06-09 16:04:191203bool TabContents::ShouldAcceptDragAndDrop() const {
1204#if defined(OS_CHROMEOS)
1205 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1206 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511207 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201208 return false;
1209 return true;
[email protected]46624bf2010-06-09 16:04:191210#else
1211 return true;
1212#endif
1213}
1214
[email protected]7813bd72011-02-05 02:19:341215void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521216 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581217 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511218 if (delegate_)
1219 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341220}
1221
[email protected]0bfbf882011-12-22 18:19:271222void TabContents::SetClosedByUserGesture(bool value) {
1223 closed_by_user_gesture_ = value;
1224}
1225
1226bool TabContents::GetClosedByUserGesture() const {
1227 return closed_by_user_gesture_;
1228}
1229
[email protected]d0b8d092010-10-25 04:05:171230double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051231 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561232 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251233 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171234 return 0;
[email protected]b75b8292010-10-01 07:28:251235
1236 double zoom_level;
1237 if (temporary_zoom_settings_) {
1238 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581239 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251240 } else {
[email protected]2ae88d12011-10-14 09:11:191241 GURL url;
[email protected]10f417c52011-12-28 21:04:231242 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191243 // Since zoom map is updated using rewritten URL, use rewritten URL
1244 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511245 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191246 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251247 }
[email protected]d0b8d092010-10-25 04:05:171248 return zoom_level;
1249}
[email protected]b75b8292010-10-01 07:28:251250
[email protected]d0b8d092010-10-25 04:05:171251int TabContents::GetZoomPercent(bool* enable_increment,
1252 bool* enable_decrement) {
1253 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011254 // Calculate the zoom percent from the factor. Round up to the nearest whole
1255 // number.
[email protected]b75b8292010-10-01 07:28:251256 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011257 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251258 *enable_decrement = percent > minimum_zoom_percent_;
1259 *enable_increment = percent < maximum_zoom_percent_;
1260 return percent;
1261}
1262
[email protected]3c733bde2010-12-21 19:56:311263void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501264 if (!delegate_)
1265 return;
1266
[email protected]10f417c52011-12-28 21:04:231267 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501268 if (!active_entry)
1269 return;
1270
[email protected]36fc0392011-12-25 03:59:511271 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121272}
1273
[email protected]932b7a12011-03-09 12:50:271274void TabContents::ViewFrameSource(const GURL& url,
1275 const std::string& content_state) {
1276 if (!delegate_)
1277 return;
1278
1279 delegate_->ViewSourceForFrame(this, url, content_state);
1280}
1281
[email protected]0bfbf882011-12-22 18:19:271282int TabContents::GetMinimumZoomPercent() const {
1283 return minimum_zoom_percent_;
1284}
1285
1286int TabContents::GetMaximumZoomPercent() const {
1287 return maximum_zoom_percent_;
1288}
1289
[email protected]bcd2815602012-01-14 18:17:231290gfx::Size TabContents::GetPreferredSize() const {
1291 return preferred_size_;
1292}
1293
[email protected]0bfbf882011-12-22 18:19:271294int TabContents::GetContentRestrictions() const {
1295 return content_restrictions_;
1296}
1297
1298WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501299 WebUIControllerFactory* factory =
1300 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1301 if (!factory)
1302 return WebUI::kNoWebUI;
1303 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271304}
1305
[email protected]01ec4ec2012-01-18 04:13:471306content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271307 // When there is a pending navigation entry, we want to use the pending WebUI
1308 // that goes along with it to control the basic flags. For example, we want to
1309 // show the pending URL in the URL bar, so we want the display_url flag to
1310 // be from the pending entry.
1311 //
1312 // The confusion comes because there are multiple possibilities for the
1313 // initial load in a tab as a side effect of the way the RenderViewHostManager
1314 // works.
1315 //
1316 // - For the very first tab the load looks "normal". The new tab Web UI is
1317 // the pending one, and we want it to apply here.
1318 //
1319 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1320 // get switched to the one previously associated with the new tab pages.
1321 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1322 // have a committed Web UI in this case.
1323 //
1324 // This condition handles all of these cases:
1325 //
1326 // - First load in first tab: no committed nav entry + pending nav entry +
1327 // pending dom ui:
1328 // -> Use pending Web UI if any.
1329 //
1330 // - First load in second tab: no committed nav entry + pending nav entry +
1331 // no pending Web UI:
1332 // -> Use the committed Web UI if any.
1333 //
1334 // - Second navigation in any tab: committed nav entry + pending nav entry:
1335 // -> Use pending Web UI if any.
1336 //
1337 // - Normal state with no load: committed nav entry + no pending nav entry:
1338 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251339 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271340 (controller_.GetLastCommittedEntry() ||
1341 render_manager_.pending_web_ui()))
1342 return render_manager_.pending_web_ui();
1343 return render_manager_.web_ui();
1344}
1345
1346bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1347 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581348 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271349}
1350
1351bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471352 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271353 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221354 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231355 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511356 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271357 return true;
1358 return false;
1359}
1360
1361void TabContents::SetFocusToLocationBar(bool select_all) {
1362 if (delegate_)
1363 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211364}
1365
[email protected]8b5af492011-11-28 21:50:581366void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301367 const string16& type,
1368 const string16& href,
1369 const string16& title,
1370 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511371 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301372 this, action, type, href, title, disposition);
1373}
1374
[email protected]678105012011-12-09 04:01:211375void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301376 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001377 WebIntentsDispatcherImpl* intents_dispatcher =
1378 new WebIntentsDispatcherImpl(this, intent, intent_id);
1379 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301380}
1381
[email protected]724159a2010-12-30 01:11:181382void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1383 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591384 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181385 const GURL& url) {
1386 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1387 GURL validated_url(url);
[email protected]9f76c1e2012-03-05 15:15:581388 GetRenderViewHostImpl()->FilterURL(
1389 ChildProcessSecurityPolicyImpl::GetInstance(),
1390 GetRenderProcessHost()->GetID(),
1391 &validated_url);
[email protected]724159a2010-12-30 01:11:181392
[email protected]8093a542011-05-13 07:29:321393 RenderViewHost* rvh =
1394 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521395 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101396 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251397 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101398 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321399 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101400
[email protected]724159a2010-12-30 01:11:181401 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591402 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251403 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591404 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181405 }
1406}
1407
1408void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591409 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181410 const GURL& source_url,
1411 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491412 // TODO(creis): Remove this method and have the pre-rendering code listen to
1413 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1414 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231415 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181416 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251417 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181418 else
1419 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511420 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181421 return;
[email protected]e7d50892011-01-19 21:47:381422
[email protected]4850a7f2011-03-08 23:36:591423 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261425 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591426 opener_url));
[email protected]724159a2010-12-30 01:11:181427}
1428
1429void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581430 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1431 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1432 << ", error_code: " << params.error_code
1433 << ", error_description: " << params.error_description
1434 << ", is_main_frame: " << params.is_main_frame
1435 << ", showing_repost_interstitial: " <<
1436 params.showing_repost_interstitial
1437 << ", frame_id: " << params.frame_id;
1438 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581439 GetRenderViewHostImpl()->FilterURL(
1440 ChildProcessSecurityPolicyImpl::GetInstance(),
1441 GetRenderProcessHost()->GetID(),
1442 &validated_url);
[email protected]724159a2010-12-30 01:11:181443
[email protected]d7b175e2011-10-11 15:31:581444 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181445 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1446 // This means that the interstitial won't be torn down properly, which is
1447 // bad. But if we have an interstitial, go back to another tab type, and
1448 // then load the same interstitial again, we could end up getting the first
1449 // interstitial's "failed" message (as a result of the cancel) when we're on
1450 // the second one.
1451 //
1452 // We can't tell this apart, so we think we're tearing down the current page
1453 // which will cause a crash later one. There is also some code in
1454 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1455 // out because of this problem.
1456 //
1457 // http://code.google.com/p/chromium/issues/detail?id=2855
1458 // Because this will not tear down the interstitial properly, if "back" is
1459 // back to another tab type, the interstitial will still be somewhat alive
1460 // in the previous tab type. If you navigate somewhere that activates the
1461 // tab with the interstitial again, you'll see a flash before the new load
1462 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271463 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181464 LOG(WARNING) << "Discarding message during interstitial.";
1465 return;
1466 }
1467
[email protected]02102f82011-06-13 20:37:021468 // Discard our pending entry if the load canceled (e.g. if we decided to
1469 // download the file instead of load it). We do not verify that the URL
1470 // being canceled matches the pending entry's URL because they will not
1471 // match if a redirect occurred (in which case we do not want to leave a
1472 // stale redirect URL showing). This means that we also cancel the pending
1473 // entry if the user started a new navigation. As a result, the navigation
1474 // controller may not remember that a load is in progress, but the
1475 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251476 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161477 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181478
[email protected]151a63d2011-12-20 22:32:521479 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181480 }
1481
1482 // Send out a notification that we failed a provisional load with an error.
1483 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581484 params.is_main_frame,
1485 controller_.IsURLInPageNavigation(validated_url),
1486 validated_url,
1487 std::string(),
1488 false,
1489 params.frame_id);
1490 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181491
[email protected]ad50def52011-10-19 23:17:071492 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271493 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501494 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531495 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101496
[email protected]d8c660432011-12-22 20:51:251497 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581498 observers_,
1499 DidFailProvisionalLoad(params.frame_id,
1500 params.is_main_frame,
1501 validated_url,
1502 params.error_code,
1503 params.error_description));
[email protected]724159a2010-12-30 01:11:181504}
1505
1506void TabContents::OnDidLoadResourceFromMemoryCache(
1507 const GURL& url,
[email protected]70435962011-08-02 20:13:281508 const std::string& security_info,
1509 const std::string& http_method,
1510 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191511 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181512 cache.Increment();
1513
1514 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081515 int cert_id = 0;
1516 net::CertStatus cert_status = 0;
1517 int security_bits = -1;
1518 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511519 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1520 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301521 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161522 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181523
[email protected]ad50def52011-10-19 23:17:071524 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271525 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501526 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531527 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181528}
1529
1530void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381531 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181532 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201533 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181534}
1535
1536void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021537 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231538 LOG(INFO) << security_origin << " ran insecure content from "
1539 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381540 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051541 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381542 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051543 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1544 }
[email protected]330614de2012-02-13 17:07:181545 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411546 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201547 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181548}
1549
1550void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1551 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251552 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101553 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181554}
1555
[email protected]1a55c5be2011-11-29 11:36:311556void TabContents::OnDidFinishLoad(
1557 int64 frame_id,
1558 const GURL& validated_url,
1559 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251560 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311561 DidFinishLoad(frame_id, validated_url, is_main_frame));
1562}
1563
1564void TabContents::OnDidFailLoadWithError(int64 frame_id,
1565 const GURL& validated_url,
1566 bool is_main_frame,
1567 int error_code,
1568 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251569 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311570 DidFailLoad(frame_id, validated_url, is_main_frame,
1571 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181572}
1573
[email protected]c8f73ab2011-01-22 00:05:171574void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271575 content_restrictions_ = restrictions;
1576 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171577}
1578
[email protected]216813952011-05-19 22:21:261579void TabContents::OnGoToEntryAtOffset(int offset) {
1580 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231581 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251582 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261583 if (!entry)
1584 return;
1585 // Note that we don't call NavigationController::GotToOffset() as we don't
1586 // want to create a pending navigation entry (it might end up lingering
1587 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251588 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581589 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511590 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581591 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471592 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571593
1594 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1595 // it in now that we know. This allows us to find the entry when it commits.
1596 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231597 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331598 entry->set_site_instance(
1599 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571600 }
[email protected]216813952011-05-19 22:21:261601 }
1602}
1603
1604void TabContents::OnUpdateZoomLimits(int minimum_percent,
1605 int maximum_percent,
1606 bool remember) {
1607 minimum_zoom_percent_ = minimum_percent;
1608 maximum_zoom_percent_ = maximum_percent;
1609 temporary_zoom_settings_ = !remember;
1610}
1611
[email protected]0bfbf882011-12-22 18:19:271612void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481613 download_stats::RecordDownloadSource(
1614 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261615 // Check if the URL to save matches the URL of the main frame. Since this
1616 // message originates from Pepper plugins, it may not be the case if the
1617 // plugin is an embedded element.
1618 GURL main_frame_url = GetURL();
1619 if (!main_frame_url.is_valid())
1620 return;
1621 bool is_main_frame = (url == main_frame_url);
1622 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271623}
1624
[email protected]3a29a6e2011-08-24 18:26:211625void TabContents::OnEnumerateDirectory(int request_id,
1626 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591627 ChildProcessSecurityPolicyImpl* policy =
1628 ChildProcessSecurityPolicyImpl::GetInstance();
1629 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1630 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211631}
1632
[email protected]7d189022011-08-25 22:54:201633void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511634 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201635}
1636
1637void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1638 const GURL& url,
1639 const string16& title) {
[email protected]b9535422012-02-09 01:47:591640 ChildProcessSecurityPolicyImpl* policy =
1641 ChildProcessSecurityPolicyImpl::GetInstance();
1642 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1643 return;
[email protected]6934a702011-12-20 00:04:511644 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201645}
1646
[email protected]b888919c2011-09-02 00:32:161647void TabContents::OnFindReply(int request_id,
1648 int number_of_matches,
1649 const gfx::Rect& selection_rect,
1650 int active_match_ordinal,
1651 bool final_update) {
[email protected]6934a702011-12-20 00:04:511652 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1653 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001654 // Send a notification to the renderer that we are ready to receive more
1655 // results from the scoping effort of the Find operation. The FindInPage
1656 // scoping is asynchronous and periodically sends results back up to the
1657 // browser using IPC. In an effort to not spam the browser we have the
1658 // browser send an ACK for each FindReply message and have the renderer
1659 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581660 GetRenderViewHostImpl()->Send(
1661 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161662}
1663
[email protected]d952a052011-09-06 18:42:451664void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511665 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451666}
1667
[email protected]7fc4bbb2011-09-08 21:23:101668void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1669 bool blocked_by_policy) {
1670 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251671 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101672 AppCacheAccessed(manifest_url, blocked_by_policy));
1673}
1674
[email protected]96d185d2009-04-24 03:28:541675// Notifies the RenderWidgetHost instance about the fact that the page is
1676// loading, or done loading and calls the base implementation.
1677void TabContents::SetIsLoading(bool is_loading,
1678 LoadNotificationDetails* details) {
1679 if (is_loading == is_loading_)
1680 return;
1681
1682 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211683 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541684 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561685 upload_size_ = 0;
1686 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541687 }
1688
1689 render_manager_.SetIsLoading(is_loading);
1690
1691 is_loading_ = is_loading;
1692 waiting_for_response_ = is_loading;
1693
[email protected]6ebdc9b2010-09-27 16:55:571694 if (delegate_)
1695 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461696 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541697
[email protected]432115822011-07-10 15:52:271698 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1699 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071700 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541701 if (details)
[email protected]6c2381d2011-10-19 02:52:531702 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071703 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501704 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541705 det);
1706}
1707
[email protected]420ae012009-04-24 05:16:321708void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131709 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321710 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561711 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381712 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441713 // that opened the window, as long as both renderers have the same
1714 // privileges.
[email protected]1fd1a502011-03-30 16:55:561715 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561716 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581717 // web_ui might be NULL if the URL refers to a non-existent extension.
1718 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401719 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521720 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441721 }
1722 }
[email protected]1fd1a502011-03-30 16:55:561723 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441724 }
1725
[email protected]4e697b042011-07-08 06:44:561726 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321727 // Clear the status bubble. This is a workaround for a bug where WebKit
1728 // doesn't let us know that the cursor left an element during a
1729 // transition (this is also why the mouse cursor remains as a hand after
1730 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1731 // clear the bubble when a user navigates to a named anchor in the same
1732 // page.
[email protected]36fc0392011-12-25 03:59:511733 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321734 }
1735
[email protected]a6e82fc2010-02-24 22:28:141736 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471737 // Once the main frame is navigated, we're no longer considered to have
1738 // displayed insecure content.
1739 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171740 }
[email protected]ce5c4502009-05-06 16:46:111741
[email protected]3c9e1872010-11-18 16:17:491742 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251743 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041744 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321745}
1746
1747void TabContents::DidNavigateAnyFramePostCommit(
1748 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131749 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321750 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061751 // If we navigate off the page, reset JavaScript state. This does nothing
1752 // to prevent a malicious script from spamming messages, since the script
1753 // could just reload the page to stop blocking.
1754 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551755 dialog_creator_->ResetJavaScriptState(this);
1756 dialog_creator_ = NULL;
1757 }
[email protected]420ae012009-04-24 05:16:321758
[email protected]3c9e1872010-11-18 16:17:491759 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251760 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041761 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321762}
1763
[email protected]74ce1ad2011-12-16 21:51:461764void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1765 // If we are creating a RVH for a restored controller, then we need to make
1766 // sure the RenderView starts with a next_page_id_ larger than the number
1767 // of restored entries. This must be called before the RenderView starts
1768 // navigating (to avoid a race between the browser updating max_page_id and
1769 // the renderer updating next_page_id_). Because of this, we only call this
1770 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561771 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581772 if (max_restored_page_id >
1773 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1774 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1775 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321776}
1777
[email protected]10f417c52011-12-28 21:04:231778bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571779 const string16& title) {
[email protected]420ae012009-04-24 05:16:321780 // For file URLs without a title, use the pathname instead. In the case of a
1781 // synthesized title, we don't want the update to count toward the "one set
1782 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511783 string16 final_title;
[email protected]420ae012009-04-24 05:16:321784 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511785 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1786 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321787 explicit_set = false; // Don't count synthetic titles toward the set limit.
1788 } else {
[email protected]acafd272011-07-26 17:35:571789 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321790 explicit_set = true;
1791 }
1792
[email protected]987fc3a2011-05-26 14:18:091793 // If a page is created via window.open and never navigated,
1794 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551795 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091796 if (entry) {
[email protected]36fc0392011-12-25 03:59:511797 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091798 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321799
[email protected]36fc0392011-12-25 03:59:511800 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091801 } else {
1802 if (page_title_when_no_navigation_entry_ == final_title)
1803 return false; // Nothing changed, don't bother.
1804
1805 page_title_when_no_navigation_entry_ = final_title;
1806 }
[email protected]420ae012009-04-24 05:16:321807
[email protected]420ae012009-04-24 05:16:321808 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231809 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321810
[email protected]105bb0f2011-05-24 17:12:141811 TitleUpdatedDetails details(entry, explicit_set);
1812
[email protected]ad50def52011-10-19 23:17:071813 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441814 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1815 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531816 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041817
[email protected]420ae012009-04-24 05:16:321818 return true;
1819}
1820
1821void TabContents::NotifySwapped() {
1822 // After sending out a swap notification, we need to send a disconnect
1823 // notification so that clients that pick up a pointer to |this| can NULL the
1824 // pointer. See Bug 1230284.
1825 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071826 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201827 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1828 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071829 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321830}
1831
1832void TabContents::NotifyConnected() {
1833 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071834 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121835 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1836 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071837 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321838}
1839
1840void TabContents::NotifyDisconnected() {
1841 if (!notify_disconnection_)
1842 return;
1843
1844 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071845 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321846 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1847 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071848 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321849}
1850
[email protected]8d3347f2009-07-09 22:00:211851RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321852 return view_.get();
1853}
1854
[email protected]8d3347f2009-07-09 22:00:211855RenderViewHostDelegate::RendererManagement*
1856TabContents::GetRendererManagementDelegate() {
1857 return &render_manager_;
1858}
1859
[email protected]daf82f82011-10-31 22:35:311860content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371861 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461862 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511863}
1864
[email protected]768c5472011-12-26 19:06:171865WebContents* TabContents::GetAsWebContents() {
1866 return this;
1867}
1868
[email protected]da4dfc42011-10-12 15:53:561869content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431870 return view_type_;
[email protected]7b291f92009-08-14 05:43:531871}
1872
[email protected]b7a756d42012-01-23 18:08:171873gfx::Rect TabContents::GetRootWindowResizerRect() const {
1874 if (delegate_)
1875 return delegate_->GetRootWindowResizerRect();
1876 return gfx::Rect();
1877}
1878
[email protected]420ae012009-04-24 05:16:321879void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071880 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271881 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321882 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531883 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231884 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321885 if (!entry)
1886 return;
1887
1888 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351889 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561890 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581891 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321892
1893 if (entry->IsViewSourceMode()) {
1894 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581895 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1896 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321897 }
[email protected]0666aef2009-05-13 19:48:081898
[email protected]d487beefe2011-12-21 05:41:211899 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261900
1901 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251902 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321903}
1904
1905void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521906 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321907 // Don't notify the world, since this came from a renderer in the
1908 // background.
1909 return;
1910 }
1911
1912 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311913 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231914 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301915
1916 // Restore the focus to the tab (otherwise the focus will be on the top
1917 // window).
[email protected]484ae5912010-09-29 19:16:141918 if (was_crashed && !FocusLocationBarByDefault() &&
1919 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301920 Focus();
[email protected]484ae5912010-09-29 19:16:141921 }
[email protected]32ded2212011-11-10 18:51:431922
[email protected]d8c660432011-12-22 20:51:251923 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321924}
1925
[email protected]443b80e2010-12-14 00:42:231926void TabContents::RenderViewGone(RenderViewHost* rvh,
1927 base::TerminationStatus status,
1928 int error_code) {
[email protected]151a63d2011-12-20 22:32:521929 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321930 // The pending page's RenderViewHost is gone.
1931 return;
1932 }
1933
1934 SetIsLoading(false, NULL);
1935 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231936 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311937 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321938
[email protected]d8c660432011-12-22 20:51:251939 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271940 observers_,
[email protected]be1f56ab2011-12-22 06:55:311941 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321942}
1943
[email protected]2e4633c2009-07-09 16:58:061944void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481945 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251946 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061947}
1948
[email protected]420ae012009-04-24 05:16:321949void TabContents::DidNavigate(RenderViewHost* rvh,
1950 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581951 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321952 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371953
[email protected]434f69f2012-02-06 21:56:521954 // Update the site of the SiteInstance if it doesn't have one yet, unless
1955 // this is for about:blank. In that case, the SiteInstance can still be
1956 // considered unused until a navigation to a real page.
1957 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1958 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331959 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521960 }
[email protected]420ae012009-04-24 05:16:321961
1962 // Need to update MIME type here because it's referred to in
1963 // UpdateNavigationCommands() called by RendererDidNavigate() to
1964 // determine whether or not to enable the encoding menu.
1965 // It's updated only for the main frame. For a subframe,
1966 // RenderView::UpdateURL does not set params.contents_mime_type.
1967 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1968 // TODO(jungshik): Add a test for the encoding menu to avoid
1969 // regressing it again.
[email protected]2905f742011-10-13 03:51:581970 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321971 contents_mime_type_ = params.contents_mime_type;
1972
[email protected]8286f51a2011-05-31 17:39:131973 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001974 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391975
[email protected]a9c0bfe2010-09-17 08:35:221976 // Send notification about committed provisional loads. This notification is
1977 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1978 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081979 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071980 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1981 // that is not recorded in the navigation history. For the purpose of
1982 // tracking navigation events, we treat this event as a sub frame navigation
1983 // event.
1984 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581985 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221986 // Whether or not a page transition was triggered by going backward or
1987 // forward in the history is only stored in the navigation controller's
1988 // entry list.
1989 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511990 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581991 content::PAGE_TRANSITION_FORWARD_BACK)) {
1992 transition_type = content::PageTransitionFromInt(
1993 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221994 }
[email protected]0d60f0192011-04-14 12:40:101995 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251996 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101997 DidCommitProvisionalLoadForFrame(params.frame_id,
1998 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221999 }
2000
[email protected]76543b92009-08-31 17:27:452001 if (!did_navigate)
2002 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322003
2004 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2005 // for the appropriate notification (best) or you can add it to
2006 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2007 // necessary, please).
2008
2009 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002010 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322011 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512012 if (delegate_)
2013 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002014 }
[email protected]420ae012009-04-24 05:16:322015 DidNavigateAnyFramePostCommit(rvh, details, params);
2016}
2017
2018void TabContents::UpdateState(RenderViewHost* rvh,
2019 int32 page_id,
2020 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152021 // Ensure that this state update comes from either the active RVH or one of
2022 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522023 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322024
2025 // We must be prepared to handle state updates for any page, these occur
2026 // when the user is scrolling and entering form data, as well as when we're
2027 // leaving a page, in which case our state may have already been moved to
2028 // the next page. The navigation controller will look up the appropriate
2029 // NavigationEntry and update it when it is notified via the delegate.
2030
2031 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582032 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322033 if (entry_index < 0)
2034 return;
[email protected]10f417c52011-12-28 21:04:232035 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322036
[email protected]36fc0392011-12-25 03:59:512037 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322038 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512039 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322040 controller_.NotifyEntryChanged(entry, entry_index);
2041}
2042
2043void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572044 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462045 const string16& title,
2046 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322047 // If we have a title, that's a pretty good indication that we've started
2048 // getting useful data.
2049 SetNotWaitingForResponse();
2050
[email protected]73eb2602012-02-09 19:50:552051 // Try to find the navigation entry, which might not be the current one.
2052 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232053 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582054 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092055
[email protected]73eb2602012-02-09 19:50:552056 // We can handle title updates when we don't have an entry in
2057 // UpdateTitleForEntry, but only if the update is from the current RVH.
2058 if (!entry && rvh != GetRenderViewHost())
2059 return;
2060
[email protected]a49e10b2011-08-01 23:57:462061 // TODO(evan): make use of title_direction.
2062 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092063 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322064 return;
2065
2066 // Broadcast notifications when the UI should be updated.
2067 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462068 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322069}
2070
[email protected]420ae012009-04-24 05:16:322071void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402072 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312073 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322074}
2075
2076void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512077 if (delegate_)
2078 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322079}
2080
[email protected]420ae012009-04-24 05:16:322081void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292082 // The UI may be in an event-tracking loop, such as between the
2083 // mouse-down and mouse-up in text selection or a button click.
2084 // Defer the close until after tracking is complete, so that we
2085 // don't free objects out from under the UI.
2086 // TODO(shess): This could probably be integrated with the
2087 // IsDoingDrag() test below. Punting for now because I need more
2088 // research to understand how this impacts platforms other than Mac.
2089 // TODO(shess): This could get more fine-grained. For instance,
2090 // closing a tab in another window while selecting text in the
2091 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212092 if (GetView()->IsEventTracking()) {
2093 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292094 return;
2095 }
2096
[email protected]24a4d1062009-07-10 23:10:422097 // If we close the tab while we're in the middle of a drag, we'll crash.
2098 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212099 if (GetView()->IsDoingDrag()) {
2100 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422101 return;
2102 }
2103
[email protected]420ae012009-04-24 05:16:322104 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522105 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512106 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322107}
2108
[email protected]cd9ed79d2011-11-15 19:22:572109void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522110 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512111 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572112}
2113
[email protected]420ae012009-04-24 05:16:322114void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512115 if (delegate_ && delegate_->IsPopupOrPanel(this))
2116 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322117}
2118
[email protected]7ab1e7d62009-10-14 23:32:012119void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322120 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492121
[email protected]6934a702011-12-20 00:04:512122 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212123 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512124 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002125 }
[email protected]3c9e1872010-11-18 16:17:492126
2127 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252128 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322129}
2130
[email protected]7ab1e7d62009-10-14 23:32:012131void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322132 scoped_ptr<LoadNotificationDetails> details;
2133
[email protected]10f417c52011-12-28 21:04:232134 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322135 // An entry may not exist for a stop when loading an initial blank page or
2136 // if an iframe injected by script into a blank page finishes loading.
2137 if (entry) {
[email protected]420ae012009-04-24 05:16:322138 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2139
2140 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512141 entry->GetVirtualURL(),
2142 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322143 elapsed,
2144 &controller_,
2145 controller_.GetCurrentEntryIndex()));
2146 }
2147
[email protected]420ae012009-04-24 05:16:322148 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492149
2150 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252151 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322152}
2153
[email protected]c95fa8b2011-04-28 20:26:162154void TabContents::DidCancelLoading() {
2155 controller_.DiscardNonCommittedEntries();
2156
2157 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462158 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162159}
2160
[email protected]1a3c3cb2010-12-16 21:03:402161void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512162 if (delegate_)
2163 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402164}
2165
[email protected]952a68e2011-11-17 00:36:102166void TabContents::DocumentAvailableInMainFrame(
2167 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252168 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102169 DocumentAvailableInMainFrame());
2170}
2171
[email protected]25497492010-09-11 15:15:082172void TabContents::DocumentOnLoadCompletedInMainFrame(
2173 RenderViewHost* render_view_host,
2174 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072175 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272176 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322177 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532178 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082179}
2180
[email protected]ae5184d62011-10-06 19:25:582181void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152182 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582183 WindowOpenDisposition disposition,
2184 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482185 // Delegate to RequestTransferURL because this is just the generic
2186 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582187 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482188 GlobalRequestID());
2189}
2190
2191void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582192 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482193 WindowOpenDisposition disposition,
2194 int64 source_frame_id,
2195 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202196 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582197 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582198 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352199 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322200 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2201 // generated suggestions).
2202 //
[email protected]e0112912011-02-02 22:54:352203 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162204 // want web sites to see a referrer of "chrome://blah" (and some
2205 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322206 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432207 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222208 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482209 false /* is_renderer_initiated */);
2210 params.transferred_global_request_id = old_request_id;
2211 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222212 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322213 } else {
[email protected]6bf6a6b52012-02-03 15:41:432214 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482215 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2216 params.transferred_global_request_id = old_request_id;
2217 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582218 }
2219 if (new_contents) {
2220 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252221 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582222 DidOpenRequestedURL(new_contents,
2223 url,
2224 referrer,
2225 disposition,
2226 transition_type,
2227 source_frame_id));
[email protected]420ae012009-04-24 05:16:322228 }
2229}
2230
[email protected]420ae012009-04-24 05:16:322231void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342232 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412233 const string16& message,
2234 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322235 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472236 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322237 IPC::Message* reply_msg,
2238 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072239 // Suppress JavaScript dialogs when requested. Also suppress messages when
2240 // showing an interstitial as it's shown over the previous page and we don't
2241 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502242 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582243 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272244 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072245 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522246 delegate_->ShouldSuppressDialogs() ||
2247 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322248
2249 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432250 std::string accept_lang = content::GetContentClient()->browser()->
2251 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552252 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522253 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432254 this,
2255 frame_url.GetOrigin(),
2256 accept_lang,
2257 javascript_message_type,
2258 message,
[email protected]51da7e32012-01-30 19:24:522259 default_prompt,
2260 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432261 reply_msg),
[email protected]51da7e32012-01-30 19:24:522262 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322263 }
[email protected]3ab9cb82011-06-03 18:02:072264
2265 if (suppress_this_message) {
2266 // If we are suppressing messages, just reply as if the user immediately
2267 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342268 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072269 }
2270
2271 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322272}
2273
[email protected]fedec012012-01-28 03:09:342274void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412275 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322276 bool is_reload,
[email protected]420ae012009-04-24 05:16:322277 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582278 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512279 if (delegate_)
2280 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072281
2282 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582283 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072284 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522285 delegate_->ShouldSuppressDialogs() ||
2286 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152287 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342288 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582289 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502290 return;
2291 }
[email protected]3ab9cb82011-06-03 18:02:072292
[email protected]7ab1e7d62009-10-14 23:32:012293 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552294 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522295 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322296 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522297 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2298 reply_msg));
[email protected]420ae012009-04-24 05:16:322299}
2300
[email protected]420ae012009-04-24 05:16:322301WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542302 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322303}
2304
[email protected]7d472472011-01-22 01:30:252305void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272306 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252307 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222308
[email protected]99907362012-01-11 05:41:402309 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172310 if (rdh) // NULL in unittests.
2311 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252312}
2313
[email protected]fa1cf0b82010-01-15 21:49:442314void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442315 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252316 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442317}
2318
[email protected]420ae012009-04-24 05:16:322319void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2320 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152321 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522322 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152323 return;
2324
[email protected]9f76c1e2012-03-05 15:15:582325 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2326
[email protected]e5fc1632011-08-08 07:51:532327 // Ignore renderer unresponsive event if debugger is attached to the tab
2328 // since the event may be a result of the renderer sitting on a breakpoint.
2329 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442330 DevToolsAgentHost* agent =
2331 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2332 if (agent &&
2333 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532334 return;
2335
[email protected]420ae012009-04-24 05:16:322336 if (is_during_unload) {
2337 // Hang occurred while firing the beforeunload/unload handler.
2338 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582339 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322340
2341 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2342 return;
2343
2344 // If the tab hangs in the beforeunload/unload handler there's really
2345 // nothing we can do to recover. Pretend the unload listeners have
2346 // all fired and close the tab. If the hang is in the beforeunload handler
2347 // then the user will not have the option of cancelling the close.
2348 Close(rvh);
2349 return;
2350 }
2351
[email protected]9f76c1e2012-03-05 15:15:582352 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472353 return;
2354
[email protected]6934a702011-12-20 00:04:512355 if (delegate_)
2356 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322357}
2358
2359void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512360 if (delegate_)
2361 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322362}
2363
2364void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212365 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562366 uint64 upload_position,
2367 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322368 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562369 upload_position_ = upload_position;
2370 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502371 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202372 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302373 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212374 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322375 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462376 if (IsLoading()) {
2377 NotifyNavigationStateChanged(
2378 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2379 }
[email protected]420ae012009-04-24 05:16:322380}
2381
[email protected]7d472472011-01-22 01:30:252382void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512383 if (delegate_)
2384 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252385}
2386
[email protected]420ae012009-04-24 05:16:322387void TabContents::BeforeUnloadFiredFromRenderManager(
2388 bool proceed,
2389 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512390 if (delegate_)
2391 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322392}
2393
[email protected]3a3d47472010-07-15 21:03:542394void TabContents::DidStartLoadingFromRenderManager(
2395 RenderViewHost* render_view_host) {
2396 DidStartLoading();
2397}
2398
2399void TabContents::RenderViewGoneFromRenderManager(
2400 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232401 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2402 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542403}
2404
[email protected]420ae012009-04-24 05:16:322405void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102406 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262407 gfx::Size size = view_->GetContainerSize();
2408 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2409 // here during container initialization and normal window size will be set
2410 // later. In case of tab duplication this resizing to 0x0 prevents setting
2411 // normal size later so just ignore it.
2412 if (!size.IsEmpty())
2413 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322414}
2415
[email protected]3a3d47472010-07-15 21:03:542416void TabContents::NotifySwappedFromRenderManager() {
2417 NotifySwapped();
2418}
2419
[email protected]d202a7c2012-01-04 07:53:472420NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202421 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542422}
2423
[email protected]d2353452012-01-19 19:53:562424WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2425 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322426}
2427
[email protected]10f417c52011-12-28 21:04:232428NavigationEntry*
2429 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322430 return controller_.GetLastCommittedEntry();
2431}
2432
2433bool TabContents::CreateRenderViewForRenderManager(
2434 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442435 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322436 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522437
[email protected]420ae012009-04-24 05:16:322438 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442439 if (rwh_view)
2440 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322441
[email protected]74ce1ad2011-12-16 21:51:462442 // Make sure we use the correct starting page_id in the new RenderView.
2443 UpdateMaxPageIDIfNecessary(render_view_host);
2444 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582445 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462446
[email protected]9f76c1e2012-03-05 15:15:582447 if (!static_cast<RenderViewHostImpl*>(
2448 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522449 return false;
2450
[email protected]e60c0232011-11-11 19:56:352451#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502452 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2453 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442454 if (rwh_view) {
2455 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2456 render_widget_host->WasResized();
2457 }
[email protected]f8233cc2011-05-31 20:24:502458#endif
2459
[email protected]420ae012009-04-24 05:16:322460 return true;
2461}
2462
[email protected]fedec012012-01-28 03:09:342463void TabContents::OnDialogClosed(RenderViewHost* rvh,
2464 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072465 bool success,
2466 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542467 if (is_showing_before_unload_dialog_ && !success) {
2468 // If a beforeunload dialog is canceled, we need to stop the throbber from
2469 // spinning, since we forced it to start spinning in Navigate.
2470 DidStopLoading();
2471
2472 tab_close_start_time_ = base::TimeTicks();
2473 }
2474 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582475 static_cast<RenderViewHostImpl*>(
2476 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542477}
2478
[email protected]be1f56ab2011-12-22 06:55:312479void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122480 encoding_ = content::GetContentClient()->browser()->
2481 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102482}
[email protected]f45d2a72010-03-08 23:28:352483
[email protected]e30d68d2012-02-09 00:06:262484void TabContents::SaveURL(const GURL& url,
2485 const GURL& referrer,
2486 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142487 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2488 if (!dlm)
2489 return;
2490 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262491 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142492 const NavigationEntry* entry = controller_.GetActiveEntry();
2493 if (entry)
2494 post_id = entry->GetPostID();
2495 }
2496 DownloadSaveInfo save_info;
2497 save_info.prompt_for_save_location = true;
2498 dlm->DownloadUrl(url,
2499 referrer,
2500 "",
2501 true, // prefer_cache
2502 post_id,
2503 save_info,
2504 this);
2505}
2506
[email protected]33f74972010-12-08 16:40:362507void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212508 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442509 // Can be NULL during tests.
2510 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212511 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362512}
[email protected]9f76c1e2012-03-05 15:15:582513
2514RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2515 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2516}