blob: cf79d601313529b907fc776712891529b885a35d [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]567812d2011-02-24 17:40:5016#include "content/browser/child_process_security_policy.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]567812d2011-02-24 17:40:5020#include "content/browser/host_zoom_map.h"
21#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0022#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0123#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0424#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3025#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5026#include "content/browser/renderer_host/render_view_host.h"
27#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2228#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3330#include "content/browser/site_instance_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/interstitial_page.h"
[email protected]10f417c52011-12-28 21:04:2332#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1434#include "content/browser/tab_contents/title_updated_details.h"
[email protected]d2353452012-01-19 19:53:5635#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1138#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4439#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4440#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1741#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4642#include "content/public/browser/invalidate_type.h"
[email protected]5b96836f2011-12-22 07:39:0043#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4844#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3845#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4246#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2547#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1048#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5049#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2150#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4851#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1852#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0353#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1654#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2955#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3456#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3757#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3858#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2459#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3160#include "webkit/glue/webpreferences.h"
61
62#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1263#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3164#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0065
[email protected]420ae012009-04-24 05:16:3266// Cross-Site Navigations
67//
68// If a TabContents is told to navigate to a different web site (as determined
69// by SiteInstance), it will replace its current RenderViewHost with a new
70// RenderViewHost dedicated to the new SiteInstance. This works as follows:
71//
72// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4673// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3274// - The pending RVH is "suspended," so that no navigation messages are sent to
75// its renderer until the onbeforeunload JavaScript handler has a chance to
76// run in the current RVH.
77// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
78// that it has a pending cross-site request. ResourceDispatcherHost will
79// check for this when the response arrives.
80// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4681// cancel all the pending logic. Otherwise we allow the pending RVH to send
82// the navigation request to its renderer.
83// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
84// main resource load on the pending RVH. It checks CrossSiteRequestManager
85// to see that it is a cross-site request, and installs a
86// CrossSiteResourceHandler.
87// - When RDH receives a response, the BufferedResourceHandler determines
88// whether it is a download. If so, it sends a message to the new renderer
89// causing it to cancel the request, and the download proceeds. For now, the
90// pending RVH remains until the next DidNavigate event for this TabContents.
91// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3292// - After RDH receives a response and determines that it is safe and not a
93// download, it pauses the response to first run the old page's onunload
94// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1595// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3296// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1597// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3298// the ResourceDispatcherHost, who unpauses the response. Data is then sent
99// to the pending RVH.
100// - The pending renderer sends a FrameNavigate message that invokes the
101// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46102// pending RVH.
[email protected]992db4c2011-05-12 15:37:15103// - The previous renderer is kept swapped out in RenderViewHostManager in case
104// the user goes back. The process only stays live if another tab is using
105// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32106
[email protected]0e12d7d2011-12-01 16:21:44107using content::DevToolsAgentHost;
108using content::DevToolsAgentHostRegistry;
109using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17110using content::DownloadItem;
111using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20112using content::GlobalRequestID;
[email protected]c5eed492012-01-04 17:07:50113using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23114using content::NavigationEntry;
115using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20116using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57117using content::RenderViewHostDelegate;
[email protected]b6583592012-01-25 19:52:33118using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17119using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38120using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09121using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25122using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56123using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22124using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50125using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44126
[email protected]420ae012009-04-24 05:16:32127namespace {
128
129// Amount of time we wait between when a key event is received and the renderer
130// is queried for its state and pushed to the NavigationEntry.
131const int kQueryStateDelay = 5000;
132
[email protected]6ebdc9b2010-09-27 16:55:57133const int kSyncWaitDelay = 40;
134
[email protected]ca406032011-07-19 21:53:05135static const char kDotGoogleDotCom[] = ".google.com";
136
[email protected]420ae012009-04-24 05:16:32137#if defined(OS_WIN)
138
139BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
140 // Note: erase is required to properly paint some widgets borders. This can
141 // be seen with textfields.
142 InvalidateRect(hwnd, NULL, TRUE);
143 return TRUE;
144}
145#endif
146
[email protected]2c5569662011-03-22 20:45:02147ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23148 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50149 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16150 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47151 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02152 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47153 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02154 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47155 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16156 break; // Fall through to rest of function.
157 }
[email protected]5e369672009-11-03 23:48:30158
[email protected]10f417c52011-12-28 21:04:23159 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37160 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02161 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30162
[email protected]2c5569662011-03-22 20:45:02163 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30164}
165
[email protected]10f417c52011-12-28 21:04:23166void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47167 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42168 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50169 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16170 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51171 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54172 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55173 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
174 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51175 params->url = entry.GetURL();
176 params->referrer = entry.GetReferrer();
177 params->transition = entry.GetTransitionType();
178 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00179 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55180 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34181 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47182 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48183 params->transferred_request_child_id =
184 entry.transferred_global_request_id().child_id;
185 params->transferred_request_request_id =
186 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47187
188 if (delegate)
189 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34190}
191
[email protected]420ae012009-04-24 05:16:32192} // namespace
193
[email protected]a81343d232011-12-27 07:39:20194namespace content {
195
196WebContents* WebContents::Create(
197 BrowserContext* browser_context,
198 SiteInstance* site_instance,
199 int routing_id,
200 const WebContents* base_tab_contents,
201 SessionStorageNamespace* session_storage_namespace) {
202 return new TabContents(browser_context,
203 site_instance,
204 routing_id,
205 static_cast<const TabContents*>(base_tab_contents),
206 session_storage_namespace);
207}
208}
[email protected]f4f50ef2011-01-21 19:01:19209
210// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32211
[email protected]3d7474ff2011-07-27 17:47:37212TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32213 SiteInstance* site_instance,
214 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07215 const TabContents* base_tab_contents,
216 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42217 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07218 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37219 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13220 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10221 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22222 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34223 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23224 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
225 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34226 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21227 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56228 upload_size_(0),
229 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47230 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57231 capturing_contents_(false),
232 is_being_destroyed_(false),
233 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55234 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57235#if defined(OS_WIN)
236 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
237#endif
[email protected]7ab1e7d62009-10-14 23:32:01238 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56239 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38240 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25241 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01242 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25243 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01244 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00245 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43246 content_restrictions_(0),
247 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37248 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32249
[email protected]34ac70502009-09-25 17:07:23250 // We have the initial size of the view be based on the size of the passed in
251 // tab contents (normally a tab from the same window).
252 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21253 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00254
255#if defined(ENABLE_JAVA_BRIDGE)
256 java_bridge_dispatcher_host_manager_.reset(
257 new JavaBridgeDispatcherHostManager(this));
258#endif
[email protected]332af7732009-03-11 13:21:35259}
initial.commit09911bf2008-07-26 23:55:29260
261TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32262 is_being_destroyed_ = true;
263
[email protected]3ab9cb82011-06-03 18:02:07264 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55265 if (dialog_creator_)
266 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07267
[email protected]420ae012009-04-24 05:16:32268 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32269
[email protected]420ae012009-04-24 05:16:32270 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07271 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09272 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
273 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07274 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32275
276 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07277#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32278 // If we still have a window handle, destroy it. GetNativeView can return
279 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42280 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52281 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44282 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42283 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42284 }
[email protected]420ae012009-04-24 05:16:32285#endif
[email protected]7ab1e7d62009-10-14 23:32:01286
287 // OnCloseStarted isn't called in unit tests.
288 if (!tab_close_start_time_.is_null()) {
289 UMA_HISTOGRAM_TIMES("Tab.Close",
290 base::TimeTicks::Now() - tab_close_start_time_);
291 }
[email protected]b5a1d11c2011-02-17 03:09:42292
[email protected]d8c660432011-12-22 20:51:25293 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08294
[email protected]6934a702011-12-20 00:04:51295 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42296}
297
[email protected]d202a7c2012-01-04 07:53:47298NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20299 return controller_;
300}
301
[email protected]765187182012-01-11 23:59:28302RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
303 return &render_manager_;
304}
305
[email protected]724159a2010-12-30 01:11:18306bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56307 if (GetWebUI() &&
308 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17309 return true;
[email protected]d2353452012-01-19 19:53:56310 }
[email protected]f82d57b52011-04-27 19:13:17311
[email protected]d8c660432011-12-22 20:51:25312 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
313 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10314 while ((observer = it.GetNext()) != NULL)
315 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53316 return true;
[email protected]403415a2011-01-10 18:57:53317
[email protected]724159a2010-12-30 01:11:18318 bool handled = true;
319 bool message_is_ok = true;
320 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58321 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
322 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24323 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
324 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18325 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
326 OnDidStartProvisionalLoadForFrame)
327 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
328 OnDidRedirectProvisionalLoad)
329 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
330 OnDidFailProvisionalLoadWithError)
331 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
332 OnDidLoadResourceFromMemoryCache)
333 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
334 OnDidDisplayInsecureContent)
335 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
336 OnDidRunInsecureContent)
337 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
338 OnDocumentLoadedInFrame)
339 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17340 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
341 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25342 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26343 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59344 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21345 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20346 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
347 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
348 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16349 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45350 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10351 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18352 IPC_MESSAGE_UNHANDLED(handled = false)
353 IPC_END_MESSAGE_MAP_EX()
354
355 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38356 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18357 GetRenderProcessHost()->ReceivedBadMessage();
358 }
359
360 return handled;
361}
362
[email protected]6c2e472f2011-08-24 23:26:18363void TabContents::RunFileChooser(
364 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23365 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51366 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18367}
368
[email protected]c5eed492012-01-04 17:07:50369NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56370 return controller_;
371}
372
[email protected]c5eed492012-01-04 17:07:50373const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56374 return controller_;
375}
376
[email protected]627e0512011-12-21 22:55:30377content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55378 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30379}
380
[email protected]f5fa20e2011-12-21 22:35:56381void TabContents::SetViewType(content::ViewType type) {
382 view_type_ = type;
383}
384
[email protected]ea049a02011-12-25 21:37:09385content::ViewType TabContents::GetViewType() const {
386 return view_type_;
387}
388
[email protected]be1f56ab2011-12-22 06:55:31389const GURL& TabContents::GetURL() const {
390 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23391 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51392 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31393}
394
395
396const base::PropertyBag* TabContents::GetPropertyBag() const {
397 return &property_bag_;
398}
399
400base::PropertyBag* TabContents::GetPropertyBag() {
401 return &property_bag_;
402}
403
404content::WebContentsDelegate* TabContents::GetDelegate() {
405 return delegate_;
406}
407
408void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
409 // TODO(cbentzel): remove this debugging code?
410 if (delegate == delegate_)
411 return;
412 if (delegate_)
413 delegate_->Detach(this);
414 delegate_ = delegate;
415 if (delegate_)
416 delegate_->Attach(this);
417}
418
[email protected]f3b1a082011-11-18 00:34:30419content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03420 if (render_manager_.current_host())
421 return render_manager_.current_host()->process();
422 else
423 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16424}
425
[email protected]be1f56ab2011-12-22 06:55:31426RenderViewHost* TabContents::GetRenderViewHost() const {
427 return render_manager_.current_host();
428}
429
430RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
431 return render_manager_.GetRenderWidgetHostView();
432}
433
[email protected]8643e6d2012-01-18 20:26:10434content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31435 return view_.get();
436}
437
[email protected]01ec4ec2012-01-18 04:13:47438content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50439 WebUIControllerFactory* factory =
440 content::GetContentClient()->browser()->GetWebUIControllerFactory();
441 if (!factory)
442 return NULL;
[email protected]d2353452012-01-19 19:53:56443 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22444 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50445 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22446 if (controller) {
447 web_ui->SetController(controller);
448 return web_ui;
449 }
450
451 delete web_ui;
452 return NULL;
453}
454
[email protected]01ec4ec2012-01-18 04:13:47455content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31456 return render_manager_.web_ui() ? render_manager_.web_ui()
457 : render_manager_.pending_web_ui();
458}
459
[email protected]01ec4ec2012-01-18 04:13:47460content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31461 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34462}
463
[email protected]96d185d2009-04-24 03:28:54464const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55465 // Transient entries take precedence. They are used for interstitial pages
466 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23467 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08468 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20469 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30470 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23471 if (entry) {
[email protected]b5cca982011-05-26 04:42:08472 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23473 }
[email protected]7ade2732011-02-10 00:13:58474 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
475 render_manager_.pending_web_ui() : render_manager_.web_ui();
476 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54477 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55478 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54479 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35480 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22481 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54482 if (!title.empty())
483 return title;
484 }
485 }
486
487 // We use the title for the last committed entry rather than a pending
488 // navigation entry. For example, when the user types in a URL, we want to
489 // keep the old page's title until the new load has committed and we get a new
490 // title.
[email protected]96d185d2009-04-24 03:28:54491 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23492 if (entry) {
[email protected]b5cca982011-05-26 04:42:08493 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23494 }
[email protected]987fc3a2011-05-26 14:18:09495
496 // |page_title_when_no_navigation_entry_| is finally used
497 // if no title cannot be retrieved.
498 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54499}
500
[email protected]d5f942ba2008-09-26 19:30:34501int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46502 return GetMaxPageIDForSiteInstance(GetSiteInstance());
503}
504
505int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33506 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
507 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46508
[email protected]b6583592012-01-25 19:52:33509 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34510}
511
512void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46513 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
514}
515
[email protected]b6583592012-01-25 19:52:33516void TabContents::UpdateMaxPageIDForSiteInstance(
517 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46518 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33519 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34520}
521
[email protected]91854cd2012-01-10 19:43:57522void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
523 max_page_ids_ = tab_contents->max_page_ids_;
524}
525
[email protected]96d185d2009-04-24 03:28:54526SiteInstance* TabContents::GetSiteInstance() const {
527 return render_manager_.current_host()->site_instance();
528}
529
[email protected]77362eb2011-08-01 17:18:38530SiteInstance* TabContents::GetPendingSiteInstance() const {
531 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
532 render_manager_.pending_render_view_host() :
533 render_manager_.current_host();
534 return dest_rvh->site_instance();
535}
536
[email protected]be1f56ab2011-12-22 06:55:31537bool TabContents::IsLoading() const {
538 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49539}
540
[email protected]be1f56ab2011-12-22 06:55:31541bool TabContents::IsWaitingForResponse() const {
542 return waiting_for_response_;
543}
544
545const net::LoadStateWithParam& TabContents::GetLoadState() const {
546 return load_state_;
547}
548
549const string16& TabContents::GetLoadStateHost() const {
550 return load_state_host_;
551}
552
553uint64 TabContents::GetUploadSize() const {
554 return upload_size_;
555}
556
557uint64 TabContents::GetUploadPosition() const {
558 return upload_position_;
559}
560
561const std::string& TabContents::GetEncoding() const {
562 return encoding_;
563}
564
565bool TabContents::DisplayedInsecureContent() const {
566 return displayed_insecure_content_;
567}
568
569void TabContents::SetCapturingContents(bool cap) {
570 capturing_contents_ = cap;
571}
572
573bool TabContents::IsCrashed() const {
574 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
575 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
576 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49577}
578
[email protected]443b80e2010-12-14 00:42:23579void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
580 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34581 return;
582
[email protected]443b80e2010-12-14 00:42:23583 crashed_status_ = status;
584 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46585 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34586}
587
[email protected]be1f56ab2011-12-22 06:55:31588base::TerminationStatus TabContents::GetCrashedStatus() const {
589 return crashed_status_;
590}
591
592bool TabContents::IsBeingDestroyed() const {
593 return is_being_destroyed_;
594}
595
[email protected]d5f942ba2008-09-26 19:30:34596void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
597 if (delegate_)
598 delegate_->NavigationStateChanged(this, changed_flags);
599}
600
[email protected]96d185d2009-04-24 03:28:54601void TabContents::DidBecomeSelected() {
602 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16603 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
604 if (rwhv) {
605 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43606#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16607 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43608#endif
609 }
[email protected]96d185d2009-04-24 03:28:54610
[email protected]5ac20162010-11-24 23:33:11611 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38612
[email protected]d8c660432011-12-22 20:51:25613 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54614}
615
[email protected]be1f56ab2011-12-22 06:55:31616
617base::TimeTicks TabContents::GetLastSelectedTime() const {
618 return last_selected_time_;
619}
620
[email protected]96d185d2009-04-24 03:28:54621void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31622 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52623 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
624 // open a tab in then background, then closes the tab before selecting it.
625 // This is because closing the tab calls TabContents::Destroy(), which
626 // removes the |GetRenderViewHost()|; then when we actually destroy the
627 // window, OnWindowPosChanged() notices and calls HideContents() (which
628 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16629 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
630 if (rwhv)
631 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54632 }
633
[email protected]ad50def52011-10-19 23:17:07634 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09635 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
636 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07637 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54638}
639
[email protected]be1f56ab2011-12-22 06:55:31640void TabContents::ShowContents() {
641 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
642 if (rwhv)
643 rwhv->DidBecomeSelected();
644}
645
646void TabContents::HideContents() {
647 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
648 // our superclass HideContents(), because some callers want to be very picky
649 // about the order in which these get called. In addition to making the code
650 // here practically impossible to understand, this also means we end up
651 // calling TabContents::WasHidden() twice if callers call both versions of
652 // HideContents() on a TabContents.
653 WasHidden();
654}
655
656bool TabContents::NeedToFireBeforeUnload() {
657 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27658 return WillNotifyDisconnection() &&
659 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31660 !GetRenderViewHost()->SuddenTerminationAllowed();
661}
662
[email protected]0bfbf882011-12-22 18:19:27663void TabContents::Stop() {
664 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25665 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27666}
667
[email protected]d9083482012-01-06 00:38:46668WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27669 // We create a new SiteInstance so that the new tab won't share processes
670 // with the old one. This can be changed in the future if we need it to share
671 // processes for some reason.
672 TabContents* tc = new TabContents(
673 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33674 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27675 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20676 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27677 return tc;
678}
679
680void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17681 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27682 bool show_history) {
683 if (!delegate_)
684 return;
685
686 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
687}
688
[email protected]2a6bc3e2011-12-28 23:51:33689void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27690 WindowOpenDisposition disposition,
691 const gfx::Rect& initial_pos,
692 bool user_gesture) {
693 if (!delegate_)
694 return;
695
696 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
697 user_gesture);
698}
699
700gfx::NativeView TabContents::GetContentNativeView() const {
701 return view_->GetContentNativeView();
702}
703
704gfx::NativeView TabContents::GetNativeView() const {
705 return view_->GetNativeView();
706}
707
708void TabContents::GetContainerBounds(gfx::Rect* out) const {
709 view_->GetContainerBounds(out);
710}
711
712void TabContents::Focus() {
713 view_->Focus();
714}
715
[email protected]d8c660432011-12-22 20:51:25716void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31717 observers_.AddObserver(observer);
718}
719
[email protected]d8c660432011-12-22 20:51:25720void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31721 observers_.RemoveObserver(observer);
722}
723
[email protected]d5f942ba2008-09-26 19:30:34724void TabContents::Activate() {
725 if (delegate_)
726 delegate_->ActivateContents(this);
727}
728
[email protected]ea42e7782010-08-23 23:58:12729void TabContents::Deactivate() {
730 if (delegate_)
731 delegate_->DeactivateContents(this);
732}
733
[email protected]63954792011-07-11 04:17:48734void TabContents::LostCapture() {
735 if (delegate_)
736 delegate_->LostCapture();
737}
738
739bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
740 bool* is_keyboard_shortcut) {
741 return delegate_ &&
742 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
743}
744
745void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
746 if (delegate_)
747 delegate_->HandleKeyboardEvent(event);
748}
749
[email protected]32ded2212011-11-10 18:51:43750void TabContents::HandleMouseDown() {
751 if (delegate_)
752 delegate_->HandleMouseDown();
753}
754
[email protected]63954792011-07-11 04:17:48755void TabContents::HandleMouseUp() {
756 if (delegate_)
757 delegate_->HandleMouseUp();
758}
759
760void TabContents::HandleMouseActivate() {
761 if (delegate_)
762 delegate_->HandleMouseActivate();
763}
764
[email protected]8a5e0ca2011-08-25 06:30:47765void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
766 if (delegate_)
767 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
768}
769
[email protected]5d5f7af2011-10-01 01:38:12770bool TabContents::IsFullscreenForCurrentTab() const {
771 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
772}
773
[email protected]e9621112011-10-17 05:38:37774void TabContents::RequestToLockMouse() {
775 if (delegate_) {
776 delegate_->RequestToLockMouse(this);
777 } else {
778 GotResponseToLockMouseRequest(false);
779 }
780}
781
782void TabContents::LostMouseLock() {
783 if (delegate_)
784 delegate_->LostMouseLock();
785}
786
[email protected]0548c5352011-09-07 00:33:33787void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23788 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33789 if (delegate_)
790 delegate_->UpdatePreferredSize(this, pref_size);
791}
792
[email protected]32ded2212011-11-10 18:51:43793void TabContents::WebUISend(RenderViewHost* render_view_host,
794 const GURL& source_url,
795 const std::string& name,
796 const base::ListValue& args) {
797 if (delegate_)
798 delegate_->WebUISend(this, source_url, name, args);
799}
800
[email protected]e5d549d2011-12-28 01:29:20801WebContents* TabContents::OpenURL(const OpenURLParams& params) {
802 if (!delegate_)
803 return NULL;
[email protected]00c37fc2011-08-02 00:22:50804
[email protected]e5d549d2011-12-28 01:29:20805 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
806 // Notify observers.
807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
808 DidOpenURL(params.url, params.referrer,
809 params.disposition, params.transition));
810 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34811}
812
[email protected]1ccb3568d2010-02-19 10:51:16813bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50814 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25815 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23816 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25817 reload_type);
[email protected]876bc832010-09-07 16:29:54818}
[email protected]96d185d2009-04-24 03:28:54819
[email protected]876bc832010-09-07 16:29:54820bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23821 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50822 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40823 // The renderer will reject IPC messages with URLs longer than
824 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51825 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40826 return false;
827
[email protected]dd11de52011-11-03 22:54:27828 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40829 if (!dest_render_view_host)
830 return false; // Unable to create the desired render view host.
831
[email protected]80a8fad2011-01-29 04:02:38832 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07833 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58834 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:50835 WebUIControllerFactory* factory =
836 content::GetContentClient()->browser()->GetWebUIControllerFactory();
837 bool is_allowed_in_web_ui_renderer =
838 factory &&
839 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43840#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51841 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43842#endif
[email protected]e091df82011-10-11 18:13:21843 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55844 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58845
[email protected]96d185d2009-04-24 03:28:54846 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44847 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52848 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44849 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51850 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54851
852 // Used for page load time metrics.
853 current_load_start_ = base::TimeTicks::Now();
854
855 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34856 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27857 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47858 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34859 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54860
[email protected]36fc0392011-12-25 03:59:51861 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54862 // HACK!! This code suppresses javascript: URLs from being added to
863 // session history, which is what we want to do for javascript: URLs that
864 // do not generate content. What we really need is a message from the
865 // renderer telling us that a new page was not created. The same message
866 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51867 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54868 return false;
869 }
870
[email protected]3c9e1872010-11-18 16:17:49871 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25872 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04873 observers_,
[email protected]36fc0392011-12-25 03:59:51874 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54875
[email protected]09b29342011-06-24 19:18:48876 if (delegate_)
877 delegate_->DidNavigateToPendingEntry(this);
878
[email protected]d5f942ba2008-09-26 19:30:34879 return true;
880}
881
[email protected]b6583592012-01-25 19:52:33882void TabContents::SetHistoryLengthAndPrune(
883 const SiteInstance* site_instance,
884 int history_length,
885 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41886 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
887 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19888 if (render_manager_.pending_render_view_host()) {
889 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14890 return;
[email protected]9e1ad4b2011-08-14 16:49:19891 }
[email protected]151a63d2011-12-20 22:32:52892 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19893 if (!rvh) {
894 NOTREACHED();
895 return;
896 }
897 if (site_instance && rvh->site_instance() != site_instance) {
898 NOTREACHED();
899 return;
900 }
901 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
902 history_length,
903 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14904}
905
[email protected]90daadb42009-06-08 21:27:28906void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27907 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54908 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
909 return;
910 }
[email protected]151a63d2011-12-20 22:32:52911 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54912}
913
[email protected]0bfbf882011-12-22 18:19:27914bool TabContents::ShowingInterstitialPage() const {
915 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54916}
917
[email protected]0bfbf882011-12-22 18:19:27918InterstitialPage* TabContents::GetInterstitialPage() const {
919 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22920}
921
[email protected]a53209b2012-01-20 16:48:16922bool TabContents::IsSavable() {
923 // WebKit creates Document object when MIME type is application/xhtml+xml,
924 // so we also support this MIME type.
925 return contents_mime_type_ == "text/html" ||
926 contents_mime_type_ == "text/xml" ||
927 contents_mime_type_ == "application/xhtml+xml" ||
928 contents_mime_type_ == "text/plain" ||
929 contents_mime_type_ == "text/css" ||
930 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
931}
932
[email protected]c7dd2f62011-07-18 15:57:59933void TabContents::OnSavePage() {
934 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:16935 if (!IsSavable()) {
[email protected]627e0512011-12-21 22:55:30936 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59937 const GURL& current_page_url = GetURL();
938 if (dlm && current_page_url.is_valid()) {
939 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46940 download_stats::RecordDownloadCount(
941 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59942 return;
943 }
944 }
945
946 Stop();
947
948 // Create the save package and possibly prompt the user for the name to save
949 // the page as. The user prompt is an asynchronous operation that runs on
950 // another thread.
951 save_package_ = new SavePackage(this);
952 save_package_->GetSaveInfo();
953}
954
955// Used in automated testing to bypass prompting the user for file names.
956// Instead, the names and paths are hard coded rather than running them through
957// file name sanitation and extension / mime checking.
958bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:16959 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:59960 // Stop the page from navigating.
961 Stop();
962
963 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
964 return save_package_->Init();
965}
966
[email protected]420ae012009-04-24 05:16:32967bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:23968 NavigationEntryImpl* active_entry =
969 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:32970 return (active_entry != NULL &&
971 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51972 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32973}
974
[email protected]0bfbf882011-12-22 18:19:27975const std::string& TabContents::GetContentsMimeType() const {
976 return contents_mime_type_;
977}
978
979bool TabContents::WillNotifyDisconnection() const {
980 return notify_disconnection_;
981}
982
[email protected]b2fe07d12010-02-09 14:38:08983void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31984 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52985 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
986 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16987}
988
[email protected]b2fe07d12010-02-09 14:38:08989void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31990 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52991 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
992 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16993}
994
[email protected]0bfbf882011-12-22 18:19:27995content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
996 return &renderer_preferences_;
997}
998
999void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1000 new_tab_start_time_ = time;
1001}
1002
1003base::TimeTicks TabContents::GetNewTabStartTime() const {
1004 return new_tab_start_time_;
1005}
1006
[email protected]7ab1e7d62009-10-14 23:32:011007void TabContents::OnCloseStarted() {
1008 if (tab_close_start_time_.is_null())
1009 tab_close_start_time_ = base::TimeTicks::Now();
1010}
1011
[email protected]46624bf2010-06-09 16:04:191012bool TabContents::ShouldAcceptDragAndDrop() const {
1013#if defined(OS_CHROMEOS)
1014 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1015 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511016 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201017 return false;
1018 return true;
[email protected]46624bf2010-06-09 16:04:191019#else
1020 return true;
1021#endif
1022}
1023
[email protected]7813bd72011-02-05 02:19:341024void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521025 if (GetRenderViewHost())
1026 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511027 if (delegate_)
1028 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341029}
1030
[email protected]0bfbf882011-12-22 18:19:271031void TabContents::SetClosedByUserGesture(bool value) {
1032 closed_by_user_gesture_ = value;
1033}
1034
1035bool TabContents::GetClosedByUserGesture() const {
1036 return closed_by_user_gesture_;
1037}
1038
[email protected]d0b8d092010-10-25 04:05:171039double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:301040 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:251041 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171042 return 0;
[email protected]b75b8292010-10-01 07:28:251043
1044 double zoom_level;
1045 if (temporary_zoom_settings_) {
1046 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521047 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251048 } else {
[email protected]2ae88d12011-10-14 09:11:191049 GURL url;
[email protected]10f417c52011-12-28 21:04:231050 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191051 // Since zoom map is updated using rewritten URL, use rewritten URL
1052 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511053 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191054 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251055 }
[email protected]d0b8d092010-10-25 04:05:171056 return zoom_level;
1057}
[email protected]b75b8292010-10-01 07:28:251058
[email protected]d0b8d092010-10-25 04:05:171059int TabContents::GetZoomPercent(bool* enable_increment,
1060 bool* enable_decrement) {
1061 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011062 // Calculate the zoom percent from the factor. Round up to the nearest whole
1063 // number.
[email protected]b75b8292010-10-01 07:28:251064 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011065 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251066 *enable_decrement = percent > minimum_zoom_percent_;
1067 *enable_increment = percent < maximum_zoom_percent_;
1068 return percent;
1069}
1070
[email protected]3c733bde2010-12-21 19:56:311071void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501072 if (!delegate_)
1073 return;
1074
[email protected]10f417c52011-12-28 21:04:231075 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501076 if (!active_entry)
1077 return;
1078
[email protected]36fc0392011-12-25 03:59:511079 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121080}
1081
[email protected]932b7a12011-03-09 12:50:271082void TabContents::ViewFrameSource(const GURL& url,
1083 const std::string& content_state) {
1084 if (!delegate_)
1085 return;
1086
1087 delegate_->ViewSourceForFrame(this, url, content_state);
1088}
1089
[email protected]0bfbf882011-12-22 18:19:271090int TabContents::GetMinimumZoomPercent() const {
1091 return minimum_zoom_percent_;
1092}
1093
1094int TabContents::GetMaximumZoomPercent() const {
1095 return maximum_zoom_percent_;
1096}
1097
[email protected]bcd2815602012-01-14 18:17:231098gfx::Size TabContents::GetPreferredSize() const {
1099 return preferred_size_;
1100}
1101
[email protected]0bfbf882011-12-22 18:19:271102int TabContents::GetContentRestrictions() const {
1103 return content_restrictions_;
1104}
1105
1106WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501107 WebUIControllerFactory* factory =
1108 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1109 if (!factory)
1110 return WebUI::kNoWebUI;
1111 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271112}
1113
[email protected]01ec4ec2012-01-18 04:13:471114content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271115 // When there is a pending navigation entry, we want to use the pending WebUI
1116 // that goes along with it to control the basic flags. For example, we want to
1117 // show the pending URL in the URL bar, so we want the display_url flag to
1118 // be from the pending entry.
1119 //
1120 // The confusion comes because there are multiple possibilities for the
1121 // initial load in a tab as a side effect of the way the RenderViewHostManager
1122 // works.
1123 //
1124 // - For the very first tab the load looks "normal". The new tab Web UI is
1125 // the pending one, and we want it to apply here.
1126 //
1127 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1128 // get switched to the one previously associated with the new tab pages.
1129 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1130 // have a committed Web UI in this case.
1131 //
1132 // This condition handles all of these cases:
1133 //
1134 // - First load in first tab: no committed nav entry + pending nav entry +
1135 // pending dom ui:
1136 // -> Use pending Web UI if any.
1137 //
1138 // - First load in second tab: no committed nav entry + pending nav entry +
1139 // no pending Web UI:
1140 // -> Use the committed Web UI if any.
1141 //
1142 // - Second navigation in any tab: committed nav entry + pending nav entry:
1143 // -> Use pending Web UI if any.
1144 //
1145 // - Normal state with no load: committed nav entry + no pending nav entry:
1146 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251147 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271148 (controller_.GetLastCommittedEntry() ||
1149 render_manager_.pending_web_ui()))
1150 return render_manager_.pending_web_ui();
1151 return render_manager_.web_ui();
1152}
1153
1154bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1155 return GetRenderViewHost() ?
1156 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1157}
1158
1159bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471160 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271161 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221162 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231163 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511164 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271165 return true;
1166 return false;
1167}
1168
1169void TabContents::SetFocusToLocationBar(bool select_all) {
1170 if (delegate_)
1171 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211172}
1173
[email protected]8b5af492011-11-28 21:50:581174void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301175 const string16& type,
1176 const string16& href,
1177 const string16& title,
1178 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511179 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301180 this, action, type, href, title, disposition);
1181}
1182
[email protected]678105012011-12-09 04:01:211183void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301184 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001185 WebIntentsDispatcherImpl* intents_dispatcher =
1186 new WebIntentsDispatcherImpl(this, intent, intent_id);
1187 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301188}
1189
[email protected]724159a2010-12-30 01:11:181190void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1191 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591192 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181193 const GURL& url) {
1194 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1195 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521196 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301197 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181198
[email protected]8093a542011-05-13 07:29:321199 RenderViewHost* rvh =
1200 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521201 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101202 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251203 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101204 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321205 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101206
[email protected]724159a2010-12-30 01:11:181207 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591208 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251209 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591210 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181211 }
1212}
1213
1214void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591215 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181216 const GURL& source_url,
1217 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491218 // TODO(creis): Remove this method and have the pre-rendering code listen to
1219 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1220 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231221 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181222 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251223 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181224 else
1225 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511226 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181227 return;
[email protected]e7d50892011-01-19 21:47:381228
[email protected]4850a7f2011-03-08 23:36:591229 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251230 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261231 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591232 opener_url));
[email protected]724159a2010-12-30 01:11:181233}
1234
1235void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581236 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1237 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1238 << ", error_code: " << params.error_code
1239 << ", error_description: " << params.error_description
1240 << ", is_main_frame: " << params.is_main_frame
1241 << ", showing_repost_interstitial: " <<
1242 params.showing_repost_interstitial
1243 << ", frame_id: " << params.frame_id;
1244 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521245 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301246 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181247
[email protected]d7b175e2011-10-11 15:31:581248 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181249 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1250 // This means that the interstitial won't be torn down properly, which is
1251 // bad. But if we have an interstitial, go back to another tab type, and
1252 // then load the same interstitial again, we could end up getting the first
1253 // interstitial's "failed" message (as a result of the cancel) when we're on
1254 // the second one.
1255 //
1256 // We can't tell this apart, so we think we're tearing down the current page
1257 // which will cause a crash later one. There is also some code in
1258 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1259 // out because of this problem.
1260 //
1261 // http://code.google.com/p/chromium/issues/detail?id=2855
1262 // Because this will not tear down the interstitial properly, if "back" is
1263 // back to another tab type, the interstitial will still be somewhat alive
1264 // in the previous tab type. If you navigate somewhere that activates the
1265 // tab with the interstitial again, you'll see a flash before the new load
1266 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271267 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181268 LOG(WARNING) << "Discarding message during interstitial.";
1269 return;
1270 }
1271
[email protected]02102f82011-06-13 20:37:021272 // Discard our pending entry if the load canceled (e.g. if we decided to
1273 // download the file instead of load it). We do not verify that the URL
1274 // being canceled matches the pending entry's URL because they will not
1275 // match if a redirect occurred (in which case we do not want to leave a
1276 // stale redirect URL showing). This means that we also cancel the pending
1277 // entry if the user started a new navigation. As a result, the navigation
1278 // controller may not remember that a load is in progress, but the
1279 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251280 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161281 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181282
[email protected]151a63d2011-12-20 22:32:521283 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181284 }
1285
1286 // Send out a notification that we failed a provisional load with an error.
1287 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581288 params.is_main_frame,
1289 controller_.IsURLInPageNavigation(validated_url),
1290 validated_url,
1291 std::string(),
1292 false,
1293 params.frame_id);
1294 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181295
[email protected]ad50def52011-10-19 23:17:071296 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271297 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501298 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531299 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101300
[email protected]d8c660432011-12-22 20:51:251301 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581302 observers_,
1303 DidFailProvisionalLoad(params.frame_id,
1304 params.is_main_frame,
1305 validated_url,
1306 params.error_code,
1307 params.error_description));
[email protected]724159a2010-12-30 01:11:181308}
1309
1310void TabContents::OnDidLoadResourceFromMemoryCache(
1311 const GURL& url,
[email protected]70435962011-08-02 20:13:281312 const std::string& security_info,
1313 const std::string& http_method,
1314 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191315 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181316 cache.Increment();
1317
1318 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081319 int cert_id = 0;
1320 net::CertStatus cert_status = 0;
1321 int security_bits = -1;
1322 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181323 SSLManager::DeserializeSecurityInfo(security_info,
1324 &cert_id, &cert_status,
1325 &security_bits,
1326 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301327 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161328 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181329
[email protected]ad50def52011-10-19 23:17:071330 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271331 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501332 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531333 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181334}
1335
1336void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381337 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181338 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201339 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181340}
1341
1342void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021343 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231344 LOG(INFO) << security_origin << " ran insecure content from "
1345 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381346 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051347 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381348 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051349 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1350 }
[email protected]71fde352011-12-29 03:29:561351 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411352 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201353 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181354}
1355
1356void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1357 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251358 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101359 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181360}
1361
[email protected]1a55c5be2011-11-29 11:36:311362void TabContents::OnDidFinishLoad(
1363 int64 frame_id,
1364 const GURL& validated_url,
1365 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251366 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311367 DidFinishLoad(frame_id, validated_url, is_main_frame));
1368}
1369
1370void TabContents::OnDidFailLoadWithError(int64 frame_id,
1371 const GURL& validated_url,
1372 bool is_main_frame,
1373 int error_code,
1374 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251375 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311376 DidFailLoad(frame_id, validated_url, is_main_frame,
1377 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181378}
1379
[email protected]c8f73ab2011-01-22 00:05:171380void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271381 content_restrictions_ = restrictions;
1382 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171383}
1384
[email protected]216813952011-05-19 22:21:261385void TabContents::OnGoToEntryAtOffset(int offset) {
1386 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231387 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251388 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261389 if (!entry)
1390 return;
1391 // Note that we don't call NavigationController::GotToOffset() as we don't
1392 // want to create a pending navigation entry (it might end up lingering
1393 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251394 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581395 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511396 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581397 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471398 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571399
1400 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1401 // it in now that we know. This allows us to find the entry when it commits.
1402 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231403 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331404 entry->set_site_instance(
1405 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571406 }
[email protected]216813952011-05-19 22:21:261407 }
1408}
1409
1410void TabContents::OnUpdateZoomLimits(int minimum_percent,
1411 int maximum_percent,
1412 bool remember) {
1413 minimum_zoom_percent_ = minimum_percent;
1414 maximum_zoom_percent_ = maximum_percent;
1415 temporary_zoom_settings_ = !remember;
1416}
1417
[email protected]0bfbf882011-12-22 18:19:271418void TabContents::OnSaveURL(const GURL& url) {
1419 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1420 dlm->DownloadUrl(url, GetURL(), "", this);
1421}
1422
[email protected]3a29a6e2011-08-24 18:26:211423void TabContents::OnEnumerateDirectory(int request_id,
1424 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511425 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211426}
1427
[email protected]7d189022011-08-25 22:54:201428void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511429 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201430}
1431
1432void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1433 const GURL& url,
1434 const string16& title) {
[email protected]6934a702011-12-20 00:04:511435 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201436}
1437
[email protected]b888919c2011-09-02 00:32:161438void TabContents::OnFindReply(int request_id,
1439 int number_of_matches,
1440 const gfx::Rect& selection_rect,
1441 int active_match_ordinal,
1442 bool final_update) {
[email protected]6934a702011-12-20 00:04:511443 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1444 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001445 // Send a notification to the renderer that we are ready to receive more
1446 // results from the scoping effort of the Find operation. The FindInPage
1447 // scoping is asynchronous and periodically sends results back up to the
1448 // browser using IPC. In an effort to not spam the browser we have the
1449 // browser send an ACK for each FindReply message and have the renderer
1450 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521451 GetRenderViewHost()->Send(
1452 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161453}
1454
[email protected]d952a052011-09-06 18:42:451455void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511456 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451457}
1458
[email protected]7fc4bbb2011-09-08 21:23:101459void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1460 bool blocked_by_policy) {
1461 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251462 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101463 AppCacheAccessed(manifest_url, blocked_by_policy));
1464}
1465
[email protected]96d185d2009-04-24 03:28:541466// Notifies the RenderWidgetHost instance about the fact that the page is
1467// loading, or done loading and calls the base implementation.
1468void TabContents::SetIsLoading(bool is_loading,
1469 LoadNotificationDetails* details) {
1470 if (is_loading == is_loading_)
1471 return;
1472
1473 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211474 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541475 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561476 upload_size_ = 0;
1477 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541478 }
1479
1480 render_manager_.SetIsLoading(is_loading);
1481
1482 is_loading_ = is_loading;
1483 waiting_for_response_ = is_loading;
1484
[email protected]6ebdc9b2010-09-27 16:55:571485 if (delegate_)
1486 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461487 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541488
[email protected]432115822011-07-10 15:52:271489 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1490 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071491 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541492 if (details)
[email protected]6c2381d2011-10-19 02:52:531493 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071494 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501495 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541496 det);
1497}
1498
[email protected]420ae012009-04-24 05:16:321499void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131500 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321501 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561502 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381503 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441504 // that opened the window, as long as both renderers have the same
1505 // privileges.
[email protected]1fd1a502011-03-30 16:55:561506 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561507 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581508 // web_ui might be NULL if the URL refers to a non-existent extension.
1509 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401510 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521511 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441512 }
1513 }
[email protected]1fd1a502011-03-30 16:55:561514 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441515 }
1516
[email protected]4e697b042011-07-08 06:44:561517 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321518 // Clear the status bubble. This is a workaround for a bug where WebKit
1519 // doesn't let us know that the cursor left an element during a
1520 // transition (this is also why the mouse cursor remains as a hand after
1521 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1522 // clear the bubble when a user navigates to a named anchor in the same
1523 // page.
[email protected]36fc0392011-12-25 03:59:511524 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321525 }
1526
[email protected]a6e82fc2010-02-24 22:28:141527 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471528 // Once the main frame is navigated, we're no longer considered to have
1529 // displayed insecure content.
1530 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171531 }
[email protected]ce5c4502009-05-06 16:46:111532
[email protected]3c9e1872010-11-18 16:17:491533 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251534 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041535 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321536}
1537
1538void TabContents::DidNavigateAnyFramePostCommit(
1539 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131540 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321541 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061542 // If we navigate off the page, reset JavaScript state. This does nothing
1543 // to prevent a malicious script from spamming messages, since the script
1544 // could just reload the page to stop blocking.
1545 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551546 dialog_creator_->ResetJavaScriptState(this);
1547 dialog_creator_ = NULL;
1548 }
[email protected]420ae012009-04-24 05:16:321549
[email protected]3c9e1872010-11-18 16:17:491550 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251551 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041552 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321553}
1554
[email protected]74ce1ad2011-12-16 21:51:461555void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1556 // If we are creating a RVH for a restored controller, then we need to make
1557 // sure the RenderView starts with a next_page_id_ larger than the number
1558 // of restored entries. This must be called before the RenderView starts
1559 // navigating (to avoid a race between the browser updating max_page_id and
1560 // the renderer updating next_page_id_). Because of this, we only call this
1561 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561562 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461563 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1564 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321565}
1566
[email protected]10f417c52011-12-28 21:04:231567bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571568 const string16& title) {
[email protected]420ae012009-04-24 05:16:321569 // For file URLs without a title, use the pathname instead. In the case of a
1570 // synthesized title, we don't want the update to count toward the "one set
1571 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511572 string16 final_title;
[email protected]420ae012009-04-24 05:16:321573 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511574 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1575 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321576 explicit_set = false; // Don't count synthetic titles toward the set limit.
1577 } else {
[email protected]acafd272011-07-26 17:35:571578 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321579 explicit_set = true;
1580 }
1581
[email protected]987fc3a2011-05-26 14:18:091582 // If a page is created via window.open and never navigated,
1583 // there will be no navigation entry. In this situation,
1584 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1585 if (entry) {
[email protected]36fc0392011-12-25 03:59:511586 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091587 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321588
[email protected]36fc0392011-12-25 03:59:511589 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091590 } else {
1591 if (page_title_when_no_navigation_entry_ == final_title)
1592 return false; // Nothing changed, don't bother.
1593
1594 page_title_when_no_navigation_entry_ = final_title;
1595 }
[email protected]420ae012009-04-24 05:16:321596
[email protected]420ae012009-04-24 05:16:321597 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231598 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321599
[email protected]105bb0f2011-05-24 17:12:141600 TitleUpdatedDetails details(entry, explicit_set);
1601
[email protected]ad50def52011-10-19 23:17:071602 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441603 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1604 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531605 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041606
[email protected]420ae012009-04-24 05:16:321607 return true;
1608}
1609
1610void TabContents::NotifySwapped() {
1611 // After sending out a swap notification, we need to send a disconnect
1612 // notification so that clients that pick up a pointer to |this| can NULL the
1613 // pointer. See Bug 1230284.
1614 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071615 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201616 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1617 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071618 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321619}
1620
1621void TabContents::NotifyConnected() {
1622 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071623 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121624 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1625 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071626 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321627}
1628
1629void TabContents::NotifyDisconnected() {
1630 if (!notify_disconnection_)
1631 return;
1632
1633 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071634 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321635 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1636 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071637 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321638}
1639
[email protected]8d3347f2009-07-09 22:00:211640RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321641 return view_.get();
1642}
1643
[email protected]8d3347f2009-07-09 22:00:211644RenderViewHostDelegate::RendererManagement*
1645TabContents::GetRendererManagementDelegate() {
1646 return &render_manager_;
1647}
1648
[email protected]daf82f82011-10-31 22:35:311649content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371650 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461651 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511652}
1653
[email protected]768c5472011-12-26 19:06:171654WebContents* TabContents::GetAsWebContents() {
1655 return this;
1656}
1657
[email protected]da4dfc42011-10-12 15:53:561658content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431659 return view_type_;
[email protected]7b291f92009-08-14 05:43:531660}
1661
[email protected]b7a756d42012-01-23 18:08:171662gfx::Rect TabContents::GetRootWindowResizerRect() const {
1663 if (delegate_)
1664 return delegate_->GetRootWindowResizerRect();
1665 return gfx::Rect();
1666}
1667
[email protected]420ae012009-04-24 05:16:321668void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071669 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271670 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321671 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531672 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231673 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321674 if (!entry)
1675 return;
1676
1677 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351678 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561679 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581680 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321681
1682 if (entry->IsViewSourceMode()) {
1683 // Put the renderer in view source mode.
1684 render_view_host->Send(
1685 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1686 }
[email protected]0666aef2009-05-13 19:48:081687
[email protected]d487beefe2011-12-21 05:41:211688 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261689
1690 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251691 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321692}
1693
1694void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521695 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321696 // Don't notify the world, since this came from a renderer in the
1697 // background.
1698 return;
1699 }
1700
1701 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311702 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231703 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301704
1705 // Restore the focus to the tab (otherwise the focus will be on the top
1706 // window).
[email protected]484ae5912010-09-29 19:16:141707 if (was_crashed && !FocusLocationBarByDefault() &&
1708 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301709 Focus();
[email protected]484ae5912010-09-29 19:16:141710 }
[email protected]32ded2212011-11-10 18:51:431711
[email protected]d8c660432011-12-22 20:51:251712 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321713}
1714
[email protected]443b80e2010-12-14 00:42:231715void TabContents::RenderViewGone(RenderViewHost* rvh,
1716 base::TerminationStatus status,
1717 int error_code) {
[email protected]151a63d2011-12-20 22:32:521718 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321719 // The pending page's RenderViewHost is gone.
1720 return;
1721 }
1722
1723 SetIsLoading(false, NULL);
1724 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231725 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311726 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321727
[email protected]d8c660432011-12-22 20:51:251728 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271729 observers_,
[email protected]be1f56ab2011-12-22 06:55:311730 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]2e4633c2009-07-09 16:58:061733void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481734 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251735 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061736}
1737
[email protected]420ae012009-04-24 05:16:321738void TabContents::DidNavigate(RenderViewHost* rvh,
1739 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581740 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321741 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371742
[email protected]420ae012009-04-24 05:16:321743 // Update the site of the SiteInstance if it doesn't have one yet.
[email protected]b6583592012-01-25 19:52:331744 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite())
1745 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]420ae012009-04-24 05:16:321746
1747 // Need to update MIME type here because it's referred to in
1748 // UpdateNavigationCommands() called by RendererDidNavigate() to
1749 // determine whether or not to enable the encoding menu.
1750 // It's updated only for the main frame. For a subframe,
1751 // RenderView::UpdateURL does not set params.contents_mime_type.
1752 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1753 // TODO(jungshik): Add a test for the encoding menu to avoid
1754 // regressing it again.
[email protected]2905f742011-10-13 03:51:581755 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321756 contents_mime_type_ = params.contents_mime_type;
1757
[email protected]8286f51a2011-05-31 17:39:131758 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001759 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391760
[email protected]a9c0bfe2010-09-17 08:35:221761 // Send notification about committed provisional loads. This notification is
1762 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1763 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081764 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071765 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1766 // that is not recorded in the navigation history. For the purpose of
1767 // tracking navigation events, we treat this event as a sub frame navigation
1768 // event.
1769 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581770 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221771 // Whether or not a page transition was triggered by going backward or
1772 // forward in the history is only stored in the navigation controller's
1773 // entry list.
1774 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511775 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581776 content::PAGE_TRANSITION_FORWARD_BACK)) {
1777 transition_type = content::PageTransitionFromInt(
1778 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221779 }
[email protected]0d60f0192011-04-14 12:40:101780 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251781 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101782 DidCommitProvisionalLoadForFrame(params.frame_id,
1783 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221784 }
1785
[email protected]76543b92009-08-31 17:27:451786 if (!did_navigate)
1787 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321788
1789 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1790 // for the appropriate notification (best) or you can add it to
1791 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1792 // necessary, please).
1793
1794 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001795 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321796 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511797 if (delegate_)
1798 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001799 }
[email protected]420ae012009-04-24 05:16:321800 DidNavigateAnyFramePostCommit(rvh, details, params);
1801}
1802
1803void TabContents::UpdateState(RenderViewHost* rvh,
1804 int32 page_id,
1805 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151806 // Ensure that this state update comes from either the active RVH or one of
1807 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521808 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321809
1810 // We must be prepared to handle state updates for any page, these occur
1811 // when the user is scrolling and entering form data, as well as when we're
1812 // leaving a page, in which case our state may have already been moved to
1813 // the next page. The navigation controller will look up the appropriate
1814 // NavigationEntry and update it when it is notified via the delegate.
1815
1816 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151817 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321818 if (entry_index < 0)
1819 return;
[email protected]10f417c52011-12-28 21:04:231820 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321821
[email protected]36fc0392011-12-25 03:59:511822 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321823 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511824 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321825 controller_.NotifyEntryChanged(entry, entry_index);
1826}
1827
1828void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571829 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461830 const string16& title,
1831 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321832 // If we have a title, that's a pretty good indication that we've started
1833 // getting useful data.
1834 SetNotWaitingForResponse();
1835
[email protected]151a63d2011-12-20 22:32:521836 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231837 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1838 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091839
[email protected]a49e10b2011-08-01 23:57:461840 // TODO(evan): make use of title_direction.
1841 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091842 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321843 return;
1844
1845 // Broadcast notifications when the UI should be updated.
1846 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:461847 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:321848}
1849
[email protected]420ae012009-04-24 05:16:321850void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401851 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311852 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321853}
1854
1855void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511856 if (delegate_)
1857 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321858}
1859
[email protected]420ae012009-04-24 05:16:321860void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291861 // The UI may be in an event-tracking loop, such as between the
1862 // mouse-down and mouse-up in text selection or a button click.
1863 // Defer the close until after tracking is complete, so that we
1864 // don't free objects out from under the UI.
1865 // TODO(shess): This could probably be integrated with the
1866 // IsDoingDrag() test below. Punting for now because I need more
1867 // research to understand how this impacts platforms other than Mac.
1868 // TODO(shess): This could get more fine-grained. For instance,
1869 // closing a tab in another window while selecting text in the
1870 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211871 if (GetView()->IsEventTracking()) {
1872 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291873 return;
1874 }
1875
[email protected]24a4d1062009-07-10 23:10:421876 // If we close the tab while we're in the middle of a drag, we'll crash.
1877 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211878 if (GetView()->IsDoingDrag()) {
1879 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421880 return;
1881 }
1882
[email protected]420ae012009-04-24 05:16:321883 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521884 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511885 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321886}
1887
[email protected]cd9ed79d2011-11-15 19:22:571888void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521889 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511890 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571891}
1892
[email protected]420ae012009-04-24 05:16:321893void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511894 if (delegate_ && delegate_->IsPopupOrPanel(this))
1895 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321896}
1897
[email protected]7ab1e7d62009-10-14 23:32:011898void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321899 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491900
[email protected]6934a702011-12-20 00:04:511901 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211902 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511903 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001904 }
[email protected]3c9e1872010-11-18 16:17:491905
1906 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251907 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321908}
1909
[email protected]7ab1e7d62009-10-14 23:32:011910void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321911 scoped_ptr<LoadNotificationDetails> details;
1912
[email protected]10f417c52011-12-28 21:04:231913 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321914 // An entry may not exist for a stop when loading an initial blank page or
1915 // if an iframe injected by script into a blank page finishes loading.
1916 if (entry) {
[email protected]420ae012009-04-24 05:16:321917 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1918
1919 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511920 entry->GetVirtualURL(),
1921 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321922 elapsed,
1923 &controller_,
1924 controller_.GetCurrentEntryIndex()));
1925 }
1926
[email protected]420ae012009-04-24 05:16:321927 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491928
1929 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251930 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321931}
1932
[email protected]c95fa8b2011-04-28 20:26:161933void TabContents::DidCancelLoading() {
1934 controller_.DiscardNonCommittedEntries();
1935
1936 // Update the URL display.
[email protected]d9083482012-01-06 00:38:461937 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:161938}
1939
[email protected]1a3c3cb2010-12-16 21:03:401940void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511941 if (delegate_)
1942 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401943}
1944
[email protected]952a68e2011-11-17 00:36:101945void TabContents::DocumentAvailableInMainFrame(
1946 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101948 DocumentAvailableInMainFrame());
1949}
1950
[email protected]25497492010-09-11 15:15:081951void TabContents::DocumentOnLoadCompletedInMainFrame(
1952 RenderViewHost* render_view_host,
1953 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071954 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271955 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321956 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531957 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081958}
1959
[email protected]ae5184d62011-10-06 19:25:581960void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151961 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581962 WindowOpenDisposition disposition,
1963 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481964 // Delegate to RequestTransferURL because this is just the generic
1965 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581966 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481967 GlobalRequestID());
1968}
1969
1970void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581971 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481972 WindowOpenDisposition disposition,
1973 int64 source_frame_id,
1974 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201975 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581976 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581977 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351978 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321979 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1980 // generated suggestions).
1981 //
[email protected]e0112912011-02-02 22:54:351982 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161983 // want web sites to see a referrer of "chrome://blah" (and some
1984 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321985 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581986 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]c63cedf22012-01-17 18:42:221987 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:481988 false /* is_renderer_initiated */);
1989 params.transferred_global_request_id = old_request_id;
1990 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:221991 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:321992 } else {
[email protected]4ad5d77d2011-12-03 02:00:481993 OpenURLParams params(url, referrer, disposition,
1994 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1995 params.transferred_global_request_id = old_request_id;
1996 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581997 }
1998 if (new_contents) {
1999 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582001 DidOpenRequestedURL(new_contents,
2002 url,
2003 referrer,
2004 disposition,
2005 transition_type,
2006 source_frame_id));
[email protected]420ae012009-04-24 05:16:322007 }
2008}
2009
[email protected]420ae012009-04-24 05:16:322010void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:152011 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412012 const string16& message,
2013 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322014 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472015 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322016 IPC::Message* reply_msg,
2017 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072018 // Suppress JavaScript dialogs when requested. Also suppress messages when
2019 // showing an interstitial as it's shown over the previous page and we don't
2020 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502021 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152022 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272023 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072024 !delegate_ ||
2025 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:322026
2027 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342028 content::JavaScriptDialogCreator::TitleType title_type;
2029 string16 title;
2030
2031 if (!frame_url.has_host()) {
2032 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2033 } else {
2034 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2035 title = net::FormatUrl(
2036 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202037 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302038 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342039 }
2040
[email protected]2e5b90c2011-08-16 21:11:552041 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2042 dialog_creator_->RunJavaScriptDialog(this,
2043 title_type,
2044 title,
[email protected]269f86d2011-12-07 02:43:472045 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:552046 message,
2047 default_prompt,
2048 reply_msg,
2049 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322050 }
[email protected]3ab9cb82011-06-03 18:02:072051
2052 if (suppress_this_message) {
2053 // If we are suppressing messages, just reply as if the user immediately
2054 // pressed "Cancel".
2055 OnDialogClosed(reply_msg, false, string16());
2056 }
2057
2058 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322059}
2060
[email protected]992db4c2011-05-12 15:37:152061void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412062 const string16& message,
[email protected]420ae012009-04-24 05:16:322063 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512064 if (delegate_)
2065 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072066
2067 bool suppress_this_message =
2068 rvh->is_swapped_out() ||
2069 !delegate_ ||
2070 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152071 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522072 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502073 return;
2074 }
[email protected]3ab9cb82011-06-03 18:02:072075
[email protected]7ab1e7d62009-10-14 23:32:012076 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552077 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2078 dialog_creator_->RunBeforeUnloadDialog(this,
2079 message,
2080 reply_msg);
[email protected]420ae012009-04-24 05:16:322081}
2082
[email protected]420ae012009-04-24 05:16:322083WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082084 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362085 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522086 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082087
[email protected]b8299c12011-06-03 19:52:282088 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212089 // chrome-devtools: pages (unless it's specifically allowed).
2090 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572091 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282092 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302093 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2094 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212095 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082096 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432097 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082098 }
2099
2100 return web_prefs;
[email protected]420ae012009-04-24 05:16:322101}
2102
[email protected]7d472472011-01-22 01:30:252103void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272104 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252105 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222106
[email protected]99907362012-01-11 05:41:402107 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172108 if (rdh) // NULL in unittests.
2109 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252110}
2111
[email protected]fa1cf0b82010-01-15 21:49:442112void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442113 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252114 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442115}
2116
[email protected]420ae012009-04-24 05:16:322117void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2118 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152119 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522120 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152121 return;
2122
[email protected]e5fc1632011-08-08 07:51:532123 // Ignore renderer unresponsive event if debugger is attached to the tab
2124 // since the event may be a result of the renderer sitting on a breakpoint.
2125 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442126 DevToolsAgentHost* agent =
2127 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2128 if (agent &&
2129 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532130 return;
2131
[email protected]420ae012009-04-24 05:16:322132 if (is_during_unload) {
2133 // Hang occurred while firing the beforeunload/unload handler.
2134 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112135 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322136
2137 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2138 return;
2139
2140 // If the tab hangs in the beforeunload/unload handler there's really
2141 // nothing we can do to recover. Pretend the unload listeners have
2142 // all fired and close the tab. If the hang is in the beforeunload handler
2143 // then the user will not have the option of cancelling the close.
2144 Close(rvh);
2145 return;
2146 }
2147
[email protected]151a63d2011-12-20 22:32:522148 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472149 return;
2150
[email protected]6934a702011-12-20 00:04:512151 if (delegate_)
2152 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322153}
2154
2155void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512156 if (delegate_)
2157 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322158}
2159
2160void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212161 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562162 uint64 upload_position,
2163 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322164 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562165 upload_position_ = upload_position;
2166 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502167 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202168 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302169 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212170 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322171 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462172 if (IsLoading()) {
2173 NotifyNavigationStateChanged(
2174 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2175 }
[email protected]420ae012009-04-24 05:16:322176}
2177
[email protected]7d472472011-01-22 01:30:252178void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512179 if (delegate_)
2180 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252181}
2182
[email protected]420ae012009-04-24 05:16:322183void TabContents::BeforeUnloadFiredFromRenderManager(
2184 bool proceed,
2185 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512186 if (delegate_)
2187 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322188}
2189
[email protected]3a3d47472010-07-15 21:03:542190void TabContents::DidStartLoadingFromRenderManager(
2191 RenderViewHost* render_view_host) {
2192 DidStartLoading();
2193}
2194
2195void TabContents::RenderViewGoneFromRenderManager(
2196 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232197 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2198 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542199}
2200
[email protected]420ae012009-04-24 05:16:322201void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102202 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262203 gfx::Size size = view_->GetContainerSize();
2204 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2205 // here during container initialization and normal window size will be set
2206 // later. In case of tab duplication this resizing to 0x0 prevents setting
2207 // normal size later so just ignore it.
2208 if (!size.IsEmpty())
2209 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322210}
2211
[email protected]3a3d47472010-07-15 21:03:542212void TabContents::NotifySwappedFromRenderManager() {
2213 NotifySwapped();
2214}
2215
[email protected]d202a7c2012-01-04 07:53:472216NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202217 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542218}
2219
[email protected]d2353452012-01-19 19:53:562220WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2221 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322222}
2223
[email protected]10f417c52011-12-28 21:04:232224NavigationEntry*
2225 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322226 return controller_.GetLastCommittedEntry();
2227}
2228
2229bool TabContents::CreateRenderViewForRenderManager(
2230 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442231 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322232 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522233
[email protected]420ae012009-04-24 05:16:322234 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442235 if (rwh_view)
2236 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322237
[email protected]74ce1ad2011-12-16 21:51:462238 // Make sure we use the correct starting page_id in the new RenderView.
2239 UpdateMaxPageIDIfNecessary(render_view_host);
2240 int32 max_page_id =
2241 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2242
2243 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522244 return false;
2245
[email protected]e60c0232011-11-11 19:56:352246#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502247 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2248 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442249 if (rwh_view) {
2250 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2251 render_widget_host->WasResized();
2252 }
[email protected]f8233cc2011-05-31 20:24:502253#endif
2254
[email protected]420ae012009-04-24 05:16:322255 return true;
2256}
2257
[email protected]3ab9cb82011-06-03 18:02:072258void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2259 bool success,
2260 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542261 if (is_showing_before_unload_dialog_ && !success) {
2262 // If a beforeunload dialog is canceled, we need to stop the throbber from
2263 // spinning, since we forced it to start spinning in Navigate.
2264 DidStopLoading();
2265
2266 tab_close_start_time_ = base::TimeTicks();
2267 }
2268 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522269 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542270}
2271
[email protected]0b08add2011-11-29 03:27:062272gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072273 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542274}
2275
[email protected]a1e97f02011-06-30 14:04:342276void TabContents::OnDialogShown() {
2277 Activate();
[email protected]3a3d47472010-07-15 21:03:542278}
2279
[email protected]be1f56ab2011-12-22 06:55:312280void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122281 encoding_ = content::GetContentClient()->browser()->
2282 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102283}
[email protected]f45d2a72010-03-08 23:28:352284
[email protected]33f74972010-12-08 16:40:362285void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212286 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442287 // Can be NULL during tests.
2288 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212289 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362290}