blob: 5f97fe2114bd56987766d28942bfa7a90d6d0dec [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]b9a1fb42011-04-12 23:16:44300 if (host && host->view())
[email protected]c30585c2012-02-16 15:02:04301 RenderWidgetHostViewPort::FromRWHV(host->view())->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]64d69de42012-02-06 00:19:54448 rvh->process()->GetID())) {
449 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())
601 return render_manager_.current_host()->process();
602 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 {
707 return render_manager_.current_host()->site_instance();
708}
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();
714 return dest_rvh->site_instance();
715}
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.
798 RenderViewHost* rvh = GetRenderViewHost();
799 if (rvh) {
800 rvh->ResizeRectChanged(GetRootWindowResizerRect());
801 }
[email protected]96d185d2009-04-24 03:28:54802}
803
[email protected]be1f56ab2011-12-22 06:55:31804
805base::TimeTicks TabContents::GetLastSelectedTime() const {
806 return last_selected_time_;
807}
808
[email protected]96d185d2009-04-24 03:28:54809void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31810 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52811 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
812 // open a tab in then background, then closes the tab before selecting it.
813 // This is because closing the tab calls TabContents::Destroy(), which
814 // removes the |GetRenderViewHost()|; then when we actually destroy the
815 // window, OnWindowPosChanged() notices and calls HideContents() (which
816 // calls us).
[email protected]c30585c2012-02-16 15:02:04817 RenderWidgetHostViewPort* rwhv =
818 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16819 if (rwhv)
820 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54821 }
822
[email protected]ad50def52011-10-19 23:17:07823 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09824 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
825 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07826 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54827}
828
[email protected]be1f56ab2011-12-22 06:55:31829void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04830 RenderWidgetHostViewPort* rwhv =
831 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31832 if (rwhv)
833 rwhv->DidBecomeSelected();
834}
835
836void TabContents::HideContents() {
837 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
838 // our superclass HideContents(), because some callers want to be very picky
839 // about the order in which these get called. In addition to making the code
840 // here practically impossible to understand, this also means we end up
841 // calling TabContents::WasHidden() twice if callers call both versions of
842 // HideContents() on a TabContents.
843 WasHidden();
844}
845
846bool TabContents::NeedToFireBeforeUnload() {
847 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27848 return WillNotifyDisconnection() &&
849 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31850 !GetRenderViewHost()->SuddenTerminationAllowed();
851}
852
[email protected]0bfbf882011-12-22 18:19:27853void TabContents::Stop() {
854 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25855 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27856}
857
[email protected]d9083482012-01-06 00:38:46858WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27859 // We create a new SiteInstance so that the new tab won't share processes
860 // with the old one. This can be changed in the future if we need it to share
861 // processes for some reason.
862 TabContents* tc = new TabContents(
863 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33864 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27865 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20866 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27867 return tc;
868}
869
[email protected]2a6bc3e2011-12-28 23:51:33870void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27871 WindowOpenDisposition disposition,
872 const gfx::Rect& initial_pos,
873 bool user_gesture) {
874 if (!delegate_)
875 return;
876
877 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
878 user_gesture);
879}
880
881gfx::NativeView TabContents::GetContentNativeView() const {
882 return view_->GetContentNativeView();
883}
884
885gfx::NativeView TabContents::GetNativeView() const {
886 return view_->GetNativeView();
887}
888
889void TabContents::GetContainerBounds(gfx::Rect* out) const {
890 view_->GetContainerBounds(out);
891}
892
893void TabContents::Focus() {
894 view_->Focus();
895}
896
[email protected]d8c660432011-12-22 20:51:25897void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31898 observers_.AddObserver(observer);
899}
900
[email protected]d8c660432011-12-22 20:51:25901void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31902 observers_.RemoveObserver(observer);
903}
904
[email protected]d5f942ba2008-09-26 19:30:34905void TabContents::Activate() {
906 if (delegate_)
907 delegate_->ActivateContents(this);
908}
909
[email protected]ea42e7782010-08-23 23:58:12910void TabContents::Deactivate() {
911 if (delegate_)
912 delegate_->DeactivateContents(this);
913}
914
[email protected]63954792011-07-11 04:17:48915void TabContents::LostCapture() {
916 if (delegate_)
917 delegate_->LostCapture();
918}
919
920bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
921 bool* is_keyboard_shortcut) {
922 return delegate_ &&
923 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
924}
925
926void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
927 if (delegate_)
928 delegate_->HandleKeyboardEvent(event);
929}
930
[email protected]32ded2212011-11-10 18:51:43931void TabContents::HandleMouseDown() {
932 if (delegate_)
933 delegate_->HandleMouseDown();
934}
935
[email protected]63954792011-07-11 04:17:48936void TabContents::HandleMouseUp() {
937 if (delegate_)
938 delegate_->HandleMouseUp();
939}
940
941void TabContents::HandleMouseActivate() {
942 if (delegate_)
943 delegate_->HandleMouseActivate();
944}
945
[email protected]8a5e0ca2011-08-25 06:30:47946void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
947 if (delegate_)
948 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
949}
950
[email protected]5d5f7af2011-10-01 01:38:12951bool TabContents::IsFullscreenForCurrentTab() const {
952 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
953}
954
[email protected]e9621112011-10-17 05:38:37955void TabContents::RequestToLockMouse() {
956 if (delegate_) {
957 delegate_->RequestToLockMouse(this);
958 } else {
959 GotResponseToLockMouseRequest(false);
960 }
961}
962
963void TabContents::LostMouseLock() {
964 if (delegate_)
965 delegate_->LostMouseLock();
966}
967
[email protected]0548c5352011-09-07 00:33:33968void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23969 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33970 if (delegate_)
971 delegate_->UpdatePreferredSize(this, pref_size);
972}
973
[email protected]61e2b3cc2012-03-02 16:13:34974void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
975 if (delegate_)
976 delegate_->ResizeDueToAutoResize(this, new_size);
977}
978
[email protected]32ded2212011-11-10 18:51:43979void TabContents::WebUISend(RenderViewHost* render_view_host,
980 const GURL& source_url,
981 const std::string& name,
982 const base::ListValue& args) {
983 if (delegate_)
984 delegate_->WebUISend(this, source_url, name, args);
985}
986
[email protected]e5d549d2011-12-28 01:29:20987WebContents* TabContents::OpenURL(const OpenURLParams& params) {
988 if (!delegate_)
989 return NULL;
[email protected]00c37fc2011-08-02 00:22:50990
[email protected]e5d549d2011-12-28 01:29:20991 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
992 // Notify observers.
993 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
994 DidOpenURL(params.url, params.referrer,
995 params.disposition, params.transition));
996 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34997}
998
[email protected]1ccb3568d2010-02-19 10:51:16999bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501000 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251001 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231002 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251003 reload_type);
[email protected]876bc832010-09-07 16:29:541004}
[email protected]96d185d2009-04-24 03:28:541005
[email protected]876bc832010-09-07 16:29:541006bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231007 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501008 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401009 // The renderer will reject IPC messages with URLs longer than
1010 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511011 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401012 return false;
1013
[email protected]dd11de52011-11-03 22:54:271014 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:401015 if (!dest_render_view_host)
1016 return false; // Unable to create the desired render view host.
1017
[email protected]80a8fad2011-01-29 04:02:381018 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071019 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581020 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501021 WebUIControllerFactory* factory =
1022 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1023 bool is_allowed_in_web_ui_renderer =
1024 factory &&
1025 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431026#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511027 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431028#endif
[email protected]e091df82011-10-11 18:13:211029 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551030 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581031
[email protected]96d185d2009-04-24 03:28:541032 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441033 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521034 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441035 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511036 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541037
1038 // Used for page load time metrics.
1039 current_load_start_ = base::TimeTicks::Now();
1040
1041 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341042 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271043 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471044 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341045 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541046
[email protected]36fc0392011-12-25 03:59:511047 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541048 // HACK!! This code suppresses javascript: URLs from being added to
1049 // session history, which is what we want to do for javascript: URLs that
1050 // do not generate content. What we really need is a message from the
1051 // renderer telling us that a new page was not created. The same message
1052 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511053 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541054 return false;
1055 }
1056
[email protected]3c9e1872010-11-18 16:17:491057 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251058 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041059 observers_,
[email protected]36fc0392011-12-25 03:59:511060 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541061
[email protected]09b29342011-06-24 19:18:481062 if (delegate_)
1063 delegate_->DidNavigateToPendingEntry(this);
1064
[email protected]d5f942ba2008-09-26 19:30:341065 return true;
1066}
1067
[email protected]b6583592012-01-25 19:52:331068void TabContents::SetHistoryLengthAndPrune(
1069 const SiteInstance* site_instance,
1070 int history_length,
1071 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411072 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1073 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191074 if (render_manager_.pending_render_view_host()) {
1075 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141076 return;
[email protected]9e1ad4b2011-08-14 16:49:191077 }
[email protected]151a63d2011-12-20 22:32:521078 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191079 if (!rvh) {
1080 NOTREACHED();
1081 return;
1082 }
1083 if (site_instance && rvh->site_instance() != site_instance) {
1084 NOTREACHED();
1085 return;
1086 }
1087 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1088 history_length,
1089 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141090}
1091
[email protected]90daadb42009-06-08 21:27:281092void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271093 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541094 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1095 return;
1096 }
[email protected]151a63d2011-12-20 22:32:521097 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541098}
1099
[email protected]0bfbf882011-12-22 18:19:271100bool TabContents::ShowingInterstitialPage() const {
1101 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541102}
1103
[email protected]0bfbf882011-12-22 18:19:271104InterstitialPage* TabContents::GetInterstitialPage() const {
1105 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221106}
1107
[email protected]a53209b2012-01-20 16:48:161108bool TabContents::IsSavable() {
1109 // WebKit creates Document object when MIME type is application/xhtml+xml,
1110 // so we also support this MIME type.
1111 return contents_mime_type_ == "text/html" ||
1112 contents_mime_type_ == "text/xml" ||
1113 contents_mime_type_ == "application/xhtml+xml" ||
1114 contents_mime_type_ == "text/plain" ||
1115 contents_mime_type_ == "text/css" ||
1116 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1117}
1118
[email protected]c7dd2f62011-07-18 15:57:591119void TabContents::OnSavePage() {
1120 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161121 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481122 download_stats::RecordDownloadSource(
1123 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261124 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141125 return;
[email protected]c7dd2f62011-07-18 15:57:591126 }
1127
1128 Stop();
1129
1130 // Create the save package and possibly prompt the user for the name to save
1131 // the page as. The user prompt is an asynchronous operation that runs on
1132 // another thread.
1133 save_package_ = new SavePackage(this);
1134 save_package_->GetSaveInfo();
1135}
1136
1137// Used in automated testing to bypass prompting the user for file names.
1138// Instead, the names and paths are hard coded rather than running them through
1139// file name sanitation and extension / mime checking.
1140bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161141 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591142 // Stop the page from navigating.
1143 Stop();
1144
1145 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1146 return save_package_->Init();
1147}
1148
[email protected]aa4f3972012-03-01 18:12:121149void TabContents::GenerateMHTML(
1150 const FilePath& file,
1151 const base::Callback<void(const FilePath&, int64)>& callback) {
1152 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1153}
1154
[email protected]420ae012009-04-24 05:16:321155bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231156 NavigationEntryImpl* active_entry =
1157 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321158 return (active_entry != NULL &&
1159 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511160 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321161}
1162
[email protected]0bfbf882011-12-22 18:19:271163const std::string& TabContents::GetContentsMimeType() const {
1164 return contents_mime_type_;
1165}
1166
1167bool TabContents::WillNotifyDisconnection() const {
1168 return notify_disconnection_;
1169}
1170
[email protected]b2fe07d12010-02-09 14:38:081171void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311172 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521173 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1174 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161175}
1176
[email protected]b2fe07d12010-02-09 14:38:081177void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311178 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521179 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1180 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161181}
1182
[email protected]0bfbf882011-12-22 18:19:271183content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1184 return &renderer_preferences_;
1185}
1186
1187void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1188 new_tab_start_time_ = time;
1189}
1190
1191base::TimeTicks TabContents::GetNewTabStartTime() const {
1192 return new_tab_start_time_;
1193}
1194
[email protected]7ab1e7d62009-10-14 23:32:011195void TabContents::OnCloseStarted() {
1196 if (tab_close_start_time_.is_null())
1197 tab_close_start_time_ = base::TimeTicks::Now();
1198}
1199
[email protected]46624bf2010-06-09 16:04:191200bool TabContents::ShouldAcceptDragAndDrop() const {
1201#if defined(OS_CHROMEOS)
1202 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1203 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511204 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201205 return false;
1206 return true;
[email protected]46624bf2010-06-09 16:04:191207#else
1208 return true;
1209#endif
1210}
1211
[email protected]7813bd72011-02-05 02:19:341212void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521213 if (GetRenderViewHost())
1214 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511215 if (delegate_)
1216 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341217}
1218
[email protected]0bfbf882011-12-22 18:19:271219void TabContents::SetClosedByUserGesture(bool value) {
1220 closed_by_user_gesture_ = value;
1221}
1222
1223bool TabContents::GetClosedByUserGesture() const {
1224 return closed_by_user_gesture_;
1225}
1226
[email protected]d0b8d092010-10-25 04:05:171227double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051228 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561229 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251230 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171231 return 0;
[email protected]b75b8292010-10-01 07:28:251232
1233 double zoom_level;
1234 if (temporary_zoom_settings_) {
1235 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521236 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251237 } else {
[email protected]2ae88d12011-10-14 09:11:191238 GURL url;
[email protected]10f417c52011-12-28 21:04:231239 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191240 // Since zoom map is updated using rewritten URL, use rewritten URL
1241 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511242 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191243 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251244 }
[email protected]d0b8d092010-10-25 04:05:171245 return zoom_level;
1246}
[email protected]b75b8292010-10-01 07:28:251247
[email protected]d0b8d092010-10-25 04:05:171248int TabContents::GetZoomPercent(bool* enable_increment,
1249 bool* enable_decrement) {
1250 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011251 // Calculate the zoom percent from the factor. Round up to the nearest whole
1252 // number.
[email protected]b75b8292010-10-01 07:28:251253 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011254 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251255 *enable_decrement = percent > minimum_zoom_percent_;
1256 *enable_increment = percent < maximum_zoom_percent_;
1257 return percent;
1258}
1259
[email protected]3c733bde2010-12-21 19:56:311260void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501261 if (!delegate_)
1262 return;
1263
[email protected]10f417c52011-12-28 21:04:231264 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501265 if (!active_entry)
1266 return;
1267
[email protected]36fc0392011-12-25 03:59:511268 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121269}
1270
[email protected]932b7a12011-03-09 12:50:271271void TabContents::ViewFrameSource(const GURL& url,
1272 const std::string& content_state) {
1273 if (!delegate_)
1274 return;
1275
1276 delegate_->ViewSourceForFrame(this, url, content_state);
1277}
1278
[email protected]0bfbf882011-12-22 18:19:271279int TabContents::GetMinimumZoomPercent() const {
1280 return minimum_zoom_percent_;
1281}
1282
1283int TabContents::GetMaximumZoomPercent() const {
1284 return maximum_zoom_percent_;
1285}
1286
[email protected]bcd2815602012-01-14 18:17:231287gfx::Size TabContents::GetPreferredSize() const {
1288 return preferred_size_;
1289}
1290
[email protected]0bfbf882011-12-22 18:19:271291int TabContents::GetContentRestrictions() const {
1292 return content_restrictions_;
1293}
1294
1295WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501296 WebUIControllerFactory* factory =
1297 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1298 if (!factory)
1299 return WebUI::kNoWebUI;
1300 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271301}
1302
[email protected]01ec4ec2012-01-18 04:13:471303content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271304 // When there is a pending navigation entry, we want to use the pending WebUI
1305 // that goes along with it to control the basic flags. For example, we want to
1306 // show the pending URL in the URL bar, so we want the display_url flag to
1307 // be from the pending entry.
1308 //
1309 // The confusion comes because there are multiple possibilities for the
1310 // initial load in a tab as a side effect of the way the RenderViewHostManager
1311 // works.
1312 //
1313 // - For the very first tab the load looks "normal". The new tab Web UI is
1314 // the pending one, and we want it to apply here.
1315 //
1316 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1317 // get switched to the one previously associated with the new tab pages.
1318 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1319 // have a committed Web UI in this case.
1320 //
1321 // This condition handles all of these cases:
1322 //
1323 // - First load in first tab: no committed nav entry + pending nav entry +
1324 // pending dom ui:
1325 // -> Use pending Web UI if any.
1326 //
1327 // - First load in second tab: no committed nav entry + pending nav entry +
1328 // no pending Web UI:
1329 // -> Use the committed Web UI if any.
1330 //
1331 // - Second navigation in any tab: committed nav entry + pending nav entry:
1332 // -> Use pending Web UI if any.
1333 //
1334 // - Normal state with no load: committed nav entry + no pending nav entry:
1335 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251336 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271337 (controller_.GetLastCommittedEntry() ||
1338 render_manager_.pending_web_ui()))
1339 return render_manager_.pending_web_ui();
1340 return render_manager_.web_ui();
1341}
1342
1343bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1344 return GetRenderViewHost() ?
1345 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1346}
1347
1348bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471349 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271350 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221351 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231352 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511353 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271354 return true;
1355 return false;
1356}
1357
1358void TabContents::SetFocusToLocationBar(bool select_all) {
1359 if (delegate_)
1360 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211361}
1362
[email protected]8b5af492011-11-28 21:50:581363void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301364 const string16& type,
1365 const string16& href,
1366 const string16& title,
1367 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511368 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301369 this, action, type, href, title, disposition);
1370}
1371
[email protected]678105012011-12-09 04:01:211372void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301373 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001374 WebIntentsDispatcherImpl* intents_dispatcher =
1375 new WebIntentsDispatcherImpl(this, intent, intent_id);
1376 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301377}
1378
[email protected]724159a2010-12-30 01:11:181379void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1380 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591381 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181382 const GURL& url) {
1383 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1384 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591385 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301386 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181387
[email protected]8093a542011-05-13 07:29:321388 RenderViewHost* rvh =
1389 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521390 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101391 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251392 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101393 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321394 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101395
[email protected]724159a2010-12-30 01:11:181396 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591397 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251398 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591399 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181400 }
1401}
1402
1403void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591404 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181405 const GURL& source_url,
1406 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491407 // TODO(creis): Remove this method and have the pre-rendering code listen to
1408 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1409 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231410 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181411 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251412 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181413 else
1414 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511415 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181416 return;
[email protected]e7d50892011-01-19 21:47:381417
[email protected]4850a7f2011-03-08 23:36:591418 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251419 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261420 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591421 opener_url));
[email protected]724159a2010-12-30 01:11:181422}
1423
1424void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581425 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1426 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1427 << ", error_code: " << params.error_code
1428 << ", error_description: " << params.error_description
1429 << ", is_main_frame: " << params.is_main_frame
1430 << ", showing_repost_interstitial: " <<
1431 params.showing_repost_interstitial
1432 << ", frame_id: " << params.frame_id;
1433 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591434 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301435 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181436
[email protected]d7b175e2011-10-11 15:31:581437 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181438 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1439 // This means that the interstitial won't be torn down properly, which is
1440 // bad. But if we have an interstitial, go back to another tab type, and
1441 // then load the same interstitial again, we could end up getting the first
1442 // interstitial's "failed" message (as a result of the cancel) when we're on
1443 // the second one.
1444 //
1445 // We can't tell this apart, so we think we're tearing down the current page
1446 // which will cause a crash later one. There is also some code in
1447 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1448 // out because of this problem.
1449 //
1450 // http://code.google.com/p/chromium/issues/detail?id=2855
1451 // Because this will not tear down the interstitial properly, if "back" is
1452 // back to another tab type, the interstitial will still be somewhat alive
1453 // in the previous tab type. If you navigate somewhere that activates the
1454 // tab with the interstitial again, you'll see a flash before the new load
1455 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271456 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181457 LOG(WARNING) << "Discarding message during interstitial.";
1458 return;
1459 }
1460
[email protected]02102f82011-06-13 20:37:021461 // Discard our pending entry if the load canceled (e.g. if we decided to
1462 // download the file instead of load it). We do not verify that the URL
1463 // being canceled matches the pending entry's URL because they will not
1464 // match if a redirect occurred (in which case we do not want to leave a
1465 // stale redirect URL showing). This means that we also cancel the pending
1466 // entry if the user started a new navigation. As a result, the navigation
1467 // controller may not remember that a load is in progress, but the
1468 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251469 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161470 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181471
[email protected]151a63d2011-12-20 22:32:521472 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181473 }
1474
1475 // Send out a notification that we failed a provisional load with an error.
1476 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581477 params.is_main_frame,
1478 controller_.IsURLInPageNavigation(validated_url),
1479 validated_url,
1480 std::string(),
1481 false,
1482 params.frame_id);
1483 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181484
[email protected]ad50def52011-10-19 23:17:071485 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271486 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501487 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531488 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101489
[email protected]d8c660432011-12-22 20:51:251490 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581491 observers_,
1492 DidFailProvisionalLoad(params.frame_id,
1493 params.is_main_frame,
1494 validated_url,
1495 params.error_code,
1496 params.error_description));
[email protected]724159a2010-12-30 01:11:181497}
1498
1499void TabContents::OnDidLoadResourceFromMemoryCache(
1500 const GURL& url,
[email protected]70435962011-08-02 20:13:281501 const std::string& security_info,
1502 const std::string& http_method,
1503 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191504 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181505 cache.Increment();
1506
1507 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081508 int cert_id = 0;
1509 net::CertStatus cert_status = 0;
1510 int security_bits = -1;
1511 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511512 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1513 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301514 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161515 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181516
[email protected]ad50def52011-10-19 23:17:071517 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271518 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501519 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531520 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181521}
1522
1523void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381524 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181525 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201526 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181527}
1528
1529void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021530 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231531 LOG(INFO) << security_origin << " ran insecure content from "
1532 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381533 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051534 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381535 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051536 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1537 }
[email protected]330614de2012-02-13 17:07:181538 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411539 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201540 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181541}
1542
1543void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1544 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251545 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101546 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181547}
1548
[email protected]1a55c5be2011-11-29 11:36:311549void TabContents::OnDidFinishLoad(
1550 int64 frame_id,
1551 const GURL& validated_url,
1552 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251553 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311554 DidFinishLoad(frame_id, validated_url, is_main_frame));
1555}
1556
1557void TabContents::OnDidFailLoadWithError(int64 frame_id,
1558 const GURL& validated_url,
1559 bool is_main_frame,
1560 int error_code,
1561 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251562 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311563 DidFailLoad(frame_id, validated_url, is_main_frame,
1564 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181565}
1566
[email protected]c8f73ab2011-01-22 00:05:171567void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271568 content_restrictions_ = restrictions;
1569 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171570}
1571
[email protected]216813952011-05-19 22:21:261572void TabContents::OnGoToEntryAtOffset(int offset) {
1573 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231574 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251575 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261576 if (!entry)
1577 return;
1578 // Note that we don't call NavigationController::GotToOffset() as we don't
1579 // want to create a pending navigation entry (it might end up lingering
1580 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251581 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581582 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511583 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581584 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471585 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571586
1587 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1588 // it in now that we know. This allows us to find the entry when it commits.
1589 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231590 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331591 entry->set_site_instance(
1592 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571593 }
[email protected]216813952011-05-19 22:21:261594 }
1595}
1596
1597void TabContents::OnUpdateZoomLimits(int minimum_percent,
1598 int maximum_percent,
1599 bool remember) {
1600 minimum_zoom_percent_ = minimum_percent;
1601 maximum_zoom_percent_ = maximum_percent;
1602 temporary_zoom_settings_ = !remember;
1603}
1604
[email protected]0bfbf882011-12-22 18:19:271605void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481606 download_stats::RecordDownloadSource(
1607 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261608 // Check if the URL to save matches the URL of the main frame. Since this
1609 // message originates from Pepper plugins, it may not be the case if the
1610 // plugin is an embedded element.
1611 GURL main_frame_url = GetURL();
1612 if (!main_frame_url.is_valid())
1613 return;
1614 bool is_main_frame = (url == main_frame_url);
1615 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271616}
1617
[email protected]3a29a6e2011-08-24 18:26:211618void TabContents::OnEnumerateDirectory(int request_id,
1619 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591620 ChildProcessSecurityPolicyImpl* policy =
1621 ChildProcessSecurityPolicyImpl::GetInstance();
1622 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1623 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211624}
1625
[email protected]7d189022011-08-25 22:54:201626void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511627 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201628}
1629
1630void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1631 const GURL& url,
1632 const string16& title) {
[email protected]b9535422012-02-09 01:47:591633 ChildProcessSecurityPolicyImpl* policy =
1634 ChildProcessSecurityPolicyImpl::GetInstance();
1635 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1636 return;
[email protected]6934a702011-12-20 00:04:511637 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201638}
1639
[email protected]b888919c2011-09-02 00:32:161640void TabContents::OnFindReply(int request_id,
1641 int number_of_matches,
1642 const gfx::Rect& selection_rect,
1643 int active_match_ordinal,
1644 bool final_update) {
[email protected]6934a702011-12-20 00:04:511645 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1646 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001647 // Send a notification to the renderer that we are ready to receive more
1648 // results from the scoping effort of the Find operation. The FindInPage
1649 // scoping is asynchronous and periodically sends results back up to the
1650 // browser using IPC. In an effort to not spam the browser we have the
1651 // browser send an ACK for each FindReply message and have the renderer
1652 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521653 GetRenderViewHost()->Send(
1654 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161655}
1656
[email protected]d952a052011-09-06 18:42:451657void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511658 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451659}
1660
[email protected]7fc4bbb2011-09-08 21:23:101661void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1662 bool blocked_by_policy) {
1663 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101665 AppCacheAccessed(manifest_url, blocked_by_policy));
1666}
1667
[email protected]96d185d2009-04-24 03:28:541668// Notifies the RenderWidgetHost instance about the fact that the page is
1669// loading, or done loading and calls the base implementation.
1670void TabContents::SetIsLoading(bool is_loading,
1671 LoadNotificationDetails* details) {
1672 if (is_loading == is_loading_)
1673 return;
1674
1675 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211676 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541677 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561678 upload_size_ = 0;
1679 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541680 }
1681
1682 render_manager_.SetIsLoading(is_loading);
1683
1684 is_loading_ = is_loading;
1685 waiting_for_response_ = is_loading;
1686
[email protected]6ebdc9b2010-09-27 16:55:571687 if (delegate_)
1688 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461689 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541690
[email protected]432115822011-07-10 15:52:271691 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1692 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071693 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541694 if (details)
[email protected]6c2381d2011-10-19 02:52:531695 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071696 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501697 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541698 det);
1699}
1700
[email protected]420ae012009-04-24 05:16:321701void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131702 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321703 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561704 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381705 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441706 // that opened the window, as long as both renderers have the same
1707 // privileges.
[email protected]1fd1a502011-03-30 16:55:561708 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561709 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581710 // web_ui might be NULL if the URL refers to a non-existent extension.
1711 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401712 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521713 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441714 }
1715 }
[email protected]1fd1a502011-03-30 16:55:561716 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441717 }
1718
[email protected]4e697b042011-07-08 06:44:561719 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321720 // Clear the status bubble. This is a workaround for a bug where WebKit
1721 // doesn't let us know that the cursor left an element during a
1722 // transition (this is also why the mouse cursor remains as a hand after
1723 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1724 // clear the bubble when a user navigates to a named anchor in the same
1725 // page.
[email protected]36fc0392011-12-25 03:59:511726 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321727 }
1728
[email protected]a6e82fc2010-02-24 22:28:141729 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471730 // Once the main frame is navigated, we're no longer considered to have
1731 // displayed insecure content.
1732 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171733 }
[email protected]ce5c4502009-05-06 16:46:111734
[email protected]3c9e1872010-11-18 16:17:491735 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251736 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041737 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321738}
1739
1740void TabContents::DidNavigateAnyFramePostCommit(
1741 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131742 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321743 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061744 // If we navigate off the page, reset JavaScript state. This does nothing
1745 // to prevent a malicious script from spamming messages, since the script
1746 // could just reload the page to stop blocking.
1747 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551748 dialog_creator_->ResetJavaScriptState(this);
1749 dialog_creator_ = NULL;
1750 }
[email protected]420ae012009-04-24 05:16:321751
[email protected]3c9e1872010-11-18 16:17:491752 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251753 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041754 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321755}
1756
[email protected]74ce1ad2011-12-16 21:51:461757void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1758 // If we are creating a RVH for a restored controller, then we need to make
1759 // sure the RenderView starts with a next_page_id_ larger than the number
1760 // of restored entries. This must be called before the RenderView starts
1761 // navigating (to avoid a race between the browser updating max_page_id and
1762 // the renderer updating next_page_id_). Because of this, we only call this
1763 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561764 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461765 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1766 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321767}
1768
[email protected]10f417c52011-12-28 21:04:231769bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571770 const string16& title) {
[email protected]420ae012009-04-24 05:16:321771 // For file URLs without a title, use the pathname instead. In the case of a
1772 // synthesized title, we don't want the update to count toward the "one set
1773 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511774 string16 final_title;
[email protected]420ae012009-04-24 05:16:321775 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511776 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1777 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321778 explicit_set = false; // Don't count synthetic titles toward the set limit.
1779 } else {
[email protected]acafd272011-07-26 17:35:571780 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321781 explicit_set = true;
1782 }
1783
[email protected]987fc3a2011-05-26 14:18:091784 // If a page is created via window.open and never navigated,
1785 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551786 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091787 if (entry) {
[email protected]36fc0392011-12-25 03:59:511788 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091789 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321790
[email protected]36fc0392011-12-25 03:59:511791 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091792 } else {
1793 if (page_title_when_no_navigation_entry_ == final_title)
1794 return false; // Nothing changed, don't bother.
1795
1796 page_title_when_no_navigation_entry_ = final_title;
1797 }
[email protected]420ae012009-04-24 05:16:321798
[email protected]420ae012009-04-24 05:16:321799 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231800 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321801
[email protected]105bb0f2011-05-24 17:12:141802 TitleUpdatedDetails details(entry, explicit_set);
1803
[email protected]ad50def52011-10-19 23:17:071804 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441805 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1806 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531807 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041808
[email protected]420ae012009-04-24 05:16:321809 return true;
1810}
1811
1812void TabContents::NotifySwapped() {
1813 // After sending out a swap notification, we need to send a disconnect
1814 // notification so that clients that pick up a pointer to |this| can NULL the
1815 // pointer. See Bug 1230284.
1816 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071817 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201818 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1819 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071820 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321821}
1822
1823void TabContents::NotifyConnected() {
1824 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071825 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121826 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1827 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071828 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321829}
1830
1831void TabContents::NotifyDisconnected() {
1832 if (!notify_disconnection_)
1833 return;
1834
1835 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071836 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321837 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1838 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071839 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321840}
1841
[email protected]8d3347f2009-07-09 22:00:211842RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321843 return view_.get();
1844}
1845
[email protected]8d3347f2009-07-09 22:00:211846RenderViewHostDelegate::RendererManagement*
1847TabContents::GetRendererManagementDelegate() {
1848 return &render_manager_;
1849}
1850
[email protected]daf82f82011-10-31 22:35:311851content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371852 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461853 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511854}
1855
[email protected]768c5472011-12-26 19:06:171856WebContents* TabContents::GetAsWebContents() {
1857 return this;
1858}
1859
[email protected]da4dfc42011-10-12 15:53:561860content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431861 return view_type_;
[email protected]7b291f92009-08-14 05:43:531862}
1863
[email protected]b7a756d42012-01-23 18:08:171864gfx::Rect TabContents::GetRootWindowResizerRect() const {
1865 if (delegate_)
1866 return delegate_->GetRootWindowResizerRect();
1867 return gfx::Rect();
1868}
1869
[email protected]420ae012009-04-24 05:16:321870void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071871 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271872 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321873 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531874 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231875 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321876 if (!entry)
1877 return;
1878
1879 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351880 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561881 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581882 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321883
1884 if (entry->IsViewSourceMode()) {
1885 // Put the renderer in view source mode.
1886 render_view_host->Send(
1887 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1888 }
[email protected]0666aef2009-05-13 19:48:081889
[email protected]d487beefe2011-12-21 05:41:211890 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261891
1892 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251893 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321894}
1895
1896void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521897 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321898 // Don't notify the world, since this came from a renderer in the
1899 // background.
1900 return;
1901 }
1902
1903 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311904 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231905 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301906
1907 // Restore the focus to the tab (otherwise the focus will be on the top
1908 // window).
[email protected]484ae5912010-09-29 19:16:141909 if (was_crashed && !FocusLocationBarByDefault() &&
1910 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301911 Focus();
[email protected]484ae5912010-09-29 19:16:141912 }
[email protected]32ded2212011-11-10 18:51:431913
[email protected]d8c660432011-12-22 20:51:251914 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321915}
1916
[email protected]443b80e2010-12-14 00:42:231917void TabContents::RenderViewGone(RenderViewHost* rvh,
1918 base::TerminationStatus status,
1919 int error_code) {
[email protected]151a63d2011-12-20 22:32:521920 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321921 // The pending page's RenderViewHost is gone.
1922 return;
1923 }
1924
1925 SetIsLoading(false, NULL);
1926 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231927 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311928 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321929
[email protected]d8c660432011-12-22 20:51:251930 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271931 observers_,
[email protected]be1f56ab2011-12-22 06:55:311932 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321933}
1934
[email protected]2e4633c2009-07-09 16:58:061935void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481936 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251937 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061938}
1939
[email protected]420ae012009-04-24 05:16:321940void TabContents::DidNavigate(RenderViewHost* rvh,
1941 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581942 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321943 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371944
[email protected]434f69f2012-02-06 21:56:521945 // Update the site of the SiteInstance if it doesn't have one yet, unless
1946 // this is for about:blank. In that case, the SiteInstance can still be
1947 // considered unused until a navigation to a real page.
1948 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1949 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331950 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521951 }
[email protected]420ae012009-04-24 05:16:321952
1953 // Need to update MIME type here because it's referred to in
1954 // UpdateNavigationCommands() called by RendererDidNavigate() to
1955 // determine whether or not to enable the encoding menu.
1956 // It's updated only for the main frame. For a subframe,
1957 // RenderView::UpdateURL does not set params.contents_mime_type.
1958 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1959 // TODO(jungshik): Add a test for the encoding menu to avoid
1960 // regressing it again.
[email protected]2905f742011-10-13 03:51:581961 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321962 contents_mime_type_ = params.contents_mime_type;
1963
[email protected]8286f51a2011-05-31 17:39:131964 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001965 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391966
[email protected]a9c0bfe2010-09-17 08:35:221967 // Send notification about committed provisional loads. This notification is
1968 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1969 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081970 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071971 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1972 // that is not recorded in the navigation history. For the purpose of
1973 // tracking navigation events, we treat this event as a sub frame navigation
1974 // event.
1975 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581976 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221977 // Whether or not a page transition was triggered by going backward or
1978 // forward in the history is only stored in the navigation controller's
1979 // entry list.
1980 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511981 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581982 content::PAGE_TRANSITION_FORWARD_BACK)) {
1983 transition_type = content::PageTransitionFromInt(
1984 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221985 }
[email protected]0d60f0192011-04-14 12:40:101986 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251987 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101988 DidCommitProvisionalLoadForFrame(params.frame_id,
1989 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221990 }
1991
[email protected]76543b92009-08-31 17:27:451992 if (!did_navigate)
1993 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321994
1995 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1996 // for the appropriate notification (best) or you can add it to
1997 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1998 // necessary, please).
1999
2000 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002001 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322002 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512003 if (delegate_)
2004 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002005 }
[email protected]420ae012009-04-24 05:16:322006 DidNavigateAnyFramePostCommit(rvh, details, params);
2007}
2008
2009void TabContents::UpdateState(RenderViewHost* rvh,
2010 int32 page_id,
2011 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152012 // Ensure that this state update comes from either the active RVH or one of
2013 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522014 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322015
2016 // We must be prepared to handle state updates for any page, these occur
2017 // when the user is scrolling and entering form data, as well as when we're
2018 // leaving a page, in which case our state may have already been moved to
2019 // the next page. The navigation controller will look up the appropriate
2020 // NavigationEntry and update it when it is notified via the delegate.
2021
2022 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:152023 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:322024 if (entry_index < 0)
2025 return;
[email protected]10f417c52011-12-28 21:04:232026 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322027
[email protected]36fc0392011-12-25 03:59:512028 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322029 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512030 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322031 controller_.NotifyEntryChanged(entry, entry_index);
2032}
2033
2034void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572035 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462036 const string16& title,
2037 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322038 // If we have a title, that's a pretty good indication that we've started
2039 // getting useful data.
2040 SetNotWaitingForResponse();
2041
[email protected]73eb2602012-02-09 19:50:552042 // Try to find the navigation entry, which might not be the current one.
2043 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232044 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2045 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092046
[email protected]73eb2602012-02-09 19:50:552047 // We can handle title updates when we don't have an entry in
2048 // UpdateTitleForEntry, but only if the update is from the current RVH.
2049 if (!entry && rvh != GetRenderViewHost())
2050 return;
2051
[email protected]a49e10b2011-08-01 23:57:462052 // TODO(evan): make use of title_direction.
2053 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092054 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322055 return;
2056
2057 // Broadcast notifications when the UI should be updated.
2058 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462059 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322060}
2061
[email protected]420ae012009-04-24 05:16:322062void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402063 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312064 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322065}
2066
2067void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512068 if (delegate_)
2069 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322070}
2071
[email protected]420ae012009-04-24 05:16:322072void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292073 // The UI may be in an event-tracking loop, such as between the
2074 // mouse-down and mouse-up in text selection or a button click.
2075 // Defer the close until after tracking is complete, so that we
2076 // don't free objects out from under the UI.
2077 // TODO(shess): This could probably be integrated with the
2078 // IsDoingDrag() test below. Punting for now because I need more
2079 // research to understand how this impacts platforms other than Mac.
2080 // TODO(shess): This could get more fine-grained. For instance,
2081 // closing a tab in another window while selecting text in the
2082 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212083 if (GetView()->IsEventTracking()) {
2084 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292085 return;
2086 }
2087
[email protected]24a4d1062009-07-10 23:10:422088 // If we close the tab while we're in the middle of a drag, we'll crash.
2089 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212090 if (GetView()->IsDoingDrag()) {
2091 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422092 return;
2093 }
2094
[email protected]420ae012009-04-24 05:16:322095 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522096 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512097 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322098}
2099
[email protected]cd9ed79d2011-11-15 19:22:572100void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522101 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512102 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572103}
2104
[email protected]420ae012009-04-24 05:16:322105void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512106 if (delegate_ && delegate_->IsPopupOrPanel(this))
2107 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322108}
2109
[email protected]7ab1e7d62009-10-14 23:32:012110void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322111 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492112
[email protected]6934a702011-12-20 00:04:512113 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212114 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512115 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002116 }
[email protected]3c9e1872010-11-18 16:17:492117
2118 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252119 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322120}
2121
[email protected]7ab1e7d62009-10-14 23:32:012122void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322123 scoped_ptr<LoadNotificationDetails> details;
2124
[email protected]10f417c52011-12-28 21:04:232125 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322126 // An entry may not exist for a stop when loading an initial blank page or
2127 // if an iframe injected by script into a blank page finishes loading.
2128 if (entry) {
[email protected]420ae012009-04-24 05:16:322129 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2130
2131 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512132 entry->GetVirtualURL(),
2133 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322134 elapsed,
2135 &controller_,
2136 controller_.GetCurrentEntryIndex()));
2137 }
2138
[email protected]420ae012009-04-24 05:16:322139 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492140
2141 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252142 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322143}
2144
[email protected]c95fa8b2011-04-28 20:26:162145void TabContents::DidCancelLoading() {
2146 controller_.DiscardNonCommittedEntries();
2147
2148 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462149 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162150}
2151
[email protected]1a3c3cb2010-12-16 21:03:402152void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512153 if (delegate_)
2154 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402155}
2156
[email protected]952a68e2011-11-17 00:36:102157void TabContents::DocumentAvailableInMainFrame(
2158 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252159 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102160 DocumentAvailableInMainFrame());
2161}
2162
[email protected]25497492010-09-11 15:15:082163void TabContents::DocumentOnLoadCompletedInMainFrame(
2164 RenderViewHost* render_view_host,
2165 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072166 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272167 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322168 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532169 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082170}
2171
[email protected]ae5184d62011-10-06 19:25:582172void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152173 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582174 WindowOpenDisposition disposition,
2175 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482176 // Delegate to RequestTransferURL because this is just the generic
2177 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582178 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482179 GlobalRequestID());
2180}
2181
2182void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582183 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482184 WindowOpenDisposition disposition,
2185 int64 source_frame_id,
2186 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202187 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582188 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582189 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352190 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322191 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2192 // generated suggestions).
2193 //
[email protected]e0112912011-02-02 22:54:352194 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162195 // want web sites to see a referrer of "chrome://blah" (and some
2196 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322197 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432198 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222199 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482200 false /* is_renderer_initiated */);
2201 params.transferred_global_request_id = old_request_id;
2202 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222203 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322204 } else {
[email protected]6bf6a6b52012-02-03 15:41:432205 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482206 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2207 params.transferred_global_request_id = old_request_id;
2208 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582209 }
2210 if (new_contents) {
2211 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252212 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582213 DidOpenRequestedURL(new_contents,
2214 url,
2215 referrer,
2216 disposition,
2217 transition_type,
2218 source_frame_id));
[email protected]420ae012009-04-24 05:16:322219 }
2220}
2221
[email protected]420ae012009-04-24 05:16:322222void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342223 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412224 const string16& message,
2225 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322226 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472227 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322228 IPC::Message* reply_msg,
2229 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072230 // Suppress JavaScript dialogs when requested. Also suppress messages when
2231 // showing an interstitial as it's shown over the previous page and we don't
2232 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502233 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152234 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272235 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072236 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522237 delegate_->ShouldSuppressDialogs() ||
2238 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322239
2240 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432241 std::string accept_lang = content::GetContentClient()->browser()->
2242 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552243 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522244 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432245 this,
2246 frame_url.GetOrigin(),
2247 accept_lang,
2248 javascript_message_type,
2249 message,
[email protected]51da7e32012-01-30 19:24:522250 default_prompt,
2251 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432252 reply_msg),
[email protected]51da7e32012-01-30 19:24:522253 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322254 }
[email protected]3ab9cb82011-06-03 18:02:072255
2256 if (suppress_this_message) {
2257 // If we are suppressing messages, just reply as if the user immediately
2258 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342259 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072260 }
2261
2262 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322263}
2264
[email protected]fedec012012-01-28 03:09:342265void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412266 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322267 bool is_reload,
[email protected]420ae012009-04-24 05:16:322268 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512269 if (delegate_)
2270 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072271
2272 bool suppress_this_message =
2273 rvh->is_swapped_out() ||
2274 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522275 delegate_->ShouldSuppressDialogs() ||
2276 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152277 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342278 // The reply must be sent to the RVH that sent the request.
2279 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502280 return;
2281 }
[email protected]3ab9cb82011-06-03 18:02:072282
[email protected]7ab1e7d62009-10-14 23:32:012283 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552284 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522285 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322286 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522287 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2288 reply_msg));
[email protected]420ae012009-04-24 05:16:322289}
2290
[email protected]420ae012009-04-24 05:16:322291WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542292 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322293}
2294
[email protected]7d472472011-01-22 01:30:252295void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272296 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252297 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222298
[email protected]99907362012-01-11 05:41:402299 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172300 if (rdh) // NULL in unittests.
2301 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252302}
2303
[email protected]fa1cf0b82010-01-15 21:49:442304void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442305 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252306 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442307}
2308
[email protected]420ae012009-04-24 05:16:322309void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2310 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152311 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522312 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152313 return;
2314
[email protected]e5fc1632011-08-08 07:51:532315 // Ignore renderer unresponsive event if debugger is attached to the tab
2316 // since the event may be a result of the renderer sitting on a breakpoint.
2317 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442318 DevToolsAgentHost* agent =
2319 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2320 if (agent &&
2321 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532322 return;
2323
[email protected]420ae012009-04-24 05:16:322324 if (is_during_unload) {
2325 // Hang occurred while firing the beforeunload/unload handler.
2326 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112327 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322328
2329 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2330 return;
2331
2332 // If the tab hangs in the beforeunload/unload handler there's really
2333 // nothing we can do to recover. Pretend the unload listeners have
2334 // all fired and close the tab. If the hang is in the beforeunload handler
2335 // then the user will not have the option of cancelling the close.
2336 Close(rvh);
2337 return;
2338 }
2339
[email protected]151a63d2011-12-20 22:32:522340 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472341 return;
2342
[email protected]6934a702011-12-20 00:04:512343 if (delegate_)
2344 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322345}
2346
2347void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512348 if (delegate_)
2349 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322350}
2351
2352void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212353 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562354 uint64 upload_position,
2355 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322356 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562357 upload_position_ = upload_position;
2358 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502359 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202360 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302361 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212362 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322363 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462364 if (IsLoading()) {
2365 NotifyNavigationStateChanged(
2366 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2367 }
[email protected]420ae012009-04-24 05:16:322368}
2369
[email protected]7d472472011-01-22 01:30:252370void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512371 if (delegate_)
2372 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252373}
2374
[email protected]420ae012009-04-24 05:16:322375void TabContents::BeforeUnloadFiredFromRenderManager(
2376 bool proceed,
2377 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512378 if (delegate_)
2379 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322380}
2381
[email protected]3a3d47472010-07-15 21:03:542382void TabContents::DidStartLoadingFromRenderManager(
2383 RenderViewHost* render_view_host) {
2384 DidStartLoading();
2385}
2386
2387void TabContents::RenderViewGoneFromRenderManager(
2388 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232389 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2390 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542391}
2392
[email protected]420ae012009-04-24 05:16:322393void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102394 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262395 gfx::Size size = view_->GetContainerSize();
2396 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2397 // here during container initialization and normal window size will be set
2398 // later. In case of tab duplication this resizing to 0x0 prevents setting
2399 // normal size later so just ignore it.
2400 if (!size.IsEmpty())
2401 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322402}
2403
[email protected]3a3d47472010-07-15 21:03:542404void TabContents::NotifySwappedFromRenderManager() {
2405 NotifySwapped();
2406}
2407
[email protected]d202a7c2012-01-04 07:53:472408NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202409 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542410}
2411
[email protected]d2353452012-01-19 19:53:562412WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2413 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322414}
2415
[email protected]10f417c52011-12-28 21:04:232416NavigationEntry*
2417 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322418 return controller_.GetLastCommittedEntry();
2419}
2420
2421bool TabContents::CreateRenderViewForRenderManager(
2422 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442423 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322424 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522425
[email protected]420ae012009-04-24 05:16:322426 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442427 if (rwh_view)
2428 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322429
[email protected]74ce1ad2011-12-16 21:51:462430 // Make sure we use the correct starting page_id in the new RenderView.
2431 UpdateMaxPageIDIfNecessary(render_view_host);
2432 int32 max_page_id =
2433 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2434
2435 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522436 return false;
2437
[email protected]e60c0232011-11-11 19:56:352438#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502439 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2440 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442441 if (rwh_view) {
2442 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2443 render_widget_host->WasResized();
2444 }
[email protected]f8233cc2011-05-31 20:24:502445#endif
2446
[email protected]420ae012009-04-24 05:16:322447 return true;
2448}
2449
[email protected]fedec012012-01-28 03:09:342450void TabContents::OnDialogClosed(RenderViewHost* rvh,
2451 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072452 bool success,
2453 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542454 if (is_showing_before_unload_dialog_ && !success) {
2455 // If a beforeunload dialog is canceled, we need to stop the throbber from
2456 // spinning, since we forced it to start spinning in Navigate.
2457 DidStopLoading();
2458
2459 tab_close_start_time_ = base::TimeTicks();
2460 }
2461 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342462 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542463}
2464
[email protected]be1f56ab2011-12-22 06:55:312465void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122466 encoding_ = content::GetContentClient()->browser()->
2467 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102468}
[email protected]f45d2a72010-03-08 23:28:352469
[email protected]e30d68d2012-02-09 00:06:262470void TabContents::SaveURL(const GURL& url,
2471 const GURL& referrer,
2472 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142473 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2474 if (!dlm)
2475 return;
2476 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262477 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142478 const NavigationEntry* entry = controller_.GetActiveEntry();
2479 if (entry)
2480 post_id = entry->GetPostID();
2481 }
2482 DownloadSaveInfo save_info;
2483 save_info.prompt_for_save_location = true;
2484 dlm->DownloadUrl(url,
2485 referrer,
2486 "",
2487 true, // prefer_cache
2488 post_id,
2489 save_info,
2490 this);
2491}
2492
[email protected]33f74972010-12-08 16:40:362493void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212494 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442495 // Can be NULL during tests.
2496 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212497 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362498}