blob: 7f3e02cd795904a3d9b4001d808b15701969db68 [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]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5916#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4417#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4618#include "content/browser/download/download_stats.h"
[email protected]a53209b2012-01-20 16:48:1619#include "content/browser/download/save_package.h"
[email protected]64d69de42012-02-06 00:19:5420#include "content/browser/gpu/gpu_data_manager.h"
21#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0522#include "content/browser/host_zoom_map_impl.h"
[email protected]567812d2011-02-24 17:40:5023#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0024#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0125#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0426#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3027#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/render_view_host.h"
29#include "content/browser/renderer_host/render_widget_host_view.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]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4644#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1545#include "content/public/browser/javascript_dialogs.h"
[email protected]5b96836f2011-12-22 07:39:0046#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4847#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3848#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4249#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2550#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1051#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5052#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2153#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1855#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5456#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0357#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1658#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2959#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5460#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3461#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3863#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2464#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3165#include "webkit/glue/webpreferences.h"
66
67#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1268#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3169#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0070
[email protected]420ae012009-04-24 05:16:3271// Cross-Site Navigations
72//
73// If a TabContents is told to navigate to a different web site (as determined
74// by SiteInstance), it will replace its current RenderViewHost with a new
75// RenderViewHost dedicated to the new SiteInstance. This works as follows:
76//
77// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4678// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3279// - The pending RVH is "suspended," so that no navigation messages are sent to
80// its renderer until the onbeforeunload JavaScript handler has a chance to
81// run in the current RVH.
82// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
83// that it has a pending cross-site request. ResourceDispatcherHost will
84// check for this when the response arrives.
85// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4686// cancel all the pending logic. Otherwise we allow the pending RVH to send
87// the navigation request to its renderer.
88// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
89// main resource load on the pending RVH. It checks CrossSiteRequestManager
90// to see that it is a cross-site request, and installs a
91// CrossSiteResourceHandler.
92// - When RDH receives a response, the BufferedResourceHandler determines
93// whether it is a download. If so, it sends a message to the new renderer
94// causing it to cancel the request, and the download proceeds. For now, the
95// pending RVH remains until the next DidNavigate event for this TabContents.
96// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3297// - After RDH receives a response and determines that it is safe and not a
98// download, it pauses the response to first run the old page's onunload
99// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15100// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32101// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15102// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32103// the ResourceDispatcherHost, who unpauses the response. Data is then sent
104// to the pending RVH.
105// - The pending renderer sends a FrameNavigate message that invokes the
106// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46107// pending RVH.
[email protected]992db4c2011-05-12 15:37:15108// - The previous renderer is kept swapped out in RenderViewHostManager in case
109// the user goes back. The process only stays live if another tab is using
110// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32111
[email protected]0e12d7d2011-12-01 16:21:44112using content::DevToolsAgentHost;
113using content::DevToolsAgentHostRegistry;
114using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17115using content::DownloadItem;
116using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20117using content::GlobalRequestID;
[email protected]cadaec52012-02-08 21:53:13118using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50119using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23120using content::NavigationEntry;
121using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20122using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57123using content::RenderViewHostDelegate;
[email protected]b6583592012-01-25 19:52:33124using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17125using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38126using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09127using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25128using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56129using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22130using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50131using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44132
[email protected]420ae012009-04-24 05:16:32133namespace {
134
135// Amount of time we wait between when a key event is received and the renderer
136// is queried for its state and pushed to the NavigationEntry.
137const int kQueryStateDelay = 5000;
138
[email protected]6ebdc9b2010-09-27 16:55:57139const int kSyncWaitDelay = 40;
140
[email protected]ca406032011-07-19 21:53:05141static const char kDotGoogleDotCom[] = ".google.com";
142
[email protected]420ae012009-04-24 05:16:32143#if defined(OS_WIN)
144
145BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
146 // Note: erase is required to properly paint some widgets borders. This can
147 // be seen with textfields.
148 InvalidateRect(hwnd, NULL, TRUE);
149 return TRUE;
150}
151#endif
152
[email protected]2c5569662011-03-22 20:45:02153ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23154 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50155 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16156 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47157 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02158 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47159 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02160 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47161 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16162 break; // Fall through to rest of function.
163 }
[email protected]5e369672009-11-03 23:48:30164
[email protected]59246c572012-02-10 13:32:13165 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
166 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23167 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13168 browser_context->DidLastSessionExitCleanly()) {
169 if (entry.GetHasPostData())
170 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02171 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13172 }
[email protected]5e369672009-11-03 23:48:30173
[email protected]2c5569662011-03-22 20:45:02174 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30175}
176
[email protected]10f417c52011-12-28 21:04:23177void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47178 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42179 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50180 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16181 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51182 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54183 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55184 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
185 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51186 params->url = entry.GetURL();
187 params->referrer = entry.GetReferrer();
188 params->transition = entry.GetTransitionType();
189 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00190 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55191 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34192 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47193 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48194 params->transferred_request_child_id =
195 entry.transferred_global_request_id().child_id;
196 params->transferred_request_request_id =
197 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47198
199 if (delegate)
200 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34201}
202
[email protected]420ae012009-04-24 05:16:32203} // namespace
204
[email protected]a81343d232011-12-27 07:39:20205namespace content {
206
207WebContents* WebContents::Create(
208 BrowserContext* browser_context,
209 SiteInstance* site_instance,
210 int routing_id,
211 const WebContents* base_tab_contents,
212 SessionStorageNamespace* session_storage_namespace) {
213 return new TabContents(browser_context,
214 site_instance,
215 routing_id,
216 static_cast<const TabContents*>(base_tab_contents),
217 session_storage_namespace);
218}
219}
[email protected]f4f50ef2011-01-21 19:01:19220
221// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32222
[email protected]3d7474ff2011-07-27 17:47:37223TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32224 SiteInstance* site_instance,
225 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07226 const TabContents* base_tab_contents,
227 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42228 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07229 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37230 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13231 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10232 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22233 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34234 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23235 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
236 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34237 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21238 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56239 upload_size_(0),
240 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47241 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57242 capturing_contents_(false),
243 is_being_destroyed_(false),
244 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55245 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57246#if defined(OS_WIN)
247 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
248#endif
[email protected]7ab1e7d62009-10-14 23:32:01249 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56250 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38251 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25252 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01253 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25254 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01255 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00256 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43257 content_restrictions_(0),
258 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37259 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32260
[email protected]34ac70502009-09-25 17:07:23261 // We have the initial size of the view be based on the size of the passed in
262 // tab contents (normally a tab from the same window).
263 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21264 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00265
266#if defined(ENABLE_JAVA_BRIDGE)
267 java_bridge_dispatcher_host_manager_.reset(
268 new JavaBridgeDispatcherHostManager(this));
269#endif
[email protected]332af7732009-03-11 13:21:35270}
initial.commit09911bf2008-07-26 23:55:29271
272TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32273 is_being_destroyed_ = true;
274
[email protected]3ab9cb82011-06-03 18:02:07275 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55276 if (dialog_creator_)
277 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07278
[email protected]420ae012009-04-24 05:16:32279 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32280
[email protected]420ae012009-04-24 05:16:32281 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07282 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09283 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
284 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07285 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32286
287 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07288#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32289 // If we still have a window handle, destroy it. GetNativeView can return
290 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42291 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52292 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44293 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42294 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42295 }
[email protected]420ae012009-04-24 05:16:32296#endif
[email protected]7ab1e7d62009-10-14 23:32:01297
298 // OnCloseStarted isn't called in unit tests.
299 if (!tab_close_start_time_.is_null()) {
300 UMA_HISTOGRAM_TIMES("Tab.Close",
301 base::TimeTicks::Now() - tab_close_start_time_);
302 }
[email protected]b5a1d11c2011-02-17 03:09:42303
[email protected]d8c660432011-12-22 20:51:25304 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08305
[email protected]6934a702011-12-20 00:04:51306 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42307}
308
[email protected]64d69de42012-02-06 00:19:54309WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
310 const GURL& url) {
311 WebPreferences prefs;
312
313 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
314
315 prefs.developer_extras_enabled = true;
316 prefs.javascript_enabled =
317 !command_line.HasSwitch(switches::kDisableJavaScript);
318 prefs.web_security_enabled =
319 !command_line.HasSwitch(switches::kDisableWebSecurity);
320 prefs.plugins_enabled =
321 !command_line.HasSwitch(switches::kDisablePlugins);
322 prefs.java_enabled =
323 !command_line.HasSwitch(switches::kDisableJava);
324
325 prefs.uses_page_cache =
326 command_line.HasSwitch(switches::kEnableFastback);
327 prefs.remote_fonts_enabled =
328 !command_line.HasSwitch(switches::kDisableRemoteFonts);
329 prefs.xss_auditor_enabled =
330 !command_line.HasSwitch(switches::kDisableXSSAuditor);
331 prefs.application_cache_enabled =
332 !command_line.HasSwitch(switches::kDisableApplicationCache);
333
334 prefs.local_storage_enabled =
335 !command_line.HasSwitch(switches::kDisableLocalStorage);
336 prefs.databases_enabled =
337 !command_line.HasSwitch(switches::kDisableDatabases);
338 prefs.webaudio_enabled =
339 !command_line.HasSwitch(switches::kDisableWebAudio);
340
341 prefs.experimental_webgl_enabled =
342 GpuProcessHost::gpu_enabled() &&
343 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
344 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
345
346 prefs.gl_multisampling_enabled =
347 !command_line.HasSwitch(switches::kDisableGLMultisampling);
348 prefs.privileged_webgl_extensions_enabled =
349 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
350 prefs.site_specific_quirks_enabled =
351 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
352 prefs.allow_file_access_from_file_urls =
353 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
354 prefs.show_composited_layer_borders =
355 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
356 prefs.show_composited_layer_tree =
357 command_line.HasSwitch(switches::kShowCompositedLayerTree);
358 prefs.show_fps_counter =
359 command_line.HasSwitch(switches::kShowFPSCounter);
360 prefs.accelerated_compositing_enabled =
361 GpuProcessHost::gpu_enabled() &&
362 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
363 prefs.threaded_compositing_enabled =
364 command_line.HasSwitch(switches::kEnableThreadedCompositing);
365 prefs.force_compositing_mode =
366 command_line.HasSwitch(switches::kForceCompositingMode);
367 prefs.fixed_position_compositing_enabled =
368 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
369 prefs.accelerated_2d_canvas_enabled =
370 GpuProcessHost::gpu_enabled() &&
371 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58372 prefs.deferred_2d_canvas_enabled =
373 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54374 prefs.accelerated_painting_enabled =
375 GpuProcessHost::gpu_enabled() &&
376 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
377 prefs.accelerated_filters_enabled =
378 GpuProcessHost::gpu_enabled() &&
379 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
380 prefs.accelerated_layers_enabled =
381 prefs.accelerated_animation_enabled =
382 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
383 prefs.composite_to_texture_enabled =
384 command_line.HasSwitch(switches::kEnableCompositeToTexture);
385 prefs.accelerated_plugins_enabled =
386 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
387 prefs.accelerated_video_enabled =
388 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
389 prefs.partial_swap_enabled =
390 command_line.HasSwitch(switches::kEnablePartialSwap);
391 prefs.interactive_form_validation_enabled =
392 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
393 prefs.fullscreen_enabled =
394 !command_line.HasSwitch(switches::kDisableFullScreen);
395
396#if defined(OS_MACOSX)
397 bool default_enable_scroll_animator = true;
398#else
399 // On CrOS, the launcher always passes in the --enable flag.
400 bool default_enable_scroll_animator = false;
401#endif
402 prefs.enable_scroll_animator = default_enable_scroll_animator;
403 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
404 prefs.enable_scroll_animator = true;
405 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
406 prefs.enable_scroll_animator = false;
407
408 prefs.visual_word_movement_enabled =
409 command_line.HasSwitch(switches::kEnableVisualWordMovement);
410 prefs.per_tile_painting_enabled =
411 command_line.HasSwitch(switches::kEnablePerTilePainting);
412
413 { // Certain GPU features might have been blacklisted.
414 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
415 DCHECK(gpu_data_manager);
416 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
417 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
418 prefs.accelerated_compositing_enabled = false;
419 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
420 prefs.experimental_webgl_enabled = false;
421 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
422 prefs.accelerated_2d_canvas_enabled = false;
423 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
424 prefs.gl_multisampling_enabled = false;
425
426 // Accelerated video and animation are slower than regular when using a
427 // software 3d rasterizer.
428 if (gpu_data_manager->software_rendering()) {
429 prefs.accelerated_video_enabled = false;
430 prefs.accelerated_animation_enabled = false;
431 }
432 }
433
[email protected]b9535422012-02-09 01:47:59434 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54435 rvh->process()->GetID())) {
436 prefs.loads_images_automatically = true;
437 prefs.javascript_enabled = true;
438 }
439
440 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
441
442 // Force accelerated compositing and 2d canvas off for chrome:, about: and
443 // chrome-devtools: pages (unless it's specifically allowed).
444 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
445 // Allow accelerated compositing for keyboard and log in screen.
446 url.SchemeIs(chrome::kChromeUIScheme) ||
447 (url.SchemeIs(chrome::kAboutScheme) &&
448 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25449 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54450 prefs.accelerated_compositing_enabled = false;
451 prefs.accelerated_2d_canvas_enabled = false;
452 }
453
454 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
455
456 return prefs;
457}
458
[email protected]d202a7c2012-01-04 07:53:47459NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20460 return controller_;
461}
462
[email protected]765187182012-01-11 23:59:28463RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
464 return &render_manager_;
465}
466
[email protected]724159a2010-12-30 01:11:18467bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56468 if (GetWebUI() &&
469 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17470 return true;
[email protected]d2353452012-01-19 19:53:56471 }
[email protected]f82d57b52011-04-27 19:13:17472
[email protected]d8c660432011-12-22 20:51:25473 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
474 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10475 while ((observer = it.GetNext()) != NULL)
476 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53477 return true;
[email protected]403415a2011-01-10 18:57:53478
[email protected]724159a2010-12-30 01:11:18479 bool handled = true;
480 bool message_is_ok = true;
481 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58482 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
483 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24484 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
485 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18486 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
487 OnDidStartProvisionalLoadForFrame)
488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
489 OnDidRedirectProvisionalLoad)
490 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
491 OnDidFailProvisionalLoadWithError)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
493 OnDidLoadResourceFromMemoryCache)
494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
495 OnDidDisplayInsecureContent)
496 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
497 OnDidRunInsecureContent)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
499 OnDocumentLoadedInFrame)
500 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17501 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
502 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25503 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26504 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59505 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21506 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20507 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
508 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
509 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16510 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45511 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10512 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18513 IPC_MESSAGE_UNHANDLED(handled = false)
514 IPC_END_MESSAGE_MAP_EX()
515
516 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38517 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18518 GetRenderProcessHost()->ReceivedBadMessage();
519 }
520
521 return handled;
522}
523
[email protected]6c2e472f2011-08-24 23:26:18524void TabContents::RunFileChooser(
525 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23526 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51527 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18528}
529
[email protected]c5eed492012-01-04 17:07:50530NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56531 return controller_;
532}
533
[email protected]c5eed492012-01-04 17:07:50534const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56535 return controller_;
536}
537
[email protected]627e0512011-12-21 22:55:30538content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55539 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30540}
541
[email protected]f5fa20e2011-12-21 22:35:56542void TabContents::SetViewType(content::ViewType type) {
543 view_type_ = type;
544}
545
[email protected]ea049a02011-12-25 21:37:09546content::ViewType TabContents::GetViewType() const {
547 return view_type_;
548}
549
[email protected]be1f56ab2011-12-22 06:55:31550const GURL& TabContents::GetURL() const {
551 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23552 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51553 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31554}
555
556
557const base::PropertyBag* TabContents::GetPropertyBag() const {
558 return &property_bag_;
559}
560
561base::PropertyBag* TabContents::GetPropertyBag() {
562 return &property_bag_;
563}
564
565content::WebContentsDelegate* TabContents::GetDelegate() {
566 return delegate_;
567}
568
569void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
570 // TODO(cbentzel): remove this debugging code?
571 if (delegate == delegate_)
572 return;
573 if (delegate_)
574 delegate_->Detach(this);
575 delegate_ = delegate;
576 if (delegate_)
577 delegate_->Attach(this);
578}
579
[email protected]f3b1a082011-11-18 00:34:30580content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03581 if (render_manager_.current_host())
582 return render_manager_.current_host()->process();
583 else
584 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16585}
586
[email protected]be1f56ab2011-12-22 06:55:31587RenderViewHost* TabContents::GetRenderViewHost() const {
588 return render_manager_.current_host();
589}
590
591RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
592 return render_manager_.GetRenderWidgetHostView();
593}
594
[email protected]8643e6d2012-01-18 20:26:10595content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31596 return view_.get();
597}
598
[email protected]01ec4ec2012-01-18 04:13:47599content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50600 WebUIControllerFactory* factory =
601 content::GetContentClient()->browser()->GetWebUIControllerFactory();
602 if (!factory)
603 return NULL;
[email protected]d2353452012-01-19 19:53:56604 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22605 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50606 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22607 if (controller) {
608 web_ui->SetController(controller);
609 return web_ui;
610 }
611
612 delete web_ui;
613 return NULL;
614}
615
[email protected]01ec4ec2012-01-18 04:13:47616content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31617 return render_manager_.web_ui() ? render_manager_.web_ui()
618 : render_manager_.pending_web_ui();
619}
620
[email protected]01ec4ec2012-01-18 04:13:47621content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31622 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34623}
624
[email protected]96d185d2009-04-24 03:28:54625const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55626 // Transient entries take precedence. They are used for interstitial pages
627 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23628 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08629 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20630 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30631 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23632 if (entry) {
[email protected]b5cca982011-05-26 04:42:08633 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23634 }
[email protected]7ade2732011-02-10 00:13:58635 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
636 render_manager_.pending_web_ui() : render_manager_.web_ui();
637 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54638 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55639 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54640 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35641 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22642 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54643 if (!title.empty())
644 return title;
645 }
646 }
647
648 // We use the title for the last committed entry rather than a pending
649 // navigation entry. For example, when the user types in a URL, we want to
650 // keep the old page's title until the new load has committed and we get a new
651 // title.
[email protected]96d185d2009-04-24 03:28:54652 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23653 if (entry) {
[email protected]b5cca982011-05-26 04:42:08654 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23655 }
[email protected]987fc3a2011-05-26 14:18:09656
657 // |page_title_when_no_navigation_entry_| is finally used
658 // if no title cannot be retrieved.
659 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54660}
661
[email protected]d5f942ba2008-09-26 19:30:34662int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46663 return GetMaxPageIDForSiteInstance(GetSiteInstance());
664}
665
666int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33667 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
668 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46669
[email protected]b6583592012-01-25 19:52:33670 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34671}
672
673void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46674 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
675}
676
[email protected]b6583592012-01-25 19:52:33677void TabContents::UpdateMaxPageIDForSiteInstance(
678 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46679 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33680 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34681}
682
[email protected]91854cd2012-01-10 19:43:57683void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
684 max_page_ids_ = tab_contents->max_page_ids_;
685}
686
[email protected]96d185d2009-04-24 03:28:54687SiteInstance* TabContents::GetSiteInstance() const {
688 return render_manager_.current_host()->site_instance();
689}
690
[email protected]77362eb2011-08-01 17:18:38691SiteInstance* TabContents::GetPendingSiteInstance() const {
692 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
693 render_manager_.pending_render_view_host() :
694 render_manager_.current_host();
695 return dest_rvh->site_instance();
696}
697
[email protected]be1f56ab2011-12-22 06:55:31698bool TabContents::IsLoading() const {
699 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49700}
701
[email protected]be1f56ab2011-12-22 06:55:31702bool TabContents::IsWaitingForResponse() const {
703 return waiting_for_response_;
704}
705
706const net::LoadStateWithParam& TabContents::GetLoadState() const {
707 return load_state_;
708}
709
710const string16& TabContents::GetLoadStateHost() const {
711 return load_state_host_;
712}
713
714uint64 TabContents::GetUploadSize() const {
715 return upload_size_;
716}
717
718uint64 TabContents::GetUploadPosition() const {
719 return upload_position_;
720}
721
722const std::string& TabContents::GetEncoding() const {
723 return encoding_;
724}
725
726bool TabContents::DisplayedInsecureContent() const {
727 return displayed_insecure_content_;
728}
729
730void TabContents::SetCapturingContents(bool cap) {
731 capturing_contents_ = cap;
732}
733
734bool TabContents::IsCrashed() const {
735 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
736 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
737 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49738}
739
[email protected]443b80e2010-12-14 00:42:23740void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
741 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34742 return;
743
[email protected]443b80e2010-12-14 00:42:23744 crashed_status_ = status;
745 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46746 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34747}
748
[email protected]be1f56ab2011-12-22 06:55:31749base::TerminationStatus TabContents::GetCrashedStatus() const {
750 return crashed_status_;
751}
752
753bool TabContents::IsBeingDestroyed() const {
754 return is_being_destroyed_;
755}
756
[email protected]d5f942ba2008-09-26 19:30:34757void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
758 if (delegate_)
759 delegate_->NavigationStateChanged(this, changed_flags);
760}
761
[email protected]96d185d2009-04-24 03:28:54762void TabContents::DidBecomeSelected() {
763 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16764 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
765 if (rwhv) {
766 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43767#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16768 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43769#endif
770 }
[email protected]96d185d2009-04-24 03:28:54771
[email protected]5ac20162010-11-24 23:33:11772 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38773
[email protected]d8c660432011-12-22 20:51:25774 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59775
776 // The resize rect might have changed while this was inactive -- send the new
777 // one to make sure it's up to date.
778 RenderViewHost* rvh = GetRenderViewHost();
779 if (rvh) {
780 rvh->ResizeRectChanged(GetRootWindowResizerRect());
781 }
[email protected]96d185d2009-04-24 03:28:54782}
783
[email protected]be1f56ab2011-12-22 06:55:31784
785base::TimeTicks TabContents::GetLastSelectedTime() const {
786 return last_selected_time_;
787}
788
[email protected]96d185d2009-04-24 03:28:54789void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31790 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52791 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
792 // open a tab in then background, then closes the tab before selecting it.
793 // This is because closing the tab calls TabContents::Destroy(), which
794 // removes the |GetRenderViewHost()|; then when we actually destroy the
795 // window, OnWindowPosChanged() notices and calls HideContents() (which
796 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16797 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
798 if (rwhv)
799 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54800 }
801
[email protected]ad50def52011-10-19 23:17:07802 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09803 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
804 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07805 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54806}
807
[email protected]be1f56ab2011-12-22 06:55:31808void TabContents::ShowContents() {
809 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
810 if (rwhv)
811 rwhv->DidBecomeSelected();
812}
813
814void TabContents::HideContents() {
815 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
816 // our superclass HideContents(), because some callers want to be very picky
817 // about the order in which these get called. In addition to making the code
818 // here practically impossible to understand, this also means we end up
819 // calling TabContents::WasHidden() twice if callers call both versions of
820 // HideContents() on a TabContents.
821 WasHidden();
822}
823
824bool TabContents::NeedToFireBeforeUnload() {
825 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27826 return WillNotifyDisconnection() &&
827 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31828 !GetRenderViewHost()->SuddenTerminationAllowed();
829}
830
[email protected]0bfbf882011-12-22 18:19:27831void TabContents::Stop() {
832 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25833 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27834}
835
[email protected]d9083482012-01-06 00:38:46836WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27837 // We create a new SiteInstance so that the new tab won't share processes
838 // with the old one. This can be changed in the future if we need it to share
839 // processes for some reason.
840 TabContents* tc = new TabContents(
841 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33842 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27843 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20844 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27845 return tc;
846}
847
848void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17849 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27850 bool show_history) {
851 if (!delegate_)
852 return;
853
854 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
855}
856
[email protected]2a6bc3e2011-12-28 23:51:33857void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27858 WindowOpenDisposition disposition,
859 const gfx::Rect& initial_pos,
860 bool user_gesture) {
861 if (!delegate_)
862 return;
863
864 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
865 user_gesture);
866}
867
868gfx::NativeView TabContents::GetContentNativeView() const {
869 return view_->GetContentNativeView();
870}
871
872gfx::NativeView TabContents::GetNativeView() const {
873 return view_->GetNativeView();
874}
875
876void TabContents::GetContainerBounds(gfx::Rect* out) const {
877 view_->GetContainerBounds(out);
878}
879
880void TabContents::Focus() {
881 view_->Focus();
882}
883
[email protected]d8c660432011-12-22 20:51:25884void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31885 observers_.AddObserver(observer);
886}
887
[email protected]d8c660432011-12-22 20:51:25888void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31889 observers_.RemoveObserver(observer);
890}
891
[email protected]d5f942ba2008-09-26 19:30:34892void TabContents::Activate() {
893 if (delegate_)
894 delegate_->ActivateContents(this);
895}
896
[email protected]ea42e7782010-08-23 23:58:12897void TabContents::Deactivate() {
898 if (delegate_)
899 delegate_->DeactivateContents(this);
900}
901
[email protected]63954792011-07-11 04:17:48902void TabContents::LostCapture() {
903 if (delegate_)
904 delegate_->LostCapture();
905}
906
907bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
908 bool* is_keyboard_shortcut) {
909 return delegate_ &&
910 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
911}
912
913void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
914 if (delegate_)
915 delegate_->HandleKeyboardEvent(event);
916}
917
[email protected]32ded2212011-11-10 18:51:43918void TabContents::HandleMouseDown() {
919 if (delegate_)
920 delegate_->HandleMouseDown();
921}
922
[email protected]63954792011-07-11 04:17:48923void TabContents::HandleMouseUp() {
924 if (delegate_)
925 delegate_->HandleMouseUp();
926}
927
928void TabContents::HandleMouseActivate() {
929 if (delegate_)
930 delegate_->HandleMouseActivate();
931}
932
[email protected]8a5e0ca2011-08-25 06:30:47933void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
934 if (delegate_)
935 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
936}
937
[email protected]5d5f7af2011-10-01 01:38:12938bool TabContents::IsFullscreenForCurrentTab() const {
939 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
940}
941
[email protected]e9621112011-10-17 05:38:37942void TabContents::RequestToLockMouse() {
943 if (delegate_) {
944 delegate_->RequestToLockMouse(this);
945 } else {
946 GotResponseToLockMouseRequest(false);
947 }
948}
949
950void TabContents::LostMouseLock() {
951 if (delegate_)
952 delegate_->LostMouseLock();
953}
954
[email protected]0548c5352011-09-07 00:33:33955void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23956 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33957 if (delegate_)
958 delegate_->UpdatePreferredSize(this, pref_size);
959}
960
[email protected]32ded2212011-11-10 18:51:43961void TabContents::WebUISend(RenderViewHost* render_view_host,
962 const GURL& source_url,
963 const std::string& name,
964 const base::ListValue& args) {
965 if (delegate_)
966 delegate_->WebUISend(this, source_url, name, args);
967}
968
[email protected]e5d549d2011-12-28 01:29:20969WebContents* TabContents::OpenURL(const OpenURLParams& params) {
970 if (!delegate_)
971 return NULL;
[email protected]00c37fc2011-08-02 00:22:50972
[email protected]e5d549d2011-12-28 01:29:20973 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
974 // Notify observers.
975 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
976 DidOpenURL(params.url, params.referrer,
977 params.disposition, params.transition));
978 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34979}
980
[email protected]1ccb3568d2010-02-19 10:51:16981bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50982 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25983 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23984 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25985 reload_type);
[email protected]876bc832010-09-07 16:29:54986}
[email protected]96d185d2009-04-24 03:28:54987
[email protected]876bc832010-09-07 16:29:54988bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23989 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50990 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40991 // The renderer will reject IPC messages with URLs longer than
992 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51993 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40994 return false;
995
[email protected]dd11de52011-11-03 22:54:27996 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40997 if (!dest_render_view_host)
998 return false; // Unable to create the desired render view host.
999
[email protected]80a8fad2011-01-29 04:02:381000 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071001 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581002 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501003 WebUIControllerFactory* factory =
1004 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1005 bool is_allowed_in_web_ui_renderer =
1006 factory &&
1007 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431008#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511009 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431010#endif
[email protected]e091df82011-10-11 18:13:211011 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551012 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581013
[email protected]96d185d2009-04-24 03:28:541014 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441015 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521016 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441017 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511018 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541019
1020 // Used for page load time metrics.
1021 current_load_start_ = base::TimeTicks::Now();
1022
1023 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341024 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271025 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471026 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341027 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541028
[email protected]36fc0392011-12-25 03:59:511029 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541030 // HACK!! This code suppresses javascript: URLs from being added to
1031 // session history, which is what we want to do for javascript: URLs that
1032 // do not generate content. What we really need is a message from the
1033 // renderer telling us that a new page was not created. The same message
1034 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511035 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541036 return false;
1037 }
1038
[email protected]3c9e1872010-11-18 16:17:491039 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251040 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041041 observers_,
[email protected]36fc0392011-12-25 03:59:511042 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541043
[email protected]09b29342011-06-24 19:18:481044 if (delegate_)
1045 delegate_->DidNavigateToPendingEntry(this);
1046
[email protected]d5f942ba2008-09-26 19:30:341047 return true;
1048}
1049
[email protected]b6583592012-01-25 19:52:331050void TabContents::SetHistoryLengthAndPrune(
1051 const SiteInstance* site_instance,
1052 int history_length,
1053 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411054 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1055 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191056 if (render_manager_.pending_render_view_host()) {
1057 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141058 return;
[email protected]9e1ad4b2011-08-14 16:49:191059 }
[email protected]151a63d2011-12-20 22:32:521060 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191061 if (!rvh) {
1062 NOTREACHED();
1063 return;
1064 }
1065 if (site_instance && rvh->site_instance() != site_instance) {
1066 NOTREACHED();
1067 return;
1068 }
1069 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1070 history_length,
1071 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141072}
1073
[email protected]90daadb42009-06-08 21:27:281074void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271075 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541076 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1077 return;
1078 }
[email protected]151a63d2011-12-20 22:32:521079 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541080}
1081
[email protected]0bfbf882011-12-22 18:19:271082bool TabContents::ShowingInterstitialPage() const {
1083 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541084}
1085
[email protected]0bfbf882011-12-22 18:19:271086InterstitialPage* TabContents::GetInterstitialPage() const {
1087 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221088}
1089
[email protected]a53209b2012-01-20 16:48:161090bool TabContents::IsSavable() {
1091 // WebKit creates Document object when MIME type is application/xhtml+xml,
1092 // so we also support this MIME type.
1093 return contents_mime_type_ == "text/html" ||
1094 contents_mime_type_ == "text/xml" ||
1095 contents_mime_type_ == "application/xhtml+xml" ||
1096 contents_mime_type_ == "text/plain" ||
1097 contents_mime_type_ == "text/css" ||
1098 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1099}
1100
[email protected]c7dd2f62011-07-18 15:57:591101void TabContents::OnSavePage() {
1102 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161103 if (!IsSavable()) {
[email protected]e30d68d2012-02-09 00:06:261104 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141105 download_stats::RecordDownloadCount(
1106 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
1107 return;
[email protected]c7dd2f62011-07-18 15:57:591108 }
1109
1110 Stop();
1111
1112 // Create the save package and possibly prompt the user for the name to save
1113 // the page as. The user prompt is an asynchronous operation that runs on
1114 // another thread.
1115 save_package_ = new SavePackage(this);
1116 save_package_->GetSaveInfo();
1117}
1118
1119// Used in automated testing to bypass prompting the user for file names.
1120// Instead, the names and paths are hard coded rather than running them through
1121// file name sanitation and extension / mime checking.
1122bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161123 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591124 // Stop the page from navigating.
1125 Stop();
1126
1127 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1128 return save_package_->Init();
1129}
1130
[email protected]420ae012009-04-24 05:16:321131bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231132 NavigationEntryImpl* active_entry =
1133 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321134 return (active_entry != NULL &&
1135 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511136 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321137}
1138
[email protected]0bfbf882011-12-22 18:19:271139const std::string& TabContents::GetContentsMimeType() const {
1140 return contents_mime_type_;
1141}
1142
1143bool TabContents::WillNotifyDisconnection() const {
1144 return notify_disconnection_;
1145}
1146
[email protected]b2fe07d12010-02-09 14:38:081147void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311148 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521149 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1150 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161151}
1152
[email protected]b2fe07d12010-02-09 14:38:081153void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311154 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521155 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1156 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161157}
1158
[email protected]0bfbf882011-12-22 18:19:271159content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1160 return &renderer_preferences_;
1161}
1162
1163void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1164 new_tab_start_time_ = time;
1165}
1166
1167base::TimeTicks TabContents::GetNewTabStartTime() const {
1168 return new_tab_start_time_;
1169}
1170
[email protected]7ab1e7d62009-10-14 23:32:011171void TabContents::OnCloseStarted() {
1172 if (tab_close_start_time_.is_null())
1173 tab_close_start_time_ = base::TimeTicks::Now();
1174}
1175
[email protected]46624bf2010-06-09 16:04:191176bool TabContents::ShouldAcceptDragAndDrop() const {
1177#if defined(OS_CHROMEOS)
1178 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1179 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511180 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201181 return false;
1182 return true;
[email protected]46624bf2010-06-09 16:04:191183#else
1184 return true;
1185#endif
1186}
1187
[email protected]7813bd72011-02-05 02:19:341188void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521189 if (GetRenderViewHost())
1190 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511191 if (delegate_)
1192 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341193}
1194
[email protected]0bfbf882011-12-22 18:19:271195void TabContents::SetClosedByUserGesture(bool value) {
1196 closed_by_user_gesture_ = value;
1197}
1198
1199bool TabContents::GetClosedByUserGesture() const {
1200 return closed_by_user_gesture_;
1201}
1202
[email protected]d0b8d092010-10-25 04:05:171203double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051204 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
1205 GetBrowserContext()->GetHostZoomMap());
[email protected]b75b8292010-10-01 07:28:251206 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171207 return 0;
[email protected]b75b8292010-10-01 07:28:251208
1209 double zoom_level;
1210 if (temporary_zoom_settings_) {
1211 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521212 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251213 } else {
[email protected]2ae88d12011-10-14 09:11:191214 GURL url;
[email protected]10f417c52011-12-28 21:04:231215 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191216 // Since zoom map is updated using rewritten URL, use rewritten URL
1217 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511218 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191219 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251220 }
[email protected]d0b8d092010-10-25 04:05:171221 return zoom_level;
1222}
[email protected]b75b8292010-10-01 07:28:251223
[email protected]d0b8d092010-10-25 04:05:171224int TabContents::GetZoomPercent(bool* enable_increment,
1225 bool* enable_decrement) {
1226 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011227 // Calculate the zoom percent from the factor. Round up to the nearest whole
1228 // number.
[email protected]b75b8292010-10-01 07:28:251229 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011230 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251231 *enable_decrement = percent > minimum_zoom_percent_;
1232 *enable_increment = percent < maximum_zoom_percent_;
1233 return percent;
1234}
1235
[email protected]3c733bde2010-12-21 19:56:311236void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501237 if (!delegate_)
1238 return;
1239
[email protected]10f417c52011-12-28 21:04:231240 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501241 if (!active_entry)
1242 return;
1243
[email protected]36fc0392011-12-25 03:59:511244 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121245}
1246
[email protected]932b7a12011-03-09 12:50:271247void TabContents::ViewFrameSource(const GURL& url,
1248 const std::string& content_state) {
1249 if (!delegate_)
1250 return;
1251
1252 delegate_->ViewSourceForFrame(this, url, content_state);
1253}
1254
[email protected]0bfbf882011-12-22 18:19:271255int TabContents::GetMinimumZoomPercent() const {
1256 return minimum_zoom_percent_;
1257}
1258
1259int TabContents::GetMaximumZoomPercent() const {
1260 return maximum_zoom_percent_;
1261}
1262
[email protected]bcd2815602012-01-14 18:17:231263gfx::Size TabContents::GetPreferredSize() const {
1264 return preferred_size_;
1265}
1266
[email protected]0bfbf882011-12-22 18:19:271267int TabContents::GetContentRestrictions() const {
1268 return content_restrictions_;
1269}
1270
1271WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501272 WebUIControllerFactory* factory =
1273 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1274 if (!factory)
1275 return WebUI::kNoWebUI;
1276 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271277}
1278
[email protected]01ec4ec2012-01-18 04:13:471279content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271280 // When there is a pending navigation entry, we want to use the pending WebUI
1281 // that goes along with it to control the basic flags. For example, we want to
1282 // show the pending URL in the URL bar, so we want the display_url flag to
1283 // be from the pending entry.
1284 //
1285 // The confusion comes because there are multiple possibilities for the
1286 // initial load in a tab as a side effect of the way the RenderViewHostManager
1287 // works.
1288 //
1289 // - For the very first tab the load looks "normal". The new tab Web UI is
1290 // the pending one, and we want it to apply here.
1291 //
1292 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1293 // get switched to the one previously associated with the new tab pages.
1294 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1295 // have a committed Web UI in this case.
1296 //
1297 // This condition handles all of these cases:
1298 //
1299 // - First load in first tab: no committed nav entry + pending nav entry +
1300 // pending dom ui:
1301 // -> Use pending Web UI if any.
1302 //
1303 // - First load in second tab: no committed nav entry + pending nav entry +
1304 // no pending Web UI:
1305 // -> Use the committed Web UI if any.
1306 //
1307 // - Second navigation in any tab: committed nav entry + pending nav entry:
1308 // -> Use pending Web UI if any.
1309 //
1310 // - Normal state with no load: committed nav entry + no pending nav entry:
1311 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251312 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271313 (controller_.GetLastCommittedEntry() ||
1314 render_manager_.pending_web_ui()))
1315 return render_manager_.pending_web_ui();
1316 return render_manager_.web_ui();
1317}
1318
1319bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1320 return GetRenderViewHost() ?
1321 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1322}
1323
1324bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471325 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271326 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221327 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231328 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511329 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271330 return true;
1331 return false;
1332}
1333
1334void TabContents::SetFocusToLocationBar(bool select_all) {
1335 if (delegate_)
1336 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211337}
1338
[email protected]8b5af492011-11-28 21:50:581339void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301340 const string16& type,
1341 const string16& href,
1342 const string16& title,
1343 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511344 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301345 this, action, type, href, title, disposition);
1346}
1347
[email protected]678105012011-12-09 04:01:211348void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301349 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001350 WebIntentsDispatcherImpl* intents_dispatcher =
1351 new WebIntentsDispatcherImpl(this, intent, intent_id);
1352 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301353}
1354
[email protected]724159a2010-12-30 01:11:181355void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1356 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591357 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181358 const GURL& url) {
1359 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1360 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591361 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301362 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181363
[email protected]8093a542011-05-13 07:29:321364 RenderViewHost* rvh =
1365 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521366 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101367 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251368 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101369 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321370 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101371
[email protected]724159a2010-12-30 01:11:181372 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591373 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251374 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591375 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181376 }
1377}
1378
1379void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591380 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181381 const GURL& source_url,
1382 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491383 // TODO(creis): Remove this method and have the pre-rendering code listen to
1384 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1385 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231386 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181387 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251388 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181389 else
1390 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511391 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181392 return;
[email protected]e7d50892011-01-19 21:47:381393
[email protected]4850a7f2011-03-08 23:36:591394 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251395 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261396 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591397 opener_url));
[email protected]724159a2010-12-30 01:11:181398}
1399
1400void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581401 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1402 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1403 << ", error_code: " << params.error_code
1404 << ", error_description: " << params.error_description
1405 << ", is_main_frame: " << params.is_main_frame
1406 << ", showing_repost_interstitial: " <<
1407 params.showing_repost_interstitial
1408 << ", frame_id: " << params.frame_id;
1409 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591410 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301411 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181412
[email protected]d7b175e2011-10-11 15:31:581413 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181414 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1415 // This means that the interstitial won't be torn down properly, which is
1416 // bad. But if we have an interstitial, go back to another tab type, and
1417 // then load the same interstitial again, we could end up getting the first
1418 // interstitial's "failed" message (as a result of the cancel) when we're on
1419 // the second one.
1420 //
1421 // We can't tell this apart, so we think we're tearing down the current page
1422 // which will cause a crash later one. There is also some code in
1423 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1424 // out because of this problem.
1425 //
1426 // http://code.google.com/p/chromium/issues/detail?id=2855
1427 // Because this will not tear down the interstitial properly, if "back" is
1428 // back to another tab type, the interstitial will still be somewhat alive
1429 // in the previous tab type. If you navigate somewhere that activates the
1430 // tab with the interstitial again, you'll see a flash before the new load
1431 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271432 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181433 LOG(WARNING) << "Discarding message during interstitial.";
1434 return;
1435 }
1436
[email protected]02102f82011-06-13 20:37:021437 // Discard our pending entry if the load canceled (e.g. if we decided to
1438 // download the file instead of load it). We do not verify that the URL
1439 // being canceled matches the pending entry's URL because they will not
1440 // match if a redirect occurred (in which case we do not want to leave a
1441 // stale redirect URL showing). This means that we also cancel the pending
1442 // entry if the user started a new navigation. As a result, the navigation
1443 // controller may not remember that a load is in progress, but the
1444 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251445 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161446 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181447
[email protected]151a63d2011-12-20 22:32:521448 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181449 }
1450
1451 // Send out a notification that we failed a provisional load with an error.
1452 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581453 params.is_main_frame,
1454 controller_.IsURLInPageNavigation(validated_url),
1455 validated_url,
1456 std::string(),
1457 false,
1458 params.frame_id);
1459 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181460
[email protected]ad50def52011-10-19 23:17:071461 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271462 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501463 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531464 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101465
[email protected]d8c660432011-12-22 20:51:251466 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581467 observers_,
1468 DidFailProvisionalLoad(params.frame_id,
1469 params.is_main_frame,
1470 validated_url,
1471 params.error_code,
1472 params.error_description));
[email protected]724159a2010-12-30 01:11:181473}
1474
1475void TabContents::OnDidLoadResourceFromMemoryCache(
1476 const GURL& url,
[email protected]70435962011-08-02 20:13:281477 const std::string& security_info,
1478 const std::string& http_method,
1479 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191480 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181481 cache.Increment();
1482
1483 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081484 int cert_id = 0;
1485 net::CertStatus cert_status = 0;
1486 int security_bits = -1;
1487 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181488 SSLManager::DeserializeSecurityInfo(security_info,
1489 &cert_id, &cert_status,
1490 &security_bits,
1491 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301492 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161493 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181494
[email protected]ad50def52011-10-19 23:17:071495 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271496 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501497 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531498 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181499}
1500
1501void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381502 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181503 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201504 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181505}
1506
1507void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021508 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231509 LOG(INFO) << security_origin << " ran insecure content from "
1510 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381511 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051512 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381513 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051514 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1515 }
[email protected]71fde352011-12-29 03:29:561516 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411517 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201518 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181519}
1520
1521void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1522 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251523 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101524 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181525}
1526
[email protected]1a55c5be2011-11-29 11:36:311527void TabContents::OnDidFinishLoad(
1528 int64 frame_id,
1529 const GURL& validated_url,
1530 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311532 DidFinishLoad(frame_id, validated_url, is_main_frame));
1533}
1534
1535void TabContents::OnDidFailLoadWithError(int64 frame_id,
1536 const GURL& validated_url,
1537 bool is_main_frame,
1538 int error_code,
1539 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251540 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311541 DidFailLoad(frame_id, validated_url, is_main_frame,
1542 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181543}
1544
[email protected]c8f73ab2011-01-22 00:05:171545void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271546 content_restrictions_ = restrictions;
1547 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171548}
1549
[email protected]216813952011-05-19 22:21:261550void TabContents::OnGoToEntryAtOffset(int offset) {
1551 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231552 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251553 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261554 if (!entry)
1555 return;
1556 // Note that we don't call NavigationController::GotToOffset() as we don't
1557 // want to create a pending navigation entry (it might end up lingering
1558 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251559 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581560 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511561 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581562 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471563 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571564
1565 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1566 // it in now that we know. This allows us to find the entry when it commits.
1567 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231568 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331569 entry->set_site_instance(
1570 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571571 }
[email protected]216813952011-05-19 22:21:261572 }
1573}
1574
1575void TabContents::OnUpdateZoomLimits(int minimum_percent,
1576 int maximum_percent,
1577 bool remember) {
1578 minimum_zoom_percent_ = minimum_percent;
1579 maximum_zoom_percent_ = maximum_percent;
1580 temporary_zoom_settings_ = !remember;
1581}
1582
[email protected]0bfbf882011-12-22 18:19:271583void TabContents::OnSaveURL(const GURL& url) {
[email protected]e30d68d2012-02-09 00:06:261584 // Check if the URL to save matches the URL of the main frame. Since this
1585 // message originates from Pepper plugins, it may not be the case if the
1586 // plugin is an embedded element.
1587 GURL main_frame_url = GetURL();
1588 if (!main_frame_url.is_valid())
1589 return;
1590 bool is_main_frame = (url == main_frame_url);
1591 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271592}
1593
[email protected]3a29a6e2011-08-24 18:26:211594void TabContents::OnEnumerateDirectory(int request_id,
1595 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591596 ChildProcessSecurityPolicyImpl* policy =
1597 ChildProcessSecurityPolicyImpl::GetInstance();
1598 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1599 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211600}
1601
[email protected]7d189022011-08-25 22:54:201602void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511603 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201604}
1605
1606void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1607 const GURL& url,
1608 const string16& title) {
[email protected]b9535422012-02-09 01:47:591609 ChildProcessSecurityPolicyImpl* policy =
1610 ChildProcessSecurityPolicyImpl::GetInstance();
1611 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1612 return;
[email protected]6934a702011-12-20 00:04:511613 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201614}
1615
[email protected]b888919c2011-09-02 00:32:161616void TabContents::OnFindReply(int request_id,
1617 int number_of_matches,
1618 const gfx::Rect& selection_rect,
1619 int active_match_ordinal,
1620 bool final_update) {
[email protected]6934a702011-12-20 00:04:511621 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1622 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001623 // Send a notification to the renderer that we are ready to receive more
1624 // results from the scoping effort of the Find operation. The FindInPage
1625 // scoping is asynchronous and periodically sends results back up to the
1626 // browser using IPC. In an effort to not spam the browser we have the
1627 // browser send an ACK for each FindReply message and have the renderer
1628 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521629 GetRenderViewHost()->Send(
1630 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161631}
1632
[email protected]d952a052011-09-06 18:42:451633void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511634 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451635}
1636
[email protected]7fc4bbb2011-09-08 21:23:101637void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1638 bool blocked_by_policy) {
1639 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101641 AppCacheAccessed(manifest_url, blocked_by_policy));
1642}
1643
[email protected]96d185d2009-04-24 03:28:541644// Notifies the RenderWidgetHost instance about the fact that the page is
1645// loading, or done loading and calls the base implementation.
1646void TabContents::SetIsLoading(bool is_loading,
1647 LoadNotificationDetails* details) {
1648 if (is_loading == is_loading_)
1649 return;
1650
1651 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211652 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541653 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561654 upload_size_ = 0;
1655 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541656 }
1657
1658 render_manager_.SetIsLoading(is_loading);
1659
1660 is_loading_ = is_loading;
1661 waiting_for_response_ = is_loading;
1662
[email protected]6ebdc9b2010-09-27 16:55:571663 if (delegate_)
1664 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461665 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541666
[email protected]432115822011-07-10 15:52:271667 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1668 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071669 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541670 if (details)
[email protected]6c2381d2011-10-19 02:52:531671 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071672 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501673 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541674 det);
1675}
1676
[email protected]420ae012009-04-24 05:16:321677void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131678 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321679 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561680 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381681 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441682 // that opened the window, as long as both renderers have the same
1683 // privileges.
[email protected]1fd1a502011-03-30 16:55:561684 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561685 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581686 // web_ui might be NULL if the URL refers to a non-existent extension.
1687 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401688 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521689 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441690 }
1691 }
[email protected]1fd1a502011-03-30 16:55:561692 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441693 }
1694
[email protected]4e697b042011-07-08 06:44:561695 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321696 // Clear the status bubble. This is a workaround for a bug where WebKit
1697 // doesn't let us know that the cursor left an element during a
1698 // transition (this is also why the mouse cursor remains as a hand after
1699 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1700 // clear the bubble when a user navigates to a named anchor in the same
1701 // page.
[email protected]36fc0392011-12-25 03:59:511702 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321703 }
1704
[email protected]a6e82fc2010-02-24 22:28:141705 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471706 // Once the main frame is navigated, we're no longer considered to have
1707 // displayed insecure content.
1708 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171709 }
[email protected]ce5c4502009-05-06 16:46:111710
[email protected]3c9e1872010-11-18 16:17:491711 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251712 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041713 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321714}
1715
1716void TabContents::DidNavigateAnyFramePostCommit(
1717 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131718 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321719 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061720 // If we navigate off the page, reset JavaScript state. This does nothing
1721 // to prevent a malicious script from spamming messages, since the script
1722 // could just reload the page to stop blocking.
1723 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551724 dialog_creator_->ResetJavaScriptState(this);
1725 dialog_creator_ = NULL;
1726 }
[email protected]420ae012009-04-24 05:16:321727
[email protected]3c9e1872010-11-18 16:17:491728 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041730 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]74ce1ad2011-12-16 21:51:461733void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1734 // If we are creating a RVH for a restored controller, then we need to make
1735 // sure the RenderView starts with a next_page_id_ larger than the number
1736 // of restored entries. This must be called before the RenderView starts
1737 // navigating (to avoid a race between the browser updating max_page_id and
1738 // the renderer updating next_page_id_). Because of this, we only call this
1739 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561740 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461741 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1742 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321743}
1744
[email protected]10f417c52011-12-28 21:04:231745bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571746 const string16& title) {
[email protected]420ae012009-04-24 05:16:321747 // For file URLs without a title, use the pathname instead. In the case of a
1748 // synthesized title, we don't want the update to count toward the "one set
1749 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511750 string16 final_title;
[email protected]420ae012009-04-24 05:16:321751 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511752 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1753 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321754 explicit_set = false; // Don't count synthetic titles toward the set limit.
1755 } else {
[email protected]acafd272011-07-26 17:35:571756 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321757 explicit_set = true;
1758 }
1759
[email protected]987fc3a2011-05-26 14:18:091760 // If a page is created via window.open and never navigated,
1761 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551762 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091763 if (entry) {
[email protected]36fc0392011-12-25 03:59:511764 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091765 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321766
[email protected]36fc0392011-12-25 03:59:511767 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091768 } else {
1769 if (page_title_when_no_navigation_entry_ == final_title)
1770 return false; // Nothing changed, don't bother.
1771
1772 page_title_when_no_navigation_entry_ = final_title;
1773 }
[email protected]420ae012009-04-24 05:16:321774
[email protected]420ae012009-04-24 05:16:321775 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231776 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321777
[email protected]105bb0f2011-05-24 17:12:141778 TitleUpdatedDetails details(entry, explicit_set);
1779
[email protected]ad50def52011-10-19 23:17:071780 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441781 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1782 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531783 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041784
[email protected]420ae012009-04-24 05:16:321785 return true;
1786}
1787
1788void TabContents::NotifySwapped() {
1789 // After sending out a swap notification, we need to send a disconnect
1790 // notification so that clients that pick up a pointer to |this| can NULL the
1791 // pointer. See Bug 1230284.
1792 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071793 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201794 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1795 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071796 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321797}
1798
1799void TabContents::NotifyConnected() {
1800 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071801 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121802 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1803 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071804 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321805}
1806
1807void TabContents::NotifyDisconnected() {
1808 if (!notify_disconnection_)
1809 return;
1810
1811 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071812 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321813 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1814 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071815 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321816}
1817
[email protected]8d3347f2009-07-09 22:00:211818RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321819 return view_.get();
1820}
1821
[email protected]8d3347f2009-07-09 22:00:211822RenderViewHostDelegate::RendererManagement*
1823TabContents::GetRendererManagementDelegate() {
1824 return &render_manager_;
1825}
1826
[email protected]daf82f82011-10-31 22:35:311827content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371828 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461829 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511830}
1831
[email protected]768c5472011-12-26 19:06:171832WebContents* TabContents::GetAsWebContents() {
1833 return this;
1834}
1835
[email protected]da4dfc42011-10-12 15:53:561836content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431837 return view_type_;
[email protected]7b291f92009-08-14 05:43:531838}
1839
[email protected]b7a756d42012-01-23 18:08:171840gfx::Rect TabContents::GetRootWindowResizerRect() const {
1841 if (delegate_)
1842 return delegate_->GetRootWindowResizerRect();
1843 return gfx::Rect();
1844}
1845
[email protected]420ae012009-04-24 05:16:321846void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071847 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271848 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321849 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531850 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231851 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321852 if (!entry)
1853 return;
1854
1855 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351856 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561857 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581858 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321859
1860 if (entry->IsViewSourceMode()) {
1861 // Put the renderer in view source mode.
1862 render_view_host->Send(
1863 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1864 }
[email protected]0666aef2009-05-13 19:48:081865
[email protected]d487beefe2011-12-21 05:41:211866 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261867
1868 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251869 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321870}
1871
1872void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521873 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321874 // Don't notify the world, since this came from a renderer in the
1875 // background.
1876 return;
1877 }
1878
1879 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311880 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231881 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301882
1883 // Restore the focus to the tab (otherwise the focus will be on the top
1884 // window).
[email protected]484ae5912010-09-29 19:16:141885 if (was_crashed && !FocusLocationBarByDefault() &&
1886 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301887 Focus();
[email protected]484ae5912010-09-29 19:16:141888 }
[email protected]32ded2212011-11-10 18:51:431889
[email protected]d8c660432011-12-22 20:51:251890 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321891}
1892
[email protected]443b80e2010-12-14 00:42:231893void TabContents::RenderViewGone(RenderViewHost* rvh,
1894 base::TerminationStatus status,
1895 int error_code) {
[email protected]151a63d2011-12-20 22:32:521896 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321897 // The pending page's RenderViewHost is gone.
1898 return;
1899 }
1900
1901 SetIsLoading(false, NULL);
1902 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231903 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311904 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321905
[email protected]d8c660432011-12-22 20:51:251906 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271907 observers_,
[email protected]be1f56ab2011-12-22 06:55:311908 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321909}
1910
[email protected]2e4633c2009-07-09 16:58:061911void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481912 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251913 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061914}
1915
[email protected]420ae012009-04-24 05:16:321916void TabContents::DidNavigate(RenderViewHost* rvh,
1917 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581918 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321919 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371920
[email protected]434f69f2012-02-06 21:56:521921 // Update the site of the SiteInstance if it doesn't have one yet, unless
1922 // this is for about:blank. In that case, the SiteInstance can still be
1923 // considered unused until a navigation to a real page.
1924 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1925 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331926 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521927 }
[email protected]420ae012009-04-24 05:16:321928
1929 // Need to update MIME type here because it's referred to in
1930 // UpdateNavigationCommands() called by RendererDidNavigate() to
1931 // determine whether or not to enable the encoding menu.
1932 // It's updated only for the main frame. For a subframe,
1933 // RenderView::UpdateURL does not set params.contents_mime_type.
1934 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1935 // TODO(jungshik): Add a test for the encoding menu to avoid
1936 // regressing it again.
[email protected]2905f742011-10-13 03:51:581937 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321938 contents_mime_type_ = params.contents_mime_type;
1939
[email protected]8286f51a2011-05-31 17:39:131940 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001941 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391942
[email protected]a9c0bfe2010-09-17 08:35:221943 // Send notification about committed provisional loads. This notification is
1944 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1945 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081946 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071947 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1948 // that is not recorded in the navigation history. For the purpose of
1949 // tracking navigation events, we treat this event as a sub frame navigation
1950 // event.
1951 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581952 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221953 // Whether or not a page transition was triggered by going backward or
1954 // forward in the history is only stored in the navigation controller's
1955 // entry list.
1956 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511957 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581958 content::PAGE_TRANSITION_FORWARD_BACK)) {
1959 transition_type = content::PageTransitionFromInt(
1960 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221961 }
[email protected]0d60f0192011-04-14 12:40:101962 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101964 DidCommitProvisionalLoadForFrame(params.frame_id,
1965 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221966 }
1967
[email protected]76543b92009-08-31 17:27:451968 if (!did_navigate)
1969 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321970
1971 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1972 // for the appropriate notification (best) or you can add it to
1973 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1974 // necessary, please).
1975
1976 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001977 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321978 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511979 if (delegate_)
1980 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001981 }
[email protected]420ae012009-04-24 05:16:321982 DidNavigateAnyFramePostCommit(rvh, details, params);
1983}
1984
1985void TabContents::UpdateState(RenderViewHost* rvh,
1986 int32 page_id,
1987 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151988 // Ensure that this state update comes from either the active RVH or one of
1989 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521990 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321991
1992 // We must be prepared to handle state updates for any page, these occur
1993 // when the user is scrolling and entering form data, as well as when we're
1994 // leaving a page, in which case our state may have already been moved to
1995 // the next page. The navigation controller will look up the appropriate
1996 // NavigationEntry and update it when it is notified via the delegate.
1997
1998 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151999 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:322000 if (entry_index < 0)
2001 return;
[email protected]10f417c52011-12-28 21:04:232002 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322003
[email protected]36fc0392011-12-25 03:59:512004 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322005 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512006 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322007 controller_.NotifyEntryChanged(entry, entry_index);
2008}
2009
2010void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572011 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462012 const string16& title,
2013 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322014 // If we have a title, that's a pretty good indication that we've started
2015 // getting useful data.
2016 SetNotWaitingForResponse();
2017
[email protected]73eb2602012-02-09 19:50:552018 // Try to find the navigation entry, which might not be the current one.
2019 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232020 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2021 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092022
[email protected]73eb2602012-02-09 19:50:552023 // We can handle title updates when we don't have an entry in
2024 // UpdateTitleForEntry, but only if the update is from the current RVH.
2025 if (!entry && rvh != GetRenderViewHost())
2026 return;
2027
[email protected]a49e10b2011-08-01 23:57:462028 // TODO(evan): make use of title_direction.
2029 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092030 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322031 return;
2032
2033 // Broadcast notifications when the UI should be updated.
2034 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462035 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322036}
2037
[email protected]420ae012009-04-24 05:16:322038void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402039 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312040 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322041}
2042
2043void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512044 if (delegate_)
2045 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322046}
2047
[email protected]420ae012009-04-24 05:16:322048void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292049 // The UI may be in an event-tracking loop, such as between the
2050 // mouse-down and mouse-up in text selection or a button click.
2051 // Defer the close until after tracking is complete, so that we
2052 // don't free objects out from under the UI.
2053 // TODO(shess): This could probably be integrated with the
2054 // IsDoingDrag() test below. Punting for now because I need more
2055 // research to understand how this impacts platforms other than Mac.
2056 // TODO(shess): This could get more fine-grained. For instance,
2057 // closing a tab in another window while selecting text in the
2058 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212059 if (GetView()->IsEventTracking()) {
2060 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292061 return;
2062 }
2063
[email protected]24a4d1062009-07-10 23:10:422064 // If we close the tab while we're in the middle of a drag, we'll crash.
2065 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212066 if (GetView()->IsDoingDrag()) {
2067 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422068 return;
2069 }
2070
[email protected]420ae012009-04-24 05:16:322071 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522072 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512073 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322074}
2075
[email protected]cd9ed79d2011-11-15 19:22:572076void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522077 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512078 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572079}
2080
[email protected]420ae012009-04-24 05:16:322081void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512082 if (delegate_ && delegate_->IsPopupOrPanel(this))
2083 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322084}
2085
[email protected]7ab1e7d62009-10-14 23:32:012086void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322087 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492088
[email protected]6934a702011-12-20 00:04:512089 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212090 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512091 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002092 }
[email protected]3c9e1872010-11-18 16:17:492093
2094 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252095 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322096}
2097
[email protected]7ab1e7d62009-10-14 23:32:012098void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322099 scoped_ptr<LoadNotificationDetails> details;
2100
[email protected]10f417c52011-12-28 21:04:232101 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322102 // An entry may not exist for a stop when loading an initial blank page or
2103 // if an iframe injected by script into a blank page finishes loading.
2104 if (entry) {
[email protected]420ae012009-04-24 05:16:322105 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2106
2107 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512108 entry->GetVirtualURL(),
2109 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322110 elapsed,
2111 &controller_,
2112 controller_.GetCurrentEntryIndex()));
2113 }
2114
[email protected]420ae012009-04-24 05:16:322115 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492116
2117 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252118 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322119}
2120
[email protected]c95fa8b2011-04-28 20:26:162121void TabContents::DidCancelLoading() {
2122 controller_.DiscardNonCommittedEntries();
2123
2124 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462125 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162126}
2127
[email protected]1a3c3cb2010-12-16 21:03:402128void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512129 if (delegate_)
2130 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402131}
2132
[email protected]952a68e2011-11-17 00:36:102133void TabContents::DocumentAvailableInMainFrame(
2134 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252135 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102136 DocumentAvailableInMainFrame());
2137}
2138
[email protected]25497492010-09-11 15:15:082139void TabContents::DocumentOnLoadCompletedInMainFrame(
2140 RenderViewHost* render_view_host,
2141 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072142 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272143 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322144 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532145 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082146}
2147
[email protected]ae5184d62011-10-06 19:25:582148void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152149 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582150 WindowOpenDisposition disposition,
2151 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482152 // Delegate to RequestTransferURL because this is just the generic
2153 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582154 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482155 GlobalRequestID());
2156}
2157
2158void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582159 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482160 WindowOpenDisposition disposition,
2161 int64 source_frame_id,
2162 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202163 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582164 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582165 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352166 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322167 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2168 // generated suggestions).
2169 //
[email protected]e0112912011-02-02 22:54:352170 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162171 // want web sites to see a referrer of "chrome://blah" (and some
2172 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322173 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432174 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222175 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482176 false /* is_renderer_initiated */);
2177 params.transferred_global_request_id = old_request_id;
2178 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222179 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322180 } else {
[email protected]6bf6a6b52012-02-03 15:41:432181 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482182 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2183 params.transferred_global_request_id = old_request_id;
2184 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582185 }
2186 if (new_contents) {
2187 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252188 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582189 DidOpenRequestedURL(new_contents,
2190 url,
2191 referrer,
2192 disposition,
2193 transition_type,
2194 source_frame_id));
[email protected]420ae012009-04-24 05:16:322195 }
2196}
2197
[email protected]420ae012009-04-24 05:16:322198void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342199 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412200 const string16& message,
2201 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322202 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472203 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322204 IPC::Message* reply_msg,
2205 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072206 // Suppress JavaScript dialogs when requested. Also suppress messages when
2207 // showing an interstitial as it's shown over the previous page and we don't
2208 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502209 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152210 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272211 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072212 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522213 delegate_->ShouldSuppressDialogs() ||
2214 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322215
2216 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342217 content::JavaScriptDialogCreator::TitleType title_type;
2218 string16 title;
2219
2220 if (!frame_url.has_host()) {
2221 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2222 } else {
2223 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2224 title = net::FormatUrl(
2225 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202226 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302227 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342228 }
2229
[email protected]2e5b90c2011-08-16 21:11:552230 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522231 dialog_creator_->RunJavaScriptDialog(
2232 this, title_type, title, javascript_message_type, message,
2233 default_prompt,
2234 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2235 reply_msg),
2236 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322237 }
[email protected]3ab9cb82011-06-03 18:02:072238
2239 if (suppress_this_message) {
2240 // If we are suppressing messages, just reply as if the user immediately
2241 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342242 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072243 }
2244
2245 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322246}
2247
[email protected]fedec012012-01-28 03:09:342248void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412249 const string16& message,
[email protected]420ae012009-04-24 05:16:322250 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512251 if (delegate_)
2252 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072253
2254 bool suppress_this_message =
2255 rvh->is_swapped_out() ||
2256 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522257 delegate_->ShouldSuppressDialogs() ||
2258 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152259 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342260 // The reply must be sent to the RVH that sent the request.
2261 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502262 return;
2263 }
[email protected]3ab9cb82011-06-03 18:02:072264
[email protected]7ab1e7d62009-10-14 23:32:012265 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552266 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522267 dialog_creator_->RunBeforeUnloadDialog(
2268 this, message,
2269 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2270 reply_msg));
[email protected]420ae012009-04-24 05:16:322271}
2272
[email protected]420ae012009-04-24 05:16:322273WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542274 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322275}
2276
[email protected]7d472472011-01-22 01:30:252277void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272278 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252279 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222280
[email protected]99907362012-01-11 05:41:402281 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172282 if (rdh) // NULL in unittests.
2283 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252284}
2285
[email protected]fa1cf0b82010-01-15 21:49:442286void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442287 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252288 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442289}
2290
[email protected]420ae012009-04-24 05:16:322291void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2292 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152293 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522294 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152295 return;
2296
[email protected]e5fc1632011-08-08 07:51:532297 // Ignore renderer unresponsive event if debugger is attached to the tab
2298 // since the event may be a result of the renderer sitting on a breakpoint.
2299 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442300 DevToolsAgentHost* agent =
2301 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2302 if (agent &&
2303 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532304 return;
2305
[email protected]420ae012009-04-24 05:16:322306 if (is_during_unload) {
2307 // Hang occurred while firing the beforeunload/unload handler.
2308 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112309 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322310
2311 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2312 return;
2313
2314 // If the tab hangs in the beforeunload/unload handler there's really
2315 // nothing we can do to recover. Pretend the unload listeners have
2316 // all fired and close the tab. If the hang is in the beforeunload handler
2317 // then the user will not have the option of cancelling the close.
2318 Close(rvh);
2319 return;
2320 }
2321
[email protected]151a63d2011-12-20 22:32:522322 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472323 return;
2324
[email protected]6934a702011-12-20 00:04:512325 if (delegate_)
2326 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322327}
2328
2329void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512330 if (delegate_)
2331 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322332}
2333
2334void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212335 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562336 uint64 upload_position,
2337 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322338 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562339 upload_position_ = upload_position;
2340 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502341 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202342 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302343 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212344 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322345 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462346 if (IsLoading()) {
2347 NotifyNavigationStateChanged(
2348 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2349 }
[email protected]420ae012009-04-24 05:16:322350}
2351
[email protected]7d472472011-01-22 01:30:252352void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512353 if (delegate_)
2354 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252355}
2356
[email protected]420ae012009-04-24 05:16:322357void TabContents::BeforeUnloadFiredFromRenderManager(
2358 bool proceed,
2359 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512360 if (delegate_)
2361 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322362}
2363
[email protected]3a3d47472010-07-15 21:03:542364void TabContents::DidStartLoadingFromRenderManager(
2365 RenderViewHost* render_view_host) {
2366 DidStartLoading();
2367}
2368
2369void TabContents::RenderViewGoneFromRenderManager(
2370 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232371 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2372 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542373}
2374
[email protected]420ae012009-04-24 05:16:322375void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102376 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262377 gfx::Size size = view_->GetContainerSize();
2378 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2379 // here during container initialization and normal window size will be set
2380 // later. In case of tab duplication this resizing to 0x0 prevents setting
2381 // normal size later so just ignore it.
2382 if (!size.IsEmpty())
2383 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322384}
2385
[email protected]3a3d47472010-07-15 21:03:542386void TabContents::NotifySwappedFromRenderManager() {
2387 NotifySwapped();
2388}
2389
[email protected]d202a7c2012-01-04 07:53:472390NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202391 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542392}
2393
[email protected]d2353452012-01-19 19:53:562394WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2395 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322396}
2397
[email protected]10f417c52011-12-28 21:04:232398NavigationEntry*
2399 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322400 return controller_.GetLastCommittedEntry();
2401}
2402
2403bool TabContents::CreateRenderViewForRenderManager(
2404 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442405 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322406 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522407
[email protected]420ae012009-04-24 05:16:322408 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442409 if (rwh_view)
2410 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322411
[email protected]74ce1ad2011-12-16 21:51:462412 // Make sure we use the correct starting page_id in the new RenderView.
2413 UpdateMaxPageIDIfNecessary(render_view_host);
2414 int32 max_page_id =
2415 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2416
2417 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522418 return false;
2419
[email protected]e60c0232011-11-11 19:56:352420#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502421 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2422 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442423 if (rwh_view) {
2424 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2425 render_widget_host->WasResized();
2426 }
[email protected]f8233cc2011-05-31 20:24:502427#endif
2428
[email protected]420ae012009-04-24 05:16:322429 return true;
2430}
2431
[email protected]fedec012012-01-28 03:09:342432void TabContents::OnDialogClosed(RenderViewHost* rvh,
2433 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072434 bool success,
2435 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542436 if (is_showing_before_unload_dialog_ && !success) {
2437 // If a beforeunload dialog is canceled, we need to stop the throbber from
2438 // spinning, since we forced it to start spinning in Navigate.
2439 DidStopLoading();
2440
2441 tab_close_start_time_ = base::TimeTicks();
2442 }
2443 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342444 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542445}
2446
[email protected]be1f56ab2011-12-22 06:55:312447void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122448 encoding_ = content::GetContentClient()->browser()->
2449 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102450}
[email protected]f45d2a72010-03-08 23:28:352451
[email protected]e30d68d2012-02-09 00:06:262452void TabContents::SaveURL(const GURL& url,
2453 const GURL& referrer,
2454 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142455 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2456 if (!dlm)
2457 return;
2458 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262459 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142460 const NavigationEntry* entry = controller_.GetActiveEntry();
2461 if (entry)
2462 post_id = entry->GetPostID();
2463 }
2464 DownloadSaveInfo save_info;
2465 save_info.prompt_for_save_location = true;
2466 dlm->DownloadUrl(url,
2467 referrer,
2468 "",
2469 true, // prefer_cache
2470 post_id,
2471 save_info,
2472 this);
2473}
2474
[email protected]33f74972010-12-08 16:40:362475void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212476 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442477 // Can be NULL during tests.
2478 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212479 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362480}