blob: 80dbc0e7ee8850b040fb8af4c0362d9516a4ce5c [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
439 // software 3d rasterizer.
[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;
443 }
444 }
445
[email protected]b9535422012-02-09 01:47:59446 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54447 rvh->process()->GetID())) {
448 prefs.loads_images_automatically = true;
449 prefs.javascript_enabled = true;
450 }
451
452 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
453
454 // Force accelerated compositing and 2d canvas off for chrome:, about: and
455 // chrome-devtools: pages (unless it's specifically allowed).
456 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54457 url.SchemeIs(chrome::kChromeUIScheme) ||
458 (url.SchemeIs(chrome::kAboutScheme) &&
459 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25460 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54461 prefs.accelerated_compositing_enabled = false;
462 prefs.accelerated_2d_canvas_enabled = false;
463 }
464
[email protected]43d9d782012-03-01 15:40:09465 int default_device_scale_factor;
466 base::StringToInt(command_line.GetSwitchValueASCII(
467 switches::kDefaultDeviceScaleFactor),
468 &default_device_scale_factor);
469
470 prefs.default_device_scale_factor = default_device_scale_factor;
471
[email protected]64d69de42012-02-06 00:19:54472 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
473
474 return prefs;
475}
476
[email protected]d202a7c2012-01-04 07:53:47477NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20478 return controller_;
479}
480
[email protected]765187182012-01-11 23:59:28481RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
482 return &render_manager_;
483}
484
[email protected]724159a2010-12-30 01:11:18485bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56486 if (GetWebUI() &&
487 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17488 return true;
[email protected]d2353452012-01-19 19:53:56489 }
[email protected]f82d57b52011-04-27 19:13:17490
[email protected]d8c660432011-12-22 20:51:25491 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
492 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10493 while ((observer = it.GetNext()) != NULL)
494 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53495 return true;
[email protected]403415a2011-01-10 18:57:53496
[email protected]724159a2010-12-30 01:11:18497 bool handled = true;
498 bool message_is_ok = true;
499 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58500 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
501 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24502 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
503 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18504 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
505 OnDidStartProvisionalLoadForFrame)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
507 OnDidRedirectProvisionalLoad)
508 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
509 OnDidFailProvisionalLoadWithError)
510 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
511 OnDidLoadResourceFromMemoryCache)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
513 OnDidDisplayInsecureContent)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
515 OnDidRunInsecureContent)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
517 OnDocumentLoadedInFrame)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17519 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
520 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25521 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26522 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59523 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21524 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20525 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
527 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16528 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45529 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10530 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18531 IPC_MESSAGE_UNHANDLED(handled = false)
532 IPC_END_MESSAGE_MAP_EX()
533
534 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38535 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18536 GetRenderProcessHost()->ReceivedBadMessage();
537 }
538
539 return handled;
540}
541
[email protected]6c2e472f2011-08-24 23:26:18542void TabContents::RunFileChooser(
543 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23544 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51545 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18546}
547
[email protected]c5eed492012-01-04 17:07:50548NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56549 return controller_;
550}
551
[email protected]c5eed492012-01-04 17:07:50552const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56553 return controller_;
554}
555
[email protected]627e0512011-12-21 22:55:30556content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55557 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30558}
559
[email protected]f5fa20e2011-12-21 22:35:56560void TabContents::SetViewType(content::ViewType type) {
561 view_type_ = type;
562}
563
[email protected]ea049a02011-12-25 21:37:09564content::ViewType TabContents::GetViewType() const {
565 return view_type_;
566}
567
[email protected]be1f56ab2011-12-22 06:55:31568const GURL& TabContents::GetURL() const {
569 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23570 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51571 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31572}
573
574
575const base::PropertyBag* TabContents::GetPropertyBag() const {
576 return &property_bag_;
577}
578
579base::PropertyBag* TabContents::GetPropertyBag() {
580 return &property_bag_;
581}
582
583content::WebContentsDelegate* TabContents::GetDelegate() {
584 return delegate_;
585}
586
587void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
588 // TODO(cbentzel): remove this debugging code?
589 if (delegate == delegate_)
590 return;
591 if (delegate_)
592 delegate_->Detach(this);
593 delegate_ = delegate;
594 if (delegate_)
595 delegate_->Attach(this);
596}
597
[email protected]f3b1a082011-11-18 00:34:30598content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03599 if (render_manager_.current_host())
600 return render_manager_.current_host()->process();
601 else
602 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16603}
604
[email protected]be1f56ab2011-12-22 06:55:31605RenderViewHost* TabContents::GetRenderViewHost() const {
606 return render_manager_.current_host();
607}
608
609RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
610 return render_manager_.GetRenderWidgetHostView();
611}
612
[email protected]8643e6d2012-01-18 20:26:10613content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31614 return view_.get();
615}
616
[email protected]01ec4ec2012-01-18 04:13:47617content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50618 WebUIControllerFactory* factory =
619 content::GetContentClient()->browser()->GetWebUIControllerFactory();
620 if (!factory)
621 return NULL;
[email protected]d2353452012-01-19 19:53:56622 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22623 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50624 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22625 if (controller) {
626 web_ui->SetController(controller);
627 return web_ui;
628 }
629
630 delete web_ui;
631 return NULL;
632}
633
[email protected]01ec4ec2012-01-18 04:13:47634content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31635 return render_manager_.web_ui() ? render_manager_.web_ui()
636 : render_manager_.pending_web_ui();
637}
638
[email protected]01ec4ec2012-01-18 04:13:47639content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31640 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34641}
642
[email protected]96d185d2009-04-24 03:28:54643const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55644 // Transient entries take precedence. They are used for interstitial pages
645 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23646 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08647 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20648 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30649 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23650 if (entry) {
[email protected]b5cca982011-05-26 04:42:08651 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23652 }
[email protected]7ade2732011-02-10 00:13:58653 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
654 render_manager_.pending_web_ui() : render_manager_.web_ui();
655 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54656 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55657 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54658 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35659 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22660 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54661 if (!title.empty())
662 return title;
663 }
664 }
665
666 // We use the title for the last committed entry rather than a pending
667 // navigation entry. For example, when the user types in a URL, we want to
668 // keep the old page's title until the new load has committed and we get a new
669 // title.
[email protected]96d185d2009-04-24 03:28:54670 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23671 if (entry) {
[email protected]b5cca982011-05-26 04:42:08672 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23673 }
[email protected]987fc3a2011-05-26 14:18:09674
675 // |page_title_when_no_navigation_entry_| is finally used
676 // if no title cannot be retrieved.
677 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54678}
679
[email protected]d5f942ba2008-09-26 19:30:34680int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46681 return GetMaxPageIDForSiteInstance(GetSiteInstance());
682}
683
684int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33685 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
686 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46687
[email protected]b6583592012-01-25 19:52:33688 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34689}
690
691void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46692 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
693}
694
[email protected]b6583592012-01-25 19:52:33695void TabContents::UpdateMaxPageIDForSiteInstance(
696 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46697 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33698 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34699}
700
[email protected]91854cd2012-01-10 19:43:57701void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
702 max_page_ids_ = tab_contents->max_page_ids_;
703}
704
[email protected]96d185d2009-04-24 03:28:54705SiteInstance* TabContents::GetSiteInstance() const {
706 return render_manager_.current_host()->site_instance();
707}
708
[email protected]77362eb2011-08-01 17:18:38709SiteInstance* TabContents::GetPendingSiteInstance() const {
710 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
711 render_manager_.pending_render_view_host() :
712 render_manager_.current_host();
713 return dest_rvh->site_instance();
714}
715
[email protected]be1f56ab2011-12-22 06:55:31716bool TabContents::IsLoading() const {
717 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49718}
719
[email protected]be1f56ab2011-12-22 06:55:31720bool TabContents::IsWaitingForResponse() const {
721 return waiting_for_response_;
722}
723
724const net::LoadStateWithParam& TabContents::GetLoadState() const {
725 return load_state_;
726}
727
728const string16& TabContents::GetLoadStateHost() const {
729 return load_state_host_;
730}
731
732uint64 TabContents::GetUploadSize() const {
733 return upload_size_;
734}
735
736uint64 TabContents::GetUploadPosition() const {
737 return upload_position_;
738}
739
740const std::string& TabContents::GetEncoding() const {
741 return encoding_;
742}
743
744bool TabContents::DisplayedInsecureContent() const {
745 return displayed_insecure_content_;
746}
747
748void TabContents::SetCapturingContents(bool cap) {
749 capturing_contents_ = cap;
750}
751
752bool TabContents::IsCrashed() const {
753 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
754 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
755 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49756}
757
[email protected]443b80e2010-12-14 00:42:23758void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
759 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34760 return;
761
[email protected]443b80e2010-12-14 00:42:23762 crashed_status_ = status;
763 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46764 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34765}
766
[email protected]be1f56ab2011-12-22 06:55:31767base::TerminationStatus TabContents::GetCrashedStatus() const {
768 return crashed_status_;
769}
770
771bool TabContents::IsBeingDestroyed() const {
772 return is_being_destroyed_;
773}
774
[email protected]d5f942ba2008-09-26 19:30:34775void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
776 if (delegate_)
777 delegate_->NavigationStateChanged(this, changed_flags);
778}
779
[email protected]96d185d2009-04-24 03:28:54780void TabContents::DidBecomeSelected() {
781 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04782 RenderWidgetHostViewPort* rwhv =
783 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16784 if (rwhv) {
785 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43786#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16787 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43788#endif
789 }
[email protected]96d185d2009-04-24 03:28:54790
[email protected]5ac20162010-11-24 23:33:11791 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38792
[email protected]d8c660432011-12-22 20:51:25793 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59794
795 // The resize rect might have changed while this was inactive -- send the new
796 // one to make sure it's up to date.
797 RenderViewHost* rvh = GetRenderViewHost();
798 if (rvh) {
799 rvh->ResizeRectChanged(GetRootWindowResizerRect());
800 }
[email protected]96d185d2009-04-24 03:28:54801}
802
[email protected]be1f56ab2011-12-22 06:55:31803
804base::TimeTicks TabContents::GetLastSelectedTime() const {
805 return last_selected_time_;
806}
807
[email protected]96d185d2009-04-24 03:28:54808void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31809 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52810 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
811 // open a tab in then background, then closes the tab before selecting it.
812 // This is because closing the tab calls TabContents::Destroy(), which
813 // removes the |GetRenderViewHost()|; then when we actually destroy the
814 // window, OnWindowPosChanged() notices and calls HideContents() (which
815 // calls us).
[email protected]c30585c2012-02-16 15:02:04816 RenderWidgetHostViewPort* rwhv =
817 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16818 if (rwhv)
819 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54820 }
821
[email protected]ad50def52011-10-19 23:17:07822 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09823 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
824 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07825 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54826}
827
[email protected]be1f56ab2011-12-22 06:55:31828void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04829 RenderWidgetHostViewPort* rwhv =
830 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31831 if (rwhv)
832 rwhv->DidBecomeSelected();
833}
834
835void TabContents::HideContents() {
836 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
837 // our superclass HideContents(), because some callers want to be very picky
838 // about the order in which these get called. In addition to making the code
839 // here practically impossible to understand, this also means we end up
840 // calling TabContents::WasHidden() twice if callers call both versions of
841 // HideContents() on a TabContents.
842 WasHidden();
843}
844
845bool TabContents::NeedToFireBeforeUnload() {
846 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27847 return WillNotifyDisconnection() &&
848 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31849 !GetRenderViewHost()->SuddenTerminationAllowed();
850}
851
[email protected]0bfbf882011-12-22 18:19:27852void TabContents::Stop() {
853 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25854 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27855}
856
[email protected]d9083482012-01-06 00:38:46857WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27858 // We create a new SiteInstance so that the new tab won't share processes
859 // with the old one. This can be changed in the future if we need it to share
860 // processes for some reason.
861 TabContents* tc = new TabContents(
862 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33863 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27864 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20865 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27866 return tc;
867}
868
[email protected]2a6bc3e2011-12-28 23:51:33869void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27870 WindowOpenDisposition disposition,
871 const gfx::Rect& initial_pos,
872 bool user_gesture) {
873 if (!delegate_)
874 return;
875
876 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
877 user_gesture);
878}
879
880gfx::NativeView TabContents::GetContentNativeView() const {
881 return view_->GetContentNativeView();
882}
883
884gfx::NativeView TabContents::GetNativeView() const {
885 return view_->GetNativeView();
886}
887
888void TabContents::GetContainerBounds(gfx::Rect* out) const {
889 view_->GetContainerBounds(out);
890}
891
892void TabContents::Focus() {
893 view_->Focus();
894}
895
[email protected]d8c660432011-12-22 20:51:25896void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31897 observers_.AddObserver(observer);
898}
899
[email protected]d8c660432011-12-22 20:51:25900void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31901 observers_.RemoveObserver(observer);
902}
903
[email protected]d5f942ba2008-09-26 19:30:34904void TabContents::Activate() {
905 if (delegate_)
906 delegate_->ActivateContents(this);
907}
908
[email protected]ea42e7782010-08-23 23:58:12909void TabContents::Deactivate() {
910 if (delegate_)
911 delegate_->DeactivateContents(this);
912}
913
[email protected]63954792011-07-11 04:17:48914void TabContents::LostCapture() {
915 if (delegate_)
916 delegate_->LostCapture();
917}
918
919bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
920 bool* is_keyboard_shortcut) {
921 return delegate_ &&
922 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
923}
924
925void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
926 if (delegate_)
927 delegate_->HandleKeyboardEvent(event);
928}
929
[email protected]32ded2212011-11-10 18:51:43930void TabContents::HandleMouseDown() {
931 if (delegate_)
932 delegate_->HandleMouseDown();
933}
934
[email protected]63954792011-07-11 04:17:48935void TabContents::HandleMouseUp() {
936 if (delegate_)
937 delegate_->HandleMouseUp();
938}
939
940void TabContents::HandleMouseActivate() {
941 if (delegate_)
942 delegate_->HandleMouseActivate();
943}
944
[email protected]8a5e0ca2011-08-25 06:30:47945void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
946 if (delegate_)
947 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
948}
949
[email protected]5d5f7af2011-10-01 01:38:12950bool TabContents::IsFullscreenForCurrentTab() const {
951 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
952}
953
[email protected]e9621112011-10-17 05:38:37954void TabContents::RequestToLockMouse() {
955 if (delegate_) {
956 delegate_->RequestToLockMouse(this);
957 } else {
958 GotResponseToLockMouseRequest(false);
959 }
960}
961
962void TabContents::LostMouseLock() {
963 if (delegate_)
964 delegate_->LostMouseLock();
965}
966
[email protected]0548c5352011-09-07 00:33:33967void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23968 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33969 if (delegate_)
970 delegate_->UpdatePreferredSize(this, pref_size);
971}
972
[email protected]32ded2212011-11-10 18:51:43973void TabContents::WebUISend(RenderViewHost* render_view_host,
974 const GURL& source_url,
975 const std::string& name,
976 const base::ListValue& args) {
977 if (delegate_)
978 delegate_->WebUISend(this, source_url, name, args);
979}
980
[email protected]e5d549d2011-12-28 01:29:20981WebContents* TabContents::OpenURL(const OpenURLParams& params) {
982 if (!delegate_)
983 return NULL;
[email protected]00c37fc2011-08-02 00:22:50984
[email protected]e5d549d2011-12-28 01:29:20985 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
986 // Notify observers.
987 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
988 DidOpenURL(params.url, params.referrer,
989 params.disposition, params.transition));
990 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34991}
992
[email protected]1ccb3568d2010-02-19 10:51:16993bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50994 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25995 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23996 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25997 reload_type);
[email protected]876bc832010-09-07 16:29:54998}
[email protected]96d185d2009-04-24 03:28:54999
[email protected]876bc832010-09-07 16:29:541000bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231001 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501002 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401003 // The renderer will reject IPC messages with URLs longer than
1004 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511005 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401006 return false;
1007
[email protected]dd11de52011-11-03 22:54:271008 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:401009 if (!dest_render_view_host)
1010 return false; // Unable to create the desired render view host.
1011
[email protected]80a8fad2011-01-29 04:02:381012 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071013 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581014 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501015 WebUIControllerFactory* factory =
1016 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1017 bool is_allowed_in_web_ui_renderer =
1018 factory &&
1019 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431020#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511021 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431022#endif
[email protected]e091df82011-10-11 18:13:211023 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551024 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581025
[email protected]96d185d2009-04-24 03:28:541026 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441027 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521028 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441029 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511030 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541031
1032 // Used for page load time metrics.
1033 current_load_start_ = base::TimeTicks::Now();
1034
1035 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341036 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271037 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471038 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341039 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541040
[email protected]36fc0392011-12-25 03:59:511041 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541042 // HACK!! This code suppresses javascript: URLs from being added to
1043 // session history, which is what we want to do for javascript: URLs that
1044 // do not generate content. What we really need is a message from the
1045 // renderer telling us that a new page was not created. The same message
1046 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511047 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541048 return false;
1049 }
1050
[email protected]3c9e1872010-11-18 16:17:491051 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251052 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041053 observers_,
[email protected]36fc0392011-12-25 03:59:511054 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541055
[email protected]09b29342011-06-24 19:18:481056 if (delegate_)
1057 delegate_->DidNavigateToPendingEntry(this);
1058
[email protected]d5f942ba2008-09-26 19:30:341059 return true;
1060}
1061
[email protected]b6583592012-01-25 19:52:331062void TabContents::SetHistoryLengthAndPrune(
1063 const SiteInstance* site_instance,
1064 int history_length,
1065 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411066 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1067 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191068 if (render_manager_.pending_render_view_host()) {
1069 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141070 return;
[email protected]9e1ad4b2011-08-14 16:49:191071 }
[email protected]151a63d2011-12-20 22:32:521072 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191073 if (!rvh) {
1074 NOTREACHED();
1075 return;
1076 }
1077 if (site_instance && rvh->site_instance() != site_instance) {
1078 NOTREACHED();
1079 return;
1080 }
1081 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1082 history_length,
1083 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141084}
1085
[email protected]90daadb42009-06-08 21:27:281086void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271087 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541088 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1089 return;
1090 }
[email protected]151a63d2011-12-20 22:32:521091 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541092}
1093
[email protected]0bfbf882011-12-22 18:19:271094bool TabContents::ShowingInterstitialPage() const {
1095 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541096}
1097
[email protected]0bfbf882011-12-22 18:19:271098InterstitialPage* TabContents::GetInterstitialPage() const {
1099 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221100}
1101
[email protected]a53209b2012-01-20 16:48:161102bool TabContents::IsSavable() {
1103 // WebKit creates Document object when MIME type is application/xhtml+xml,
1104 // so we also support this MIME type.
1105 return contents_mime_type_ == "text/html" ||
1106 contents_mime_type_ == "text/xml" ||
1107 contents_mime_type_ == "application/xhtml+xml" ||
1108 contents_mime_type_ == "text/plain" ||
1109 contents_mime_type_ == "text/css" ||
1110 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1111}
1112
[email protected]c7dd2f62011-07-18 15:57:591113void TabContents::OnSavePage() {
1114 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161115 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481116 download_stats::RecordDownloadSource(
1117 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261118 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141119 return;
[email protected]c7dd2f62011-07-18 15:57:591120 }
1121
1122 Stop();
1123
1124 // Create the save package and possibly prompt the user for the name to save
1125 // the page as. The user prompt is an asynchronous operation that runs on
1126 // another thread.
1127 save_package_ = new SavePackage(this);
1128 save_package_->GetSaveInfo();
1129}
1130
1131// Used in automated testing to bypass prompting the user for file names.
1132// Instead, the names and paths are hard coded rather than running them through
1133// file name sanitation and extension / mime checking.
1134bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161135 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591136 // Stop the page from navigating.
1137 Stop();
1138
1139 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1140 return save_package_->Init();
1141}
1142
[email protected]aa4f3972012-03-01 18:12:121143void TabContents::GenerateMHTML(
1144 const FilePath& file,
1145 const base::Callback<void(const FilePath&, int64)>& callback) {
1146 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1147}
1148
[email protected]420ae012009-04-24 05:16:321149bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231150 NavigationEntryImpl* active_entry =
1151 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321152 return (active_entry != NULL &&
1153 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511154 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321155}
1156
[email protected]0bfbf882011-12-22 18:19:271157const std::string& TabContents::GetContentsMimeType() const {
1158 return contents_mime_type_;
1159}
1160
1161bool TabContents::WillNotifyDisconnection() const {
1162 return notify_disconnection_;
1163}
1164
[email protected]b2fe07d12010-02-09 14:38:081165void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311166 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521167 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1168 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161169}
1170
[email protected]b2fe07d12010-02-09 14:38:081171void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311172 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521173 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1174 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161175}
1176
[email protected]0bfbf882011-12-22 18:19:271177content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1178 return &renderer_preferences_;
1179}
1180
1181void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1182 new_tab_start_time_ = time;
1183}
1184
1185base::TimeTicks TabContents::GetNewTabStartTime() const {
1186 return new_tab_start_time_;
1187}
1188
[email protected]7ab1e7d62009-10-14 23:32:011189void TabContents::OnCloseStarted() {
1190 if (tab_close_start_time_.is_null())
1191 tab_close_start_time_ = base::TimeTicks::Now();
1192}
1193
[email protected]46624bf2010-06-09 16:04:191194bool TabContents::ShouldAcceptDragAndDrop() const {
1195#if defined(OS_CHROMEOS)
1196 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1197 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511198 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201199 return false;
1200 return true;
[email protected]46624bf2010-06-09 16:04:191201#else
1202 return true;
1203#endif
1204}
1205
[email protected]7813bd72011-02-05 02:19:341206void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521207 if (GetRenderViewHost())
1208 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511209 if (delegate_)
1210 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341211}
1212
[email protected]0bfbf882011-12-22 18:19:271213void TabContents::SetClosedByUserGesture(bool value) {
1214 closed_by_user_gesture_ = value;
1215}
1216
1217bool TabContents::GetClosedByUserGesture() const {
1218 return closed_by_user_gesture_;
1219}
1220
[email protected]d0b8d092010-10-25 04:05:171221double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051222 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561223 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251224 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171225 return 0;
[email protected]b75b8292010-10-01 07:28:251226
1227 double zoom_level;
1228 if (temporary_zoom_settings_) {
1229 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521230 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251231 } else {
[email protected]2ae88d12011-10-14 09:11:191232 GURL url;
[email protected]10f417c52011-12-28 21:04:231233 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191234 // Since zoom map is updated using rewritten URL, use rewritten URL
1235 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511236 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191237 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251238 }
[email protected]d0b8d092010-10-25 04:05:171239 return zoom_level;
1240}
[email protected]b75b8292010-10-01 07:28:251241
[email protected]d0b8d092010-10-25 04:05:171242int TabContents::GetZoomPercent(bool* enable_increment,
1243 bool* enable_decrement) {
1244 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011245 // Calculate the zoom percent from the factor. Round up to the nearest whole
1246 // number.
[email protected]b75b8292010-10-01 07:28:251247 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011248 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251249 *enable_decrement = percent > minimum_zoom_percent_;
1250 *enable_increment = percent < maximum_zoom_percent_;
1251 return percent;
1252}
1253
[email protected]3c733bde2010-12-21 19:56:311254void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501255 if (!delegate_)
1256 return;
1257
[email protected]10f417c52011-12-28 21:04:231258 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501259 if (!active_entry)
1260 return;
1261
[email protected]36fc0392011-12-25 03:59:511262 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121263}
1264
[email protected]932b7a12011-03-09 12:50:271265void TabContents::ViewFrameSource(const GURL& url,
1266 const std::string& content_state) {
1267 if (!delegate_)
1268 return;
1269
1270 delegate_->ViewSourceForFrame(this, url, content_state);
1271}
1272
[email protected]0bfbf882011-12-22 18:19:271273int TabContents::GetMinimumZoomPercent() const {
1274 return minimum_zoom_percent_;
1275}
1276
1277int TabContents::GetMaximumZoomPercent() const {
1278 return maximum_zoom_percent_;
1279}
1280
[email protected]bcd2815602012-01-14 18:17:231281gfx::Size TabContents::GetPreferredSize() const {
1282 return preferred_size_;
1283}
1284
[email protected]0bfbf882011-12-22 18:19:271285int TabContents::GetContentRestrictions() const {
1286 return content_restrictions_;
1287}
1288
1289WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501290 WebUIControllerFactory* factory =
1291 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1292 if (!factory)
1293 return WebUI::kNoWebUI;
1294 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271295}
1296
[email protected]01ec4ec2012-01-18 04:13:471297content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271298 // When there is a pending navigation entry, we want to use the pending WebUI
1299 // that goes along with it to control the basic flags. For example, we want to
1300 // show the pending URL in the URL bar, so we want the display_url flag to
1301 // be from the pending entry.
1302 //
1303 // The confusion comes because there are multiple possibilities for the
1304 // initial load in a tab as a side effect of the way the RenderViewHostManager
1305 // works.
1306 //
1307 // - For the very first tab the load looks "normal". The new tab Web UI is
1308 // the pending one, and we want it to apply here.
1309 //
1310 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1311 // get switched to the one previously associated with the new tab pages.
1312 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1313 // have a committed Web UI in this case.
1314 //
1315 // This condition handles all of these cases:
1316 //
1317 // - First load in first tab: no committed nav entry + pending nav entry +
1318 // pending dom ui:
1319 // -> Use pending Web UI if any.
1320 //
1321 // - First load in second tab: no committed nav entry + pending nav entry +
1322 // no pending Web UI:
1323 // -> Use the committed Web UI if any.
1324 //
1325 // - Second navigation in any tab: committed nav entry + pending nav entry:
1326 // -> Use pending Web UI if any.
1327 //
1328 // - Normal state with no load: committed nav entry + no pending nav entry:
1329 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251330 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271331 (controller_.GetLastCommittedEntry() ||
1332 render_manager_.pending_web_ui()))
1333 return render_manager_.pending_web_ui();
1334 return render_manager_.web_ui();
1335}
1336
1337bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1338 return GetRenderViewHost() ?
1339 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1340}
1341
1342bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471343 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271344 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221345 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231346 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511347 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271348 return true;
1349 return false;
1350}
1351
1352void TabContents::SetFocusToLocationBar(bool select_all) {
1353 if (delegate_)
1354 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211355}
1356
[email protected]8b5af492011-11-28 21:50:581357void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301358 const string16& type,
1359 const string16& href,
1360 const string16& title,
1361 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511362 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301363 this, action, type, href, title, disposition);
1364}
1365
[email protected]678105012011-12-09 04:01:211366void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301367 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001368 WebIntentsDispatcherImpl* intents_dispatcher =
1369 new WebIntentsDispatcherImpl(this, intent, intent_id);
1370 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301371}
1372
[email protected]724159a2010-12-30 01:11:181373void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1374 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591375 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181376 const GURL& url) {
1377 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1378 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591379 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301380 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181381
[email protected]8093a542011-05-13 07:29:321382 RenderViewHost* rvh =
1383 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521384 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101385 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101387 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321388 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101389
[email protected]724159a2010-12-30 01:11:181390 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591391 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251392 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591393 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181394 }
1395}
1396
1397void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591398 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181399 const GURL& source_url,
1400 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491401 // TODO(creis): Remove this method and have the pre-rendering code listen to
1402 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1403 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231404 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181405 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251406 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181407 else
1408 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511409 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181410 return;
[email protected]e7d50892011-01-19 21:47:381411
[email protected]4850a7f2011-03-08 23:36:591412 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251413 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261414 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591415 opener_url));
[email protected]724159a2010-12-30 01:11:181416}
1417
1418void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581419 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1420 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1421 << ", error_code: " << params.error_code
1422 << ", error_description: " << params.error_description
1423 << ", is_main_frame: " << params.is_main_frame
1424 << ", showing_repost_interstitial: " <<
1425 params.showing_repost_interstitial
1426 << ", frame_id: " << params.frame_id;
1427 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591428 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301429 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181430
[email protected]d7b175e2011-10-11 15:31:581431 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181432 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1433 // This means that the interstitial won't be torn down properly, which is
1434 // bad. But if we have an interstitial, go back to another tab type, and
1435 // then load the same interstitial again, we could end up getting the first
1436 // interstitial's "failed" message (as a result of the cancel) when we're on
1437 // the second one.
1438 //
1439 // We can't tell this apart, so we think we're tearing down the current page
1440 // which will cause a crash later one. There is also some code in
1441 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1442 // out because of this problem.
1443 //
1444 // http://code.google.com/p/chromium/issues/detail?id=2855
1445 // Because this will not tear down the interstitial properly, if "back" is
1446 // back to another tab type, the interstitial will still be somewhat alive
1447 // in the previous tab type. If you navigate somewhere that activates the
1448 // tab with the interstitial again, you'll see a flash before the new load
1449 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271450 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181451 LOG(WARNING) << "Discarding message during interstitial.";
1452 return;
1453 }
1454
[email protected]02102f82011-06-13 20:37:021455 // Discard our pending entry if the load canceled (e.g. if we decided to
1456 // download the file instead of load it). We do not verify that the URL
1457 // being canceled matches the pending entry's URL because they will not
1458 // match if a redirect occurred (in which case we do not want to leave a
1459 // stale redirect URL showing). This means that we also cancel the pending
1460 // entry if the user started a new navigation. As a result, the navigation
1461 // controller may not remember that a load is in progress, but the
1462 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251463 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161464 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181465
[email protected]151a63d2011-12-20 22:32:521466 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181467 }
1468
1469 // Send out a notification that we failed a provisional load with an error.
1470 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581471 params.is_main_frame,
1472 controller_.IsURLInPageNavigation(validated_url),
1473 validated_url,
1474 std::string(),
1475 false,
1476 params.frame_id);
1477 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181478
[email protected]ad50def52011-10-19 23:17:071479 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271480 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501481 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531482 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101483
[email protected]d8c660432011-12-22 20:51:251484 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581485 observers_,
1486 DidFailProvisionalLoad(params.frame_id,
1487 params.is_main_frame,
1488 validated_url,
1489 params.error_code,
1490 params.error_description));
[email protected]724159a2010-12-30 01:11:181491}
1492
1493void TabContents::OnDidLoadResourceFromMemoryCache(
1494 const GURL& url,
[email protected]70435962011-08-02 20:13:281495 const std::string& security_info,
1496 const std::string& http_method,
1497 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191498 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181499 cache.Increment();
1500
1501 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081502 int cert_id = 0;
1503 net::CertStatus cert_status = 0;
1504 int security_bits = -1;
1505 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511506 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1507 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301508 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161509 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181510
[email protected]ad50def52011-10-19 23:17:071511 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271512 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501513 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531514 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181515}
1516
1517void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381518 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181519 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201520 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181521}
1522
1523void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021524 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231525 LOG(INFO) << security_origin << " ran insecure content from "
1526 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381527 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051528 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381529 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051530 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1531 }
[email protected]330614de2012-02-13 17:07:181532 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411533 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201534 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181535}
1536
1537void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1538 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251539 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101540 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181541}
1542
[email protected]1a55c5b2011-11-29 11:36:311543void TabContents::OnDidFinishLoad(
1544 int64 frame_id,
1545 const GURL& validated_url,
1546 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251547 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311548 DidFinishLoad(frame_id, validated_url, is_main_frame));
1549}
1550
1551void TabContents::OnDidFailLoadWithError(int64 frame_id,
1552 const GURL& validated_url,
1553 bool is_main_frame,
1554 int error_code,
1555 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251556 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311557 DidFailLoad(frame_id, validated_url, is_main_frame,
1558 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181559}
1560
[email protected]c8f73ab2011-01-22 00:05:171561void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271562 content_restrictions_ = restrictions;
1563 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171564}
1565
[email protected]216813952011-05-19 22:21:261566void TabContents::OnGoToEntryAtOffset(int offset) {
1567 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231568 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251569 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261570 if (!entry)
1571 return;
1572 // Note that we don't call NavigationController::GotToOffset() as we don't
1573 // want to create a pending navigation entry (it might end up lingering
1574 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251575 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581576 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511577 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581578 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471579 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571580
1581 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1582 // it in now that we know. This allows us to find the entry when it commits.
1583 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231584 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331585 entry->set_site_instance(
1586 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571587 }
[email protected]216813952011-05-19 22:21:261588 }
1589}
1590
1591void TabContents::OnUpdateZoomLimits(int minimum_percent,
1592 int maximum_percent,
1593 bool remember) {
1594 minimum_zoom_percent_ = minimum_percent;
1595 maximum_zoom_percent_ = maximum_percent;
1596 temporary_zoom_settings_ = !remember;
1597}
1598
[email protected]0bfbf882011-12-22 18:19:271599void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481600 download_stats::RecordDownloadSource(
1601 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261602 // Check if the URL to save matches the URL of the main frame. Since this
1603 // message originates from Pepper plugins, it may not be the case if the
1604 // plugin is an embedded element.
1605 GURL main_frame_url = GetURL();
1606 if (!main_frame_url.is_valid())
1607 return;
1608 bool is_main_frame = (url == main_frame_url);
1609 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271610}
1611
[email protected]3a29a6e2011-08-24 18:26:211612void TabContents::OnEnumerateDirectory(int request_id,
1613 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591614 ChildProcessSecurityPolicyImpl* policy =
1615 ChildProcessSecurityPolicyImpl::GetInstance();
1616 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1617 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211618}
1619
[email protected]7d189022011-08-25 22:54:201620void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511621 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201622}
1623
1624void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1625 const GURL& url,
1626 const string16& title) {
[email protected]b9535422012-02-09 01:47:591627 ChildProcessSecurityPolicyImpl* policy =
1628 ChildProcessSecurityPolicyImpl::GetInstance();
1629 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1630 return;
[email protected]6934a702011-12-20 00:04:511631 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201632}
1633
[email protected]b888919c2011-09-02 00:32:161634void TabContents::OnFindReply(int request_id,
1635 int number_of_matches,
1636 const gfx::Rect& selection_rect,
1637 int active_match_ordinal,
1638 bool final_update) {
[email protected]6934a702011-12-20 00:04:511639 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1640 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001641 // Send a notification to the renderer that we are ready to receive more
1642 // results from the scoping effort of the Find operation. The FindInPage
1643 // scoping is asynchronous and periodically sends results back up to the
1644 // browser using IPC. In an effort to not spam the browser we have the
1645 // browser send an ACK for each FindReply message and have the renderer
1646 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521647 GetRenderViewHost()->Send(
1648 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161649}
1650
[email protected]d952a052011-09-06 18:42:451651void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511652 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451653}
1654
[email protected]7fc4bbb2011-09-08 21:23:101655void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1656 bool blocked_by_policy) {
1657 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101659 AppCacheAccessed(manifest_url, blocked_by_policy));
1660}
1661
[email protected]96d185d2009-04-24 03:28:541662// Notifies the RenderWidgetHost instance about the fact that the page is
1663// loading, or done loading and calls the base implementation.
1664void TabContents::SetIsLoading(bool is_loading,
1665 LoadNotificationDetails* details) {
1666 if (is_loading == is_loading_)
1667 return;
1668
1669 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211670 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541671 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561672 upload_size_ = 0;
1673 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541674 }
1675
1676 render_manager_.SetIsLoading(is_loading);
1677
1678 is_loading_ = is_loading;
1679 waiting_for_response_ = is_loading;
1680
[email protected]6ebdc9b2010-09-27 16:55:571681 if (delegate_)
1682 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461683 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541684
[email protected]432115822011-07-10 15:52:271685 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1686 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071687 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541688 if (details)
[email protected]6c2381d2011-10-19 02:52:531689 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071690 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501691 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541692 det);
1693}
1694
[email protected]420ae012009-04-24 05:16:321695void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131696 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321697 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561698 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381699 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441700 // that opened the window, as long as both renderers have the same
1701 // privileges.
[email protected]1fd1a502011-03-30 16:55:561702 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561703 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581704 // web_ui might be NULL if the URL refers to a non-existent extension.
1705 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401706 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521707 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441708 }
1709 }
[email protected]1fd1a502011-03-30 16:55:561710 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441711 }
1712
[email protected]4e697b042011-07-08 06:44:561713 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321714 // Clear the status bubble. This is a workaround for a bug where WebKit
1715 // doesn't let us know that the cursor left an element during a
1716 // transition (this is also why the mouse cursor remains as a hand after
1717 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1718 // clear the bubble when a user navigates to a named anchor in the same
1719 // page.
[email protected]36fc0392011-12-25 03:59:511720 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321721 }
1722
[email protected]a6e82fc2010-02-24 22:28:141723 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471724 // Once the main frame is navigated, we're no longer considered to have
1725 // displayed insecure content.
1726 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171727 }
[email protected]ce5c4502009-05-06 16:46:111728
[email protected]3c9e1872010-11-18 16:17:491729 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041731 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321732}
1733
1734void TabContents::DidNavigateAnyFramePostCommit(
1735 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131736 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321737 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061738 // If we navigate off the page, reset JavaScript state. This does nothing
1739 // to prevent a malicious script from spamming messages, since the script
1740 // could just reload the page to stop blocking.
1741 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551742 dialog_creator_->ResetJavaScriptState(this);
1743 dialog_creator_ = NULL;
1744 }
[email protected]420ae012009-04-24 05:16:321745
[email protected]3c9e1872010-11-18 16:17:491746 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251747 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041748 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321749}
1750
[email protected]74ce1ad2011-12-16 21:51:461751void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1752 // If we are creating a RVH for a restored controller, then we need to make
1753 // sure the RenderView starts with a next_page_id_ larger than the number
1754 // of restored entries. This must be called before the RenderView starts
1755 // navigating (to avoid a race between the browser updating max_page_id and
1756 // the renderer updating next_page_id_). Because of this, we only call this
1757 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561758 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461759 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1760 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321761}
1762
[email protected]10f417c52011-12-28 21:04:231763bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571764 const string16& title) {
[email protected]420ae012009-04-24 05:16:321765 // For file URLs without a title, use the pathname instead. In the case of a
1766 // synthesized title, we don't want the update to count toward the "one set
1767 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511768 string16 final_title;
[email protected]420ae012009-04-24 05:16:321769 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511770 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1771 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321772 explicit_set = false; // Don't count synthetic titles toward the set limit.
1773 } else {
[email protected]acafd272011-07-26 17:35:571774 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321775 explicit_set = true;
1776 }
1777
[email protected]987fc3a2011-05-26 14:18:091778 // If a page is created via window.open and never navigated,
1779 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551780 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091781 if (entry) {
[email protected]36fc0392011-12-25 03:59:511782 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091783 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321784
[email protected]36fc0392011-12-25 03:59:511785 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091786 } else {
1787 if (page_title_when_no_navigation_entry_ == final_title)
1788 return false; // Nothing changed, don't bother.
1789
1790 page_title_when_no_navigation_entry_ = final_title;
1791 }
[email protected]420ae012009-04-24 05:16:321792
[email protected]420ae012009-04-24 05:16:321793 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231794 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321795
[email protected]105bb0f2011-05-24 17:12:141796 TitleUpdatedDetails details(entry, explicit_set);
1797
[email protected]ad50def52011-10-19 23:17:071798 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441799 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1800 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531801 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041802
[email protected]420ae012009-04-24 05:16:321803 return true;
1804}
1805
1806void TabContents::NotifySwapped() {
1807 // After sending out a swap notification, we need to send a disconnect
1808 // notification so that clients that pick up a pointer to |this| can NULL the
1809 // pointer. See Bug 1230284.
1810 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071811 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201812 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1813 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071814 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321815}
1816
1817void TabContents::NotifyConnected() {
1818 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071819 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121820 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1821 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071822 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321823}
1824
1825void TabContents::NotifyDisconnected() {
1826 if (!notify_disconnection_)
1827 return;
1828
1829 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071830 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321831 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1832 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071833 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321834}
1835
[email protected]8d3347f2009-07-09 22:00:211836RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321837 return view_.get();
1838}
1839
[email protected]8d3347f2009-07-09 22:00:211840RenderViewHostDelegate::RendererManagement*
1841TabContents::GetRendererManagementDelegate() {
1842 return &render_manager_;
1843}
1844
[email protected]daf82f82011-10-31 22:35:311845content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371846 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461847 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511848}
1849
[email protected]768c5472011-12-26 19:06:171850WebContents* TabContents::GetAsWebContents() {
1851 return this;
1852}
1853
[email protected]da4dfc42011-10-12 15:53:561854content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431855 return view_type_;
[email protected]7b291f92009-08-14 05:43:531856}
1857
[email protected]b7a756d42012-01-23 18:08:171858gfx::Rect TabContents::GetRootWindowResizerRect() const {
1859 if (delegate_)
1860 return delegate_->GetRootWindowResizerRect();
1861 return gfx::Rect();
1862}
1863
[email protected]420ae012009-04-24 05:16:321864void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071865 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271866 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321867 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531868 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231869 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321870 if (!entry)
1871 return;
1872
1873 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351874 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561875 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581876 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321877
1878 if (entry->IsViewSourceMode()) {
1879 // Put the renderer in view source mode.
1880 render_view_host->Send(
1881 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1882 }
[email protected]0666aef2009-05-13 19:48:081883
[email protected]d487beefe2011-12-21 05:41:211884 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261885
1886 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251887 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321888}
1889
1890void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521891 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321892 // Don't notify the world, since this came from a renderer in the
1893 // background.
1894 return;
1895 }
1896
1897 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311898 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231899 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301900
1901 // Restore the focus to the tab (otherwise the focus will be on the top
1902 // window).
[email protected]484ae5912010-09-29 19:16:141903 if (was_crashed && !FocusLocationBarByDefault() &&
1904 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301905 Focus();
[email protected]484ae5912010-09-29 19:16:141906 }
[email protected]32ded2212011-11-10 18:51:431907
[email protected]d8c660432011-12-22 20:51:251908 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321909}
1910
[email protected]443b80e2010-12-14 00:42:231911void TabContents::RenderViewGone(RenderViewHost* rvh,
1912 base::TerminationStatus status,
1913 int error_code) {
[email protected]151a63d2011-12-20 22:32:521914 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321915 // The pending page's RenderViewHost is gone.
1916 return;
1917 }
1918
1919 SetIsLoading(false, NULL);
1920 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231921 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311922 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321923
[email protected]d8c660432011-12-22 20:51:251924 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271925 observers_,
[email protected]be1f56ab2011-12-22 06:55:311926 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321927}
1928
[email protected]2e4633c2009-07-09 16:58:061929void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481930 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251931 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061932}
1933
[email protected]420ae012009-04-24 05:16:321934void TabContents::DidNavigate(RenderViewHost* rvh,
1935 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581936 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321937 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371938
[email protected]434f69f2012-02-06 21:56:521939 // Update the site of the SiteInstance if it doesn't have one yet, unless
1940 // this is for about:blank. In that case, the SiteInstance can still be
1941 // considered unused until a navigation to a real page.
1942 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1943 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331944 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521945 }
[email protected]420ae012009-04-24 05:16:321946
1947 // Need to update MIME type here because it's referred to in
1948 // UpdateNavigationCommands() called by RendererDidNavigate() to
1949 // determine whether or not to enable the encoding menu.
1950 // It's updated only for the main frame. For a subframe,
1951 // RenderView::UpdateURL does not set params.contents_mime_type.
1952 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1953 // TODO(jungshik): Add a test for the encoding menu to avoid
1954 // regressing it again.
[email protected]2905f742011-10-13 03:51:581955 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321956 contents_mime_type_ = params.contents_mime_type;
1957
[email protected]8286f51a2011-05-31 17:39:131958 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001959 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391960
[email protected]a9c0bfe2010-09-17 08:35:221961 // Send notification about committed provisional loads. This notification is
1962 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1963 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081964 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071965 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1966 // that is not recorded in the navigation history. For the purpose of
1967 // tracking navigation events, we treat this event as a sub frame navigation
1968 // event.
1969 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581970 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221971 // Whether or not a page transition was triggered by going backward or
1972 // forward in the history is only stored in the navigation controller's
1973 // entry list.
1974 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511975 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581976 content::PAGE_TRANSITION_FORWARD_BACK)) {
1977 transition_type = content::PageTransitionFromInt(
1978 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221979 }
[email protected]0d60f0192011-04-14 12:40:101980 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251981 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101982 DidCommitProvisionalLoadForFrame(params.frame_id,
1983 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221984 }
1985
[email protected]76543b92009-08-31 17:27:451986 if (!did_navigate)
1987 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321988
1989 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1990 // for the appropriate notification (best) or you can add it to
1991 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1992 // necessary, please).
1993
1994 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001995 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321996 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511997 if (delegate_)
1998 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001999 }
[email protected]420ae012009-04-24 05:16:322000 DidNavigateAnyFramePostCommit(rvh, details, params);
2001}
2002
2003void TabContents::UpdateState(RenderViewHost* rvh,
2004 int32 page_id,
2005 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152006 // Ensure that this state update comes from either the active RVH or one of
2007 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522008 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322009
2010 // We must be prepared to handle state updates for any page, these occur
2011 // when the user is scrolling and entering form data, as well as when we're
2012 // leaving a page, in which case our state may have already been moved to
2013 // the next page. The navigation controller will look up the appropriate
2014 // NavigationEntry and update it when it is notified via the delegate.
2015
2016 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:152017 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:322018 if (entry_index < 0)
2019 return;
[email protected]10f417c52011-12-28 21:04:232020 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322021
[email protected]36fc0392011-12-25 03:59:512022 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322023 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512024 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322025 controller_.NotifyEntryChanged(entry, entry_index);
2026}
2027
2028void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572029 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462030 const string16& title,
2031 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322032 // If we have a title, that's a pretty good indication that we've started
2033 // getting useful data.
2034 SetNotWaitingForResponse();
2035
[email protected]73eb2602012-02-09 19:50:552036 // Try to find the navigation entry, which might not be the current one.
2037 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232038 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2039 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092040
[email protected]73eb2602012-02-09 19:50:552041 // We can handle title updates when we don't have an entry in
2042 // UpdateTitleForEntry, but only if the update is from the current RVH.
2043 if (!entry && rvh != GetRenderViewHost())
2044 return;
2045
[email protected]a49e10b2011-08-01 23:57:462046 // TODO(evan): make use of title_direction.
2047 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092048 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322049 return;
2050
2051 // Broadcast notifications when the UI should be updated.
2052 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462053 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322054}
2055
[email protected]420ae012009-04-24 05:16:322056void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402057 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312058 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322059}
2060
2061void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512062 if (delegate_)
2063 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322064}
2065
[email protected]420ae012009-04-24 05:16:322066void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292067 // The UI may be in an event-tracking loop, such as between the
2068 // mouse-down and mouse-up in text selection or a button click.
2069 // Defer the close until after tracking is complete, so that we
2070 // don't free objects out from under the UI.
2071 // TODO(shess): This could probably be integrated with the
2072 // IsDoingDrag() test below. Punting for now because I need more
2073 // research to understand how this impacts platforms other than Mac.
2074 // TODO(shess): This could get more fine-grained. For instance,
2075 // closing a tab in another window while selecting text in the
2076 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212077 if (GetView()->IsEventTracking()) {
2078 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292079 return;
2080 }
2081
[email protected]24a4d1062009-07-10 23:10:422082 // If we close the tab while we're in the middle of a drag, we'll crash.
2083 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212084 if (GetView()->IsDoingDrag()) {
2085 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422086 return;
2087 }
2088
[email protected]420ae012009-04-24 05:16:322089 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522090 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512091 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322092}
2093
[email protected]cd9ed79d2011-11-15 19:22:572094void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522095 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512096 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572097}
2098
[email protected]420ae012009-04-24 05:16:322099void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512100 if (delegate_ && delegate_->IsPopupOrPanel(this))
2101 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322102}
2103
[email protected]7ab1e7d62009-10-14 23:32:012104void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322105 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492106
[email protected]6934a702011-12-20 00:04:512107 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212108 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512109 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002110 }
[email protected]3c9e1872010-11-18 16:17:492111
2112 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252113 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322114}
2115
[email protected]7ab1e7d62009-10-14 23:32:012116void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322117 scoped_ptr<LoadNotificationDetails> details;
2118
[email protected]10f417c52011-12-28 21:04:232119 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322120 // An entry may not exist for a stop when loading an initial blank page or
2121 // if an iframe injected by script into a blank page finishes loading.
2122 if (entry) {
[email protected]420ae012009-04-24 05:16:322123 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2124
2125 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512126 entry->GetVirtualURL(),
2127 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322128 elapsed,
2129 &controller_,
2130 controller_.GetCurrentEntryIndex()));
2131 }
2132
[email protected]420ae012009-04-24 05:16:322133 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492134
2135 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252136 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322137}
2138
[email protected]c95fa8b2011-04-28 20:26:162139void TabContents::DidCancelLoading() {
2140 controller_.DiscardNonCommittedEntries();
2141
2142 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462143 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162144}
2145
[email protected]1a3c3cb2010-12-16 21:03:402146void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512147 if (delegate_)
2148 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402149}
2150
[email protected]952a68e2011-11-17 00:36:102151void TabContents::DocumentAvailableInMainFrame(
2152 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102154 DocumentAvailableInMainFrame());
2155}
2156
[email protected]25497492010-09-11 15:15:082157void TabContents::DocumentOnLoadCompletedInMainFrame(
2158 RenderViewHost* render_view_host,
2159 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072160 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272161 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322162 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532163 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082164}
2165
[email protected]ae5184d62011-10-06 19:25:582166void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152167 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582168 WindowOpenDisposition disposition,
2169 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482170 // Delegate to RequestTransferURL because this is just the generic
2171 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582172 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482173 GlobalRequestID());
2174}
2175
2176void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582177 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482178 WindowOpenDisposition disposition,
2179 int64 source_frame_id,
2180 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202181 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582182 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582183 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352184 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322185 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2186 // generated suggestions).
2187 //
[email protected]e0112912011-02-02 22:54:352188 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162189 // want web sites to see a referrer of "chrome://blah" (and some
2190 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322191 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432192 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222193 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482194 false /* is_renderer_initiated */);
2195 params.transferred_global_request_id = old_request_id;
2196 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222197 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322198 } else {
[email protected]6bf6a6b52012-02-03 15:41:432199 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482200 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2201 params.transferred_global_request_id = old_request_id;
2202 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582203 }
2204 if (new_contents) {
2205 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582207 DidOpenRequestedURL(new_contents,
2208 url,
2209 referrer,
2210 disposition,
2211 transition_type,
2212 source_frame_id));
[email protected]420ae012009-04-24 05:16:322213 }
2214}
2215
[email protected]420ae012009-04-24 05:16:322216void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342217 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412218 const string16& message,
2219 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322220 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472221 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322222 IPC::Message* reply_msg,
2223 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072224 // Suppress JavaScript dialogs when requested. Also suppress messages when
2225 // showing an interstitial as it's shown over the previous page and we don't
2226 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502227 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152228 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272229 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072230 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522231 delegate_->ShouldSuppressDialogs() ||
2232 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322233
2234 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432235 std::string accept_lang = content::GetContentClient()->browser()->
2236 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552237 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522238 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432239 this,
2240 frame_url.GetOrigin(),
2241 accept_lang,
2242 javascript_message_type,
2243 message,
[email protected]51da7e32012-01-30 19:24:522244 default_prompt,
2245 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432246 reply_msg),
[email protected]51da7e32012-01-30 19:24:522247 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322248 }
[email protected]3ab9cb82011-06-03 18:02:072249
2250 if (suppress_this_message) {
2251 // If we are suppressing messages, just reply as if the user immediately
2252 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342253 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072254 }
2255
2256 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322257}
2258
[email protected]fedec012012-01-28 03:09:342259void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412260 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322261 bool is_reload,
[email protected]420ae012009-04-24 05:16:322262 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512263 if (delegate_)
2264 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072265
2266 bool suppress_this_message =
2267 rvh->is_swapped_out() ||
2268 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522269 delegate_->ShouldSuppressDialogs() ||
2270 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152271 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342272 // The reply must be sent to the RVH that sent the request.
2273 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502274 return;
2275 }
[email protected]3ab9cb82011-06-03 18:02:072276
[email protected]7ab1e7d62009-10-14 23:32:012277 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552278 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522279 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322280 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522281 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2282 reply_msg));
[email protected]420ae012009-04-24 05:16:322283}
2284
[email protected]420ae012009-04-24 05:16:322285WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542286 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322287}
2288
[email protected]7d472472011-01-22 01:30:252289void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272290 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252291 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222292
[email protected]99907362012-01-11 05:41:402293 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172294 if (rdh) // NULL in unittests.
2295 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252296}
2297
[email protected]fa1cf0b82010-01-15 21:49:442298void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442299 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252300 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442301}
2302
[email protected]420ae012009-04-24 05:16:322303void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2304 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152305 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522306 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152307 return;
2308
[email protected]e5fc1632011-08-08 07:51:532309 // Ignore renderer unresponsive event if debugger is attached to the tab
2310 // since the event may be a result of the renderer sitting on a breakpoint.
2311 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442312 DevToolsAgentHost* agent =
2313 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2314 if (agent &&
2315 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532316 return;
2317
[email protected]420ae012009-04-24 05:16:322318 if (is_during_unload) {
2319 // Hang occurred while firing the beforeunload/unload handler.
2320 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112321 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322322
2323 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2324 return;
2325
2326 // If the tab hangs in the beforeunload/unload handler there's really
2327 // nothing we can do to recover. Pretend the unload listeners have
2328 // all fired and close the tab. If the hang is in the beforeunload handler
2329 // then the user will not have the option of cancelling the close.
2330 Close(rvh);
2331 return;
2332 }
2333
[email protected]151a63d2011-12-20 22:32:522334 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472335 return;
2336
[email protected]6934a702011-12-20 00:04:512337 if (delegate_)
2338 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322339}
2340
2341void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512342 if (delegate_)
2343 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322344}
2345
2346void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212347 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562348 uint64 upload_position,
2349 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322350 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562351 upload_position_ = upload_position;
2352 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502353 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202354 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302355 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212356 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322357 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462358 if (IsLoading()) {
2359 NotifyNavigationStateChanged(
2360 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2361 }
[email protected]420ae012009-04-24 05:16:322362}
2363
[email protected]7d472472011-01-22 01:30:252364void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512365 if (delegate_)
2366 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252367}
2368
[email protected]420ae012009-04-24 05:16:322369void TabContents::BeforeUnloadFiredFromRenderManager(
2370 bool proceed,
2371 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512372 if (delegate_)
2373 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322374}
2375
[email protected]3a3d47472010-07-15 21:03:542376void TabContents::DidStartLoadingFromRenderManager(
2377 RenderViewHost* render_view_host) {
2378 DidStartLoading();
2379}
2380
2381void TabContents::RenderViewGoneFromRenderManager(
2382 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232383 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2384 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542385}
2386
[email protected]420ae012009-04-24 05:16:322387void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102388 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262389 gfx::Size size = view_->GetContainerSize();
2390 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2391 // here during container initialization and normal window size will be set
2392 // later. In case of tab duplication this resizing to 0x0 prevents setting
2393 // normal size later so just ignore it.
2394 if (!size.IsEmpty())
2395 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322396}
2397
[email protected]3a3d47472010-07-15 21:03:542398void TabContents::NotifySwappedFromRenderManager() {
2399 NotifySwapped();
2400}
2401
[email protected]d202a7c2012-01-04 07:53:472402NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202403 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542404}
2405
[email protected]d2353452012-01-19 19:53:562406WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2407 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322408}
2409
[email protected]10f417c52011-12-28 21:04:232410NavigationEntry*
2411 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322412 return controller_.GetLastCommittedEntry();
2413}
2414
2415bool TabContents::CreateRenderViewForRenderManager(
2416 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442417 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322418 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522419
[email protected]420ae012009-04-24 05:16:322420 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442421 if (rwh_view)
2422 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322423
[email protected]74ce1ad2011-12-16 21:51:462424 // Make sure we use the correct starting page_id in the new RenderView.
2425 UpdateMaxPageIDIfNecessary(render_view_host);
2426 int32 max_page_id =
2427 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2428
2429 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522430 return false;
2431
[email protected]e60c0232011-11-11 19:56:352432#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502433 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2434 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442435 if (rwh_view) {
2436 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2437 render_widget_host->WasResized();
2438 }
[email protected]f8233cc2011-05-31 20:24:502439#endif
2440
[email protected]420ae012009-04-24 05:16:322441 return true;
2442}
2443
[email protected]fedec012012-01-28 03:09:342444void TabContents::OnDialogClosed(RenderViewHost* rvh,
2445 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072446 bool success,
2447 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542448 if (is_showing_before_unload_dialog_ && !success) {
2449 // If a beforeunload dialog is canceled, we need to stop the throbber from
2450 // spinning, since we forced it to start spinning in Navigate.
2451 DidStopLoading();
2452
2453 tab_close_start_time_ = base::TimeTicks();
2454 }
2455 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342456 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542457}
2458
[email protected]be1f56ab2011-12-22 06:55:312459void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122460 encoding_ = content::GetContentClient()->browser()->
2461 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102462}
[email protected]f45d2a72010-03-08 23:28:352463
[email protected]e30d68d2012-02-09 00:06:262464void TabContents::SaveURL(const GURL& url,
2465 const GURL& referrer,
2466 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142467 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2468 if (!dlm)
2469 return;
2470 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262471 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142472 const NavigationEntry* entry = controller_.GetActiveEntry();
2473 if (entry)
2474 post_id = entry->GetPostID();
2475 }
2476 DownloadSaveInfo save_info;
2477 save_info.prompt_for_save_location = true;
2478 dlm->DownloadUrl(url,
2479 referrer,
2480 "",
2481 true, // prefer_cache
2482 post_id,
2483 save_info,
2484 this);
2485}
2486
[email protected]33f74972010-12-08 16:40:362487void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212488 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442489 // Can be NULL during tests.
2490 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212491 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362492}