blob: b6c4e8517fdebc88e063d710499232a8361047e9 [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]f3f3b722012-01-07 01:29:4349#include "content/public/browser/web_ui_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]0e47edc2011-11-22 08:01:02106//
107// It is possible that we trigger a new navigation after we have received
108// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
109// In this case the old RVH has been swapped out but the new one has not
110// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
111// of the old RVH.
[email protected]420ae012009-04-24 05:16:32112
[email protected]0e12d7d2011-12-01 16:21:44113using content::DevToolsAgentHost;
114using content::DevToolsAgentHostRegistry;
115using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17116using content::DownloadItem;
117using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20118using content::GlobalRequestID;
[email protected]c5eed492012-01-04 17:07:50119using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23120using content::NavigationEntry;
121using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20122using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57123using content::RenderViewHostDelegate;
[email protected]b6583592012-01-25 19:52:33124using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17125using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38126using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09127using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25128using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56129using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22130using content::WebUIController;
[email protected]0e12d7d2011-12-01 16:21:44131
[email protected]420ae012009-04-24 05:16:32132namespace {
133
134// Amount of time we wait between when a key event is received and the renderer
135// is queried for its state and pushed to the NavigationEntry.
136const int kQueryStateDelay = 5000;
137
[email protected]6ebdc9b2010-09-27 16:55:57138const int kSyncWaitDelay = 40;
139
[email protected]ca406032011-07-19 21:53:05140static const char kDotGoogleDotCom[] = ".google.com";
141
[email protected]420ae012009-04-24 05:16:32142#if defined(OS_WIN)
143
144BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
145 // Note: erase is required to properly paint some widgets borders. This can
146 // be seen with textfields.
147 InvalidateRect(hwnd, NULL, TRUE);
148 return TRUE;
149}
150#endif
151
[email protected]2c5569662011-03-22 20:45:02152ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23153 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50154 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16155 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47156 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02157 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47158 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02159 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47160 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16161 break; // Fall through to rest of function.
162 }
[email protected]5e369672009-11-03 23:48:30163
[email protected]10f417c52011-12-28 21:04:23164 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37165 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02166 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30167
[email protected]2c5569662011-03-22 20:45:02168 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30169}
170
[email protected]10f417c52011-12-28 21:04:23171void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47172 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42173 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50174 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16175 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51176 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54177 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55178 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
179 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51180 params->url = entry.GetURL();
181 params->referrer = entry.GetReferrer();
182 params->transition = entry.GetTransitionType();
183 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00184 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55185 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34186 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47187 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48188 params->transferred_request_child_id =
189 entry.transferred_global_request_id().child_id;
190 params->transferred_request_request_id =
191 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47192
193 if (delegate)
194 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34195}
196
[email protected]420ae012009-04-24 05:16:32197} // namespace
198
[email protected]a81343d232011-12-27 07:39:20199namespace content {
200
201WebContents* WebContents::Create(
202 BrowserContext* browser_context,
203 SiteInstance* site_instance,
204 int routing_id,
205 const WebContents* base_tab_contents,
206 SessionStorageNamespace* session_storage_namespace) {
207 return new TabContents(browser_context,
208 site_instance,
209 routing_id,
210 static_cast<const TabContents*>(base_tab_contents),
211 session_storage_namespace);
212}
213}
[email protected]f4f50ef2011-01-21 19:01:19214
215// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32216
[email protected]3d7474ff2011-07-27 17:47:37217TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32218 SiteInstance* site_instance,
219 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07220 const TabContents* base_tab_contents,
221 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42222 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07223 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37224 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13225 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10226 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22227 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34228 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23229 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
230 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34231 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21232 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56233 upload_size_(0),
234 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47235 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57236 capturing_contents_(false),
237 is_being_destroyed_(false),
238 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55239 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57240#if defined(OS_WIN)
241 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
242#endif
[email protected]7ab1e7d62009-10-14 23:32:01243 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56244 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38245 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25246 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01247 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25248 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01249 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00250 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43251 content_restrictions_(0),
252 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37253 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32254
[email protected]34ac70502009-09-25 17:07:23255 // We have the initial size of the view be based on the size of the passed in
256 // tab contents (normally a tab from the same window).
257 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21258 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00259
260#if defined(ENABLE_JAVA_BRIDGE)
261 java_bridge_dispatcher_host_manager_.reset(
262 new JavaBridgeDispatcherHostManager(this));
263#endif
[email protected]332af7732009-03-11 13:21:35264}
initial.commit09911bf2008-07-26 23:55:29265
266TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32267 is_being_destroyed_ = true;
268
[email protected]3ab9cb82011-06-03 18:02:07269 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55270 if (dialog_creator_)
271 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07272
[email protected]420ae012009-04-24 05:16:32273 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32274
[email protected]420ae012009-04-24 05:16:32275 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07276 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09277 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
278 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07279 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32280
281 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07282#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32283 // If we still have a window handle, destroy it. GetNativeView can return
284 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42285 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52286 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44287 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42288 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42289 }
[email protected]420ae012009-04-24 05:16:32290#endif
[email protected]7ab1e7d62009-10-14 23:32:01291
292 // OnCloseStarted isn't called in unit tests.
293 if (!tab_close_start_time_.is_null()) {
294 UMA_HISTOGRAM_TIMES("Tab.Close",
295 base::TimeTicks::Now() - tab_close_start_time_);
296 }
[email protected]b5a1d11c2011-02-17 03:09:42297
[email protected]d8c660432011-12-22 20:51:25298 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08299
[email protected]6934a702011-12-20 00:04:51300 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42301}
302
[email protected]d202a7c2012-01-04 07:53:47303NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20304 return controller_;
305}
306
[email protected]765187182012-01-11 23:59:28307RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
308 return &render_manager_;
309}
310
[email protected]724159a2010-12-30 01:11:18311bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56312 if (GetWebUI() &&
313 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17314 return true;
[email protected]d2353452012-01-19 19:53:56315 }
[email protected]f82d57b52011-04-27 19:13:17316
[email protected]d8c660432011-12-22 20:51:25317 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
318 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10319 while ((observer = it.GetNext()) != NULL)
320 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53321 return true;
[email protected]403415a2011-01-10 18:57:53322
[email protected]724159a2010-12-30 01:11:18323 bool handled = true;
324 bool message_is_ok = true;
325 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58326 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
327 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24328 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
329 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18330 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
331 OnDidStartProvisionalLoadForFrame)
332 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
333 OnDidRedirectProvisionalLoad)
334 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
335 OnDidFailProvisionalLoadWithError)
336 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
337 OnDidLoadResourceFromMemoryCache)
338 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
339 OnDidDisplayInsecureContent)
340 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
341 OnDidRunInsecureContent)
342 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
343 OnDocumentLoadedInFrame)
344 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17345 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
346 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25347 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26348 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59349 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21350 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20351 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
352 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
353 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16354 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45355 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10356 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18357 IPC_MESSAGE_UNHANDLED(handled = false)
358 IPC_END_MESSAGE_MAP_EX()
359
360 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38361 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18362 GetRenderProcessHost()->ReceivedBadMessage();
363 }
364
365 return handled;
366}
367
[email protected]6c2e472f2011-08-24 23:26:18368void TabContents::RunFileChooser(
369 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23370 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51371 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18372}
373
[email protected]c5eed492012-01-04 17:07:50374NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56375 return controller_;
376}
377
[email protected]c5eed492012-01-04 17:07:50378const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56379 return controller_;
380}
381
[email protected]627e0512011-12-21 22:55:30382content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55383 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30384}
385
[email protected]f5fa20e2011-12-21 22:35:56386void TabContents::SetViewType(content::ViewType type) {
387 view_type_ = type;
388}
389
[email protected]ea049a02011-12-25 21:37:09390content::ViewType TabContents::GetViewType() const {
391 return view_type_;
392}
393
[email protected]be1f56ab2011-12-22 06:55:31394const GURL& TabContents::GetURL() const {
395 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23396 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51397 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31398}
399
400
401const base::PropertyBag* TabContents::GetPropertyBag() const {
402 return &property_bag_;
403}
404
405base::PropertyBag* TabContents::GetPropertyBag() {
406 return &property_bag_;
407}
408
409content::WebContentsDelegate* TabContents::GetDelegate() {
410 return delegate_;
411}
412
413void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
414 // TODO(cbentzel): remove this debugging code?
415 if (delegate == delegate_)
416 return;
417 if (delegate_)
418 delegate_->Detach(this);
419 delegate_ = delegate;
420 if (delegate_)
421 delegate_->Attach(this);
422}
423
[email protected]f3b1a082011-11-18 00:34:30424content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03425 if (render_manager_.current_host())
426 return render_manager_.current_host()->process();
427 else
428 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16429}
430
[email protected]be1f56ab2011-12-22 06:55:31431RenderViewHost* TabContents::GetRenderViewHost() const {
432 return render_manager_.current_host();
433}
434
435RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
436 return render_manager_.GetRenderWidgetHostView();
437}
438
[email protected]8643e6d2012-01-18 20:26:10439content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31440 return view_.get();
441}
442
[email protected]01ec4ec2012-01-18 04:13:47443content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56444 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22445 WebUIController* controller =
446 content::GetContentClient()->browser()->GetWebUIFactory()->
447 CreateWebUIForURL(web_ui, url);
448 if (controller) {
449 web_ui->SetController(controller);
450 return web_ui;
451 }
452
453 delete web_ui;
454 return NULL;
455}
456
[email protected]01ec4ec2012-01-18 04:13:47457content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31458 return render_manager_.web_ui() ? render_manager_.web_ui()
459 : render_manager_.pending_web_ui();
460}
461
[email protected]01ec4ec2012-01-18 04:13:47462content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31463 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34464}
465
[email protected]96d185d2009-04-24 03:28:54466const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55467 // Transient entries take precedence. They are used for interstitial pages
468 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23469 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08470 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20471 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30472 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23473 if (entry) {
[email protected]b5cca982011-05-26 04:42:08474 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23475 }
[email protected]7ade2732011-02-10 00:13:58476 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
477 render_manager_.pending_web_ui() : render_manager_.web_ui();
478 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54479 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55480 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54481 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35482 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22483 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54484 if (!title.empty())
485 return title;
486 }
487 }
488
489 // We use the title for the last committed entry rather than a pending
490 // navigation entry. For example, when the user types in a URL, we want to
491 // keep the old page's title until the new load has committed and we get a new
492 // title.
[email protected]96d185d2009-04-24 03:28:54493 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23494 if (entry) {
[email protected]b5cca982011-05-26 04:42:08495 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23496 }
[email protected]987fc3a2011-05-26 14:18:09497
498 // |page_title_when_no_navigation_entry_| is finally used
499 // if no title cannot be retrieved.
500 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54501}
502
[email protected]d5f942ba2008-09-26 19:30:34503int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46504 return GetMaxPageIDForSiteInstance(GetSiteInstance());
505}
506
507int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33508 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
509 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46510
[email protected]b6583592012-01-25 19:52:33511 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34512}
513
514void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46515 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
516}
517
[email protected]b6583592012-01-25 19:52:33518void TabContents::UpdateMaxPageIDForSiteInstance(
519 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46520 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33521 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34522}
523
[email protected]91854cd2012-01-10 19:43:57524void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
525 max_page_ids_ = tab_contents->max_page_ids_;
526}
527
[email protected]96d185d2009-04-24 03:28:54528SiteInstance* TabContents::GetSiteInstance() const {
529 return render_manager_.current_host()->site_instance();
530}
531
[email protected]77362eb2011-08-01 17:18:38532SiteInstance* TabContents::GetPendingSiteInstance() const {
533 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
534 render_manager_.pending_render_view_host() :
535 render_manager_.current_host();
536 return dest_rvh->site_instance();
537}
538
[email protected]be1f56ab2011-12-22 06:55:31539bool TabContents::IsLoading() const {
540 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49541}
542
[email protected]be1f56ab2011-12-22 06:55:31543bool TabContents::IsWaitingForResponse() const {
544 return waiting_for_response_;
545}
546
547const net::LoadStateWithParam& TabContents::GetLoadState() const {
548 return load_state_;
549}
550
551const string16& TabContents::GetLoadStateHost() const {
552 return load_state_host_;
553}
554
555uint64 TabContents::GetUploadSize() const {
556 return upload_size_;
557}
558
559uint64 TabContents::GetUploadPosition() const {
560 return upload_position_;
561}
562
563const std::string& TabContents::GetEncoding() const {
564 return encoding_;
565}
566
567bool TabContents::DisplayedInsecureContent() const {
568 return displayed_insecure_content_;
569}
570
571void TabContents::SetCapturingContents(bool cap) {
572 capturing_contents_ = cap;
573}
574
575bool TabContents::IsCrashed() const {
576 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
577 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
578 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49579}
580
[email protected]443b80e2010-12-14 00:42:23581void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
582 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34583 return;
584
[email protected]443b80e2010-12-14 00:42:23585 crashed_status_ = status;
586 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46587 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34588}
589
[email protected]be1f56ab2011-12-22 06:55:31590base::TerminationStatus TabContents::GetCrashedStatus() const {
591 return crashed_status_;
592}
593
594bool TabContents::IsBeingDestroyed() const {
595 return is_being_destroyed_;
596}
597
[email protected]d5f942ba2008-09-26 19:30:34598void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
599 if (delegate_)
600 delegate_->NavigationStateChanged(this, changed_flags);
601}
602
[email protected]96d185d2009-04-24 03:28:54603void TabContents::DidBecomeSelected() {
604 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16605 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
606 if (rwhv) {
607 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43608#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16609 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43610#endif
611 }
[email protected]96d185d2009-04-24 03:28:54612
[email protected]5ac20162010-11-24 23:33:11613 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38614
[email protected]d8c660432011-12-22 20:51:25615 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54616}
617
[email protected]be1f56ab2011-12-22 06:55:31618
619base::TimeTicks TabContents::GetLastSelectedTime() const {
620 return last_selected_time_;
621}
622
[email protected]96d185d2009-04-24 03:28:54623void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31624 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52625 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
626 // open a tab in then background, then closes the tab before selecting it.
627 // This is because closing the tab calls TabContents::Destroy(), which
628 // removes the |GetRenderViewHost()|; then when we actually destroy the
629 // window, OnWindowPosChanged() notices and calls HideContents() (which
630 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16631 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
632 if (rwhv)
633 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54634 }
635
[email protected]ad50def52011-10-19 23:17:07636 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09637 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
638 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07639 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54640}
641
[email protected]be1f56ab2011-12-22 06:55:31642void TabContents::ShowContents() {
643 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
644 if (rwhv)
645 rwhv->DidBecomeSelected();
646}
647
648void TabContents::HideContents() {
649 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
650 // our superclass HideContents(), because some callers want to be very picky
651 // about the order in which these get called. In addition to making the code
652 // here practically impossible to understand, this also means we end up
653 // calling TabContents::WasHidden() twice if callers call both versions of
654 // HideContents() on a TabContents.
655 WasHidden();
656}
657
658bool TabContents::NeedToFireBeforeUnload() {
659 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27660 return WillNotifyDisconnection() &&
661 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31662 !GetRenderViewHost()->SuddenTerminationAllowed();
663}
664
[email protected]0bfbf882011-12-22 18:19:27665void TabContents::Stop() {
666 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25667 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27668}
669
[email protected]d9083482012-01-06 00:38:46670WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27671 // We create a new SiteInstance so that the new tab won't share processes
672 // with the old one. This can be changed in the future if we need it to share
673 // processes for some reason.
674 TabContents* tc = new TabContents(
675 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33676 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27677 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20678 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27679 return tc;
680}
681
682void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17683 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27684 bool show_history) {
685 if (!delegate_)
686 return;
687
688 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
689}
690
[email protected]2a6bc3e2011-12-28 23:51:33691void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27692 WindowOpenDisposition disposition,
693 const gfx::Rect& initial_pos,
694 bool user_gesture) {
695 if (!delegate_)
696 return;
697
698 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
699 user_gesture);
700}
701
702gfx::NativeView TabContents::GetContentNativeView() const {
703 return view_->GetContentNativeView();
704}
705
706gfx::NativeView TabContents::GetNativeView() const {
707 return view_->GetNativeView();
708}
709
710void TabContents::GetContainerBounds(gfx::Rect* out) const {
711 view_->GetContainerBounds(out);
712}
713
714void TabContents::Focus() {
715 view_->Focus();
716}
717
[email protected]d8c660432011-12-22 20:51:25718void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31719 observers_.AddObserver(observer);
720}
721
[email protected]d8c660432011-12-22 20:51:25722void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31723 observers_.RemoveObserver(observer);
724}
725
[email protected]d5f942ba2008-09-26 19:30:34726void TabContents::Activate() {
727 if (delegate_)
728 delegate_->ActivateContents(this);
729}
730
[email protected]ea42e7782010-08-23 23:58:12731void TabContents::Deactivate() {
732 if (delegate_)
733 delegate_->DeactivateContents(this);
734}
735
[email protected]63954792011-07-11 04:17:48736void TabContents::LostCapture() {
737 if (delegate_)
738 delegate_->LostCapture();
739}
740
741bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
742 bool* is_keyboard_shortcut) {
743 return delegate_ &&
744 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
745}
746
747void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
748 if (delegate_)
749 delegate_->HandleKeyboardEvent(event);
750}
751
[email protected]32ded2212011-11-10 18:51:43752void TabContents::HandleMouseDown() {
753 if (delegate_)
754 delegate_->HandleMouseDown();
755}
756
[email protected]63954792011-07-11 04:17:48757void TabContents::HandleMouseUp() {
758 if (delegate_)
759 delegate_->HandleMouseUp();
760}
761
762void TabContents::HandleMouseActivate() {
763 if (delegate_)
764 delegate_->HandleMouseActivate();
765}
766
[email protected]8a5e0ca2011-08-25 06:30:47767void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
768 if (delegate_)
769 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
770}
771
[email protected]5d5f7af2011-10-01 01:38:12772bool TabContents::IsFullscreenForCurrentTab() const {
773 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
774}
775
[email protected]e9621112011-10-17 05:38:37776void TabContents::RequestToLockMouse() {
777 if (delegate_) {
778 delegate_->RequestToLockMouse(this);
779 } else {
780 GotResponseToLockMouseRequest(false);
781 }
782}
783
784void TabContents::LostMouseLock() {
785 if (delegate_)
786 delegate_->LostMouseLock();
787}
788
[email protected]0548c5352011-09-07 00:33:33789void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23790 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33791 if (delegate_)
792 delegate_->UpdatePreferredSize(this, pref_size);
793}
794
[email protected]32ded2212011-11-10 18:51:43795void TabContents::WebUISend(RenderViewHost* render_view_host,
796 const GURL& source_url,
797 const std::string& name,
798 const base::ListValue& args) {
799 if (delegate_)
800 delegate_->WebUISend(this, source_url, name, args);
801}
802
[email protected]e5d549d2011-12-28 01:29:20803WebContents* TabContents::OpenURL(const OpenURLParams& params) {
804 if (!delegate_)
805 return NULL;
[email protected]00c37fc2011-08-02 00:22:50806
[email protected]e5d549d2011-12-28 01:29:20807 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
808 // Notify observers.
809 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
810 DidOpenURL(params.url, params.referrer,
811 params.disposition, params.transition));
812 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34813}
814
[email protected]1ccb3568d2010-02-19 10:51:16815bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50816 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25817 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23818 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25819 reload_type);
[email protected]876bc832010-09-07 16:29:54820}
[email protected]96d185d2009-04-24 03:28:54821
[email protected]876bc832010-09-07 16:29:54822bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23823 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50824 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40825 // The renderer will reject IPC messages with URLs longer than
826 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51827 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40828 return false;
829
[email protected]dd11de52011-11-03 22:54:27830 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40831 if (!dest_render_view_host)
832 return false; // Unable to create the desired render view host.
833
[email protected]80a8fad2011-01-29 04:02:38834 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07835 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58836 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56837 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30838 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51839 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]f3f3b722012-01-07 01:29:431107 return content::GetContentClient()->browser()->GetWebUIFactory()->
1108 GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271109}
1110
[email protected]01ec4ec2012-01-18 04:13:471111content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271112 // When there is a pending navigation entry, we want to use the pending WebUI
1113 // that goes along with it to control the basic flags. For example, we want to
1114 // show the pending URL in the URL bar, so we want the display_url flag to
1115 // be from the pending entry.
1116 //
1117 // The confusion comes because there are multiple possibilities for the
1118 // initial load in a tab as a side effect of the way the RenderViewHostManager
1119 // works.
1120 //
1121 // - For the very first tab the load looks "normal". The new tab Web UI is
1122 // the pending one, and we want it to apply here.
1123 //
1124 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1125 // get switched to the one previously associated with the new tab pages.
1126 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1127 // have a committed Web UI in this case.
1128 //
1129 // This condition handles all of these cases:
1130 //
1131 // - First load in first tab: no committed nav entry + pending nav entry +
1132 // pending dom ui:
1133 // -> Use pending Web UI if any.
1134 //
1135 // - First load in second tab: no committed nav entry + pending nav entry +
1136 // no pending Web UI:
1137 // -> Use the committed Web UI if any.
1138 //
1139 // - Second navigation in any tab: committed nav entry + pending nav entry:
1140 // -> Use pending Web UI if any.
1141 //
1142 // - Normal state with no load: committed nav entry + no pending nav entry:
1143 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251144 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271145 (controller_.GetLastCommittedEntry() ||
1146 render_manager_.pending_web_ui()))
1147 return render_manager_.pending_web_ui();
1148 return render_manager_.web_ui();
1149}
1150
1151bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1152 return GetRenderViewHost() ?
1153 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1154}
1155
1156bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471157 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271158 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221159 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231160 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511161 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271162 return true;
1163 return false;
1164}
1165
1166void TabContents::SetFocusToLocationBar(bool select_all) {
1167 if (delegate_)
1168 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211169}
1170
[email protected]8b5af492011-11-28 21:50:581171void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301172 const string16& type,
1173 const string16& href,
1174 const string16& title,
1175 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511176 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301177 this, action, type, href, title, disposition);
1178}
1179
[email protected]678105012011-12-09 04:01:211180void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301181 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001182 WebIntentsDispatcherImpl* intents_dispatcher =
1183 new WebIntentsDispatcherImpl(this, intent, intent_id);
1184 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301185}
1186
[email protected]724159a2010-12-30 01:11:181187void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1188 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591189 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181190 const GURL& url) {
1191 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1192 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521193 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301194 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181195
[email protected]8093a542011-05-13 07:29:321196 RenderViewHost* rvh =
1197 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521198 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101199 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251200 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101201 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321202 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101203
[email protected]724159a2010-12-30 01:11:181204 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591205 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591207 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181208 }
1209}
1210
1211void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591212 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181213 const GURL& source_url,
1214 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491215 // TODO(creis): Remove this method and have the pre-rendering code listen to
1216 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1217 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231218 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181219 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251220 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181221 else
1222 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511223 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181224 return;
[email protected]e7d50892011-01-19 21:47:381225
[email protected]4850a7f2011-03-08 23:36:591226 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251227 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261228 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591229 opener_url));
[email protected]724159a2010-12-30 01:11:181230}
1231
1232void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581233 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1234 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1235 << ", error_code: " << params.error_code
1236 << ", error_description: " << params.error_description
1237 << ", is_main_frame: " << params.is_main_frame
1238 << ", showing_repost_interstitial: " <<
1239 params.showing_repost_interstitial
1240 << ", frame_id: " << params.frame_id;
1241 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521242 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301243 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181244
[email protected]d7b175e2011-10-11 15:31:581245 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181246 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1247 // This means that the interstitial won't be torn down properly, which is
1248 // bad. But if we have an interstitial, go back to another tab type, and
1249 // then load the same interstitial again, we could end up getting the first
1250 // interstitial's "failed" message (as a result of the cancel) when we're on
1251 // the second one.
1252 //
1253 // We can't tell this apart, so we think we're tearing down the current page
1254 // which will cause a crash later one. There is also some code in
1255 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1256 // out because of this problem.
1257 //
1258 // http://code.google.com/p/chromium/issues/detail?id=2855
1259 // Because this will not tear down the interstitial properly, if "back" is
1260 // back to another tab type, the interstitial will still be somewhat alive
1261 // in the previous tab type. If you navigate somewhere that activates the
1262 // tab with the interstitial again, you'll see a flash before the new load
1263 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271264 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181265 LOG(WARNING) << "Discarding message during interstitial.";
1266 return;
1267 }
1268
[email protected]02102f82011-06-13 20:37:021269 // Discard our pending entry if the load canceled (e.g. if we decided to
1270 // download the file instead of load it). We do not verify that the URL
1271 // being canceled matches the pending entry's URL because they will not
1272 // match if a redirect occurred (in which case we do not want to leave a
1273 // stale redirect URL showing). This means that we also cancel the pending
1274 // entry if the user started a new navigation. As a result, the navigation
1275 // controller may not remember that a load is in progress, but the
1276 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251277 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161278 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181279
[email protected]151a63d2011-12-20 22:32:521280 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181281 }
1282
1283 // Send out a notification that we failed a provisional load with an error.
1284 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581285 params.is_main_frame,
1286 controller_.IsURLInPageNavigation(validated_url),
1287 validated_url,
1288 std::string(),
1289 false,
1290 params.frame_id);
1291 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181292
[email protected]ad50def52011-10-19 23:17:071293 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271294 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501295 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531296 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101297
[email protected]d8c660432011-12-22 20:51:251298 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581299 observers_,
1300 DidFailProvisionalLoad(params.frame_id,
1301 params.is_main_frame,
1302 validated_url,
1303 params.error_code,
1304 params.error_description));
[email protected]724159a2010-12-30 01:11:181305}
1306
1307void TabContents::OnDidLoadResourceFromMemoryCache(
1308 const GURL& url,
[email protected]70435962011-08-02 20:13:281309 const std::string& security_info,
1310 const std::string& http_method,
1311 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191312 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181313 cache.Increment();
1314
1315 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081316 int cert_id = 0;
1317 net::CertStatus cert_status = 0;
1318 int security_bits = -1;
1319 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181320 SSLManager::DeserializeSecurityInfo(security_info,
1321 &cert_id, &cert_status,
1322 &security_bits,
1323 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301324 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161325 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181326
[email protected]ad50def52011-10-19 23:17:071327 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271328 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501329 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531330 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181331}
1332
1333void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381334 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181335 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201336 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181337}
1338
1339void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021340 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231341 LOG(INFO) << security_origin << " ran insecure content from "
1342 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381343 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051344 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381345 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051346 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1347 }
[email protected]71fde352011-12-29 03:29:561348 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411349 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201350 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181351}
1352
1353void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1354 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251355 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101356 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181357}
1358
[email protected]1a55c5be2011-11-29 11:36:311359void TabContents::OnDidFinishLoad(
1360 int64 frame_id,
1361 const GURL& validated_url,
1362 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251363 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311364 DidFinishLoad(frame_id, validated_url, is_main_frame));
1365}
1366
1367void TabContents::OnDidFailLoadWithError(int64 frame_id,
1368 const GURL& validated_url,
1369 bool is_main_frame,
1370 int error_code,
1371 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251372 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311373 DidFailLoad(frame_id, validated_url, is_main_frame,
1374 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181375}
1376
[email protected]c8f73ab2011-01-22 00:05:171377void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271378 content_restrictions_ = restrictions;
1379 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171380}
1381
[email protected]216813952011-05-19 22:21:261382void TabContents::OnGoToEntryAtOffset(int offset) {
1383 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231384 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251385 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261386 if (!entry)
1387 return;
1388 // Note that we don't call NavigationController::GotToOffset() as we don't
1389 // want to create a pending navigation entry (it might end up lingering
1390 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251391 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581392 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511393 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581394 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471395 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571396
1397 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1398 // it in now that we know. This allows us to find the entry when it commits.
1399 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231400 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331401 entry->set_site_instance(
1402 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571403 }
[email protected]216813952011-05-19 22:21:261404 }
1405}
1406
1407void TabContents::OnUpdateZoomLimits(int minimum_percent,
1408 int maximum_percent,
1409 bool remember) {
1410 minimum_zoom_percent_ = minimum_percent;
1411 maximum_zoom_percent_ = maximum_percent;
1412 temporary_zoom_settings_ = !remember;
1413}
1414
[email protected]0bfbf882011-12-22 18:19:271415void TabContents::OnSaveURL(const GURL& url) {
1416 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1417 dlm->DownloadUrl(url, GetURL(), "", this);
1418}
1419
[email protected]3a29a6e2011-08-24 18:26:211420void TabContents::OnEnumerateDirectory(int request_id,
1421 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511422 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211423}
1424
[email protected]7d189022011-08-25 22:54:201425void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511426 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201427}
1428
1429void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1430 const GURL& url,
1431 const string16& title) {
[email protected]6934a702011-12-20 00:04:511432 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201433}
1434
[email protected]b888919c2011-09-02 00:32:161435void TabContents::OnFindReply(int request_id,
1436 int number_of_matches,
1437 const gfx::Rect& selection_rect,
1438 int active_match_ordinal,
1439 bool final_update) {
[email protected]6934a702011-12-20 00:04:511440 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1441 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001442 // Send a notification to the renderer that we are ready to receive more
1443 // results from the scoping effort of the Find operation. The FindInPage
1444 // scoping is asynchronous and periodically sends results back up to the
1445 // browser using IPC. In an effort to not spam the browser we have the
1446 // browser send an ACK for each FindReply message and have the renderer
1447 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521448 GetRenderViewHost()->Send(
1449 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161450}
1451
[email protected]d952a052011-09-06 18:42:451452void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511453 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451454}
1455
[email protected]7fc4bbb2011-09-08 21:23:101456void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1457 bool blocked_by_policy) {
1458 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251459 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101460 AppCacheAccessed(manifest_url, blocked_by_policy));
1461}
1462
[email protected]96d185d2009-04-24 03:28:541463// Notifies the RenderWidgetHost instance about the fact that the page is
1464// loading, or done loading and calls the base implementation.
1465void TabContents::SetIsLoading(bool is_loading,
1466 LoadNotificationDetails* details) {
1467 if (is_loading == is_loading_)
1468 return;
1469
1470 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211471 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541472 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561473 upload_size_ = 0;
1474 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541475 }
1476
1477 render_manager_.SetIsLoading(is_loading);
1478
1479 is_loading_ = is_loading;
1480 waiting_for_response_ = is_loading;
1481
[email protected]6ebdc9b2010-09-27 16:55:571482 if (delegate_)
1483 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461484 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541485
[email protected]432115822011-07-10 15:52:271486 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1487 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071488 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541489 if (details)
[email protected]6c2381d2011-10-19 02:52:531490 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071491 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501492 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541493 det);
1494}
1495
[email protected]420ae012009-04-24 05:16:321496void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131497 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321498 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561499 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381500 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441501 // that opened the window, as long as both renderers have the same
1502 // privileges.
[email protected]1fd1a502011-03-30 16:55:561503 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561504 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581505 // web_ui might be NULL if the URL refers to a non-existent extension.
1506 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401507 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521508 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441509 }
1510 }
[email protected]1fd1a502011-03-30 16:55:561511 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441512 }
1513
[email protected]4e697b042011-07-08 06:44:561514 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321515 // Clear the status bubble. This is a workaround for a bug where WebKit
1516 // doesn't let us know that the cursor left an element during a
1517 // transition (this is also why the mouse cursor remains as a hand after
1518 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1519 // clear the bubble when a user navigates to a named anchor in the same
1520 // page.
[email protected]36fc0392011-12-25 03:59:511521 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321522 }
1523
[email protected]a6e82fc2010-02-24 22:28:141524 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471525 // Once the main frame is navigated, we're no longer considered to have
1526 // displayed insecure content.
1527 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171528 }
[email protected]ce5c4502009-05-06 16:46:111529
[email protected]3c9e1872010-11-18 16:17:491530 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041532 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321533}
1534
1535void TabContents::DidNavigateAnyFramePostCommit(
1536 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131537 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321538 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061539 // If we navigate off the page, reset JavaScript state. This does nothing
1540 // to prevent a malicious script from spamming messages, since the script
1541 // could just reload the page to stop blocking.
1542 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551543 dialog_creator_->ResetJavaScriptState(this);
1544 dialog_creator_ = NULL;
1545 }
[email protected]420ae012009-04-24 05:16:321546
[email protected]3c9e1872010-11-18 16:17:491547 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251548 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041549 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321550}
1551
[email protected]74ce1ad2011-12-16 21:51:461552void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1553 // If we are creating a RVH for a restored controller, then we need to make
1554 // sure the RenderView starts with a next_page_id_ larger than the number
1555 // of restored entries. This must be called before the RenderView starts
1556 // navigating (to avoid a race between the browser updating max_page_id and
1557 // the renderer updating next_page_id_). Because of this, we only call this
1558 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561559 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461560 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1561 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321562}
1563
[email protected]10f417c52011-12-28 21:04:231564bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571565 const string16& title) {
[email protected]420ae012009-04-24 05:16:321566 // For file URLs without a title, use the pathname instead. In the case of a
1567 // synthesized title, we don't want the update to count toward the "one set
1568 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511569 string16 final_title;
[email protected]420ae012009-04-24 05:16:321570 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511571 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1572 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321573 explicit_set = false; // Don't count synthetic titles toward the set limit.
1574 } else {
[email protected]acafd272011-07-26 17:35:571575 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321576 explicit_set = true;
1577 }
1578
[email protected]987fc3a2011-05-26 14:18:091579 // If a page is created via window.open and never navigated,
1580 // there will be no navigation entry. In this situation,
1581 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1582 if (entry) {
[email protected]36fc0392011-12-25 03:59:511583 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091584 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321585
[email protected]36fc0392011-12-25 03:59:511586 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091587 } else {
1588 if (page_title_when_no_navigation_entry_ == final_title)
1589 return false; // Nothing changed, don't bother.
1590
1591 page_title_when_no_navigation_entry_ = final_title;
1592 }
[email protected]420ae012009-04-24 05:16:321593
[email protected]420ae012009-04-24 05:16:321594 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231595 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321596
[email protected]105bb0f2011-05-24 17:12:141597 TitleUpdatedDetails details(entry, explicit_set);
1598
[email protected]ad50def52011-10-19 23:17:071599 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441600 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1601 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531602 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041603
[email protected]420ae012009-04-24 05:16:321604 return true;
1605}
1606
1607void TabContents::NotifySwapped() {
1608 // After sending out a swap notification, we need to send a disconnect
1609 // notification so that clients that pick up a pointer to |this| can NULL the
1610 // pointer. See Bug 1230284.
1611 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071612 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201613 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1614 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071615 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321616}
1617
1618void TabContents::NotifyConnected() {
1619 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071620 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121621 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1622 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071623 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321624}
1625
1626void TabContents::NotifyDisconnected() {
1627 if (!notify_disconnection_)
1628 return;
1629
1630 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071631 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321632 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1633 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071634 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321635}
1636
[email protected]8d3347f2009-07-09 22:00:211637RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321638 return view_.get();
1639}
1640
[email protected]8d3347f2009-07-09 22:00:211641RenderViewHostDelegate::RendererManagement*
1642TabContents::GetRendererManagementDelegate() {
1643 return &render_manager_;
1644}
1645
[email protected]daf82f82011-10-31 22:35:311646content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371647 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461648 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511649}
1650
[email protected]768c5472011-12-26 19:06:171651WebContents* TabContents::GetAsWebContents() {
1652 return this;
1653}
1654
[email protected]da4dfc42011-10-12 15:53:561655content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431656 return view_type_;
[email protected]7b291f92009-08-14 05:43:531657}
1658
[email protected]b7a756d42012-01-23 18:08:171659gfx::Rect TabContents::GetRootWindowResizerRect() const {
1660 if (delegate_)
1661 return delegate_->GetRootWindowResizerRect();
1662 return gfx::Rect();
1663}
1664
[email protected]420ae012009-04-24 05:16:321665void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071666 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271667 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321668 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531669 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231670 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321671 if (!entry)
1672 return;
1673
1674 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351675 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561676 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581677 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321678
1679 if (entry->IsViewSourceMode()) {
1680 // Put the renderer in view source mode.
1681 render_view_host->Send(
1682 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1683 }
[email protected]0666aef2009-05-13 19:48:081684
[email protected]d487beefe2011-12-21 05:41:211685 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261686
1687 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251688 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321689}
1690
1691void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521692 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321693 // Don't notify the world, since this came from a renderer in the
1694 // background.
1695 return;
1696 }
1697
1698 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311699 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231700 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301701
1702 // Restore the focus to the tab (otherwise the focus will be on the top
1703 // window).
[email protected]484ae5912010-09-29 19:16:141704 if (was_crashed && !FocusLocationBarByDefault() &&
1705 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301706 Focus();
[email protected]484ae5912010-09-29 19:16:141707 }
[email protected]32ded2212011-11-10 18:51:431708
[email protected]d8c660432011-12-22 20:51:251709 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321710}
1711
[email protected]443b80e2010-12-14 00:42:231712void TabContents::RenderViewGone(RenderViewHost* rvh,
1713 base::TerminationStatus status,
1714 int error_code) {
[email protected]151a63d2011-12-20 22:32:521715 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321716 // The pending page's RenderViewHost is gone.
1717 return;
1718 }
1719
1720 SetIsLoading(false, NULL);
1721 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231722 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311723 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321724
[email protected]d8c660432011-12-22 20:51:251725 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271726 observers_,
[email protected]be1f56ab2011-12-22 06:55:311727 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321728}
1729
[email protected]2e4633c2009-07-09 16:58:061730void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481731 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251732 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061733}
1734
[email protected]420ae012009-04-24 05:16:321735void TabContents::DidNavigate(RenderViewHost* rvh,
1736 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581737 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321738 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371739
[email protected]420ae012009-04-24 05:16:321740 // Update the site of the SiteInstance if it doesn't have one yet.
[email protected]b6583592012-01-25 19:52:331741 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite())
1742 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]420ae012009-04-24 05:16:321743
1744 // Need to update MIME type here because it's referred to in
1745 // UpdateNavigationCommands() called by RendererDidNavigate() to
1746 // determine whether or not to enable the encoding menu.
1747 // It's updated only for the main frame. For a subframe,
1748 // RenderView::UpdateURL does not set params.contents_mime_type.
1749 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1750 // TODO(jungshik): Add a test for the encoding menu to avoid
1751 // regressing it again.
[email protected]2905f742011-10-13 03:51:581752 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321753 contents_mime_type_ = params.contents_mime_type;
1754
[email protected]8286f51a2011-05-31 17:39:131755 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001756 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391757
[email protected]a9c0bfe2010-09-17 08:35:221758 // Send notification about committed provisional loads. This notification is
1759 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1760 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081761 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071762 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1763 // that is not recorded in the navigation history. For the purpose of
1764 // tracking navigation events, we treat this event as a sub frame navigation
1765 // event.
1766 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581767 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221768 // Whether or not a page transition was triggered by going backward or
1769 // forward in the history is only stored in the navigation controller's
1770 // entry list.
1771 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511772 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581773 content::PAGE_TRANSITION_FORWARD_BACK)) {
1774 transition_type = content::PageTransitionFromInt(
1775 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221776 }
[email protected]0d60f0192011-04-14 12:40:101777 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251778 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101779 DidCommitProvisionalLoadForFrame(params.frame_id,
1780 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221781 }
1782
[email protected]76543b92009-08-31 17:27:451783 if (!did_navigate)
1784 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321785
1786 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1787 // for the appropriate notification (best) or you can add it to
1788 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1789 // necessary, please).
1790
1791 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001792 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321793 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511794 if (delegate_)
1795 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001796 }
[email protected]420ae012009-04-24 05:16:321797 DidNavigateAnyFramePostCommit(rvh, details, params);
1798}
1799
1800void TabContents::UpdateState(RenderViewHost* rvh,
1801 int32 page_id,
1802 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151803 // Ensure that this state update comes from either the active RVH or one of
1804 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521805 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321806
1807 // We must be prepared to handle state updates for any page, these occur
1808 // when the user is scrolling and entering form data, as well as when we're
1809 // leaving a page, in which case our state may have already been moved to
1810 // the next page. The navigation controller will look up the appropriate
1811 // NavigationEntry and update it when it is notified via the delegate.
1812
1813 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151814 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321815 if (entry_index < 0)
1816 return;
[email protected]10f417c52011-12-28 21:04:231817 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321818
[email protected]36fc0392011-12-25 03:59:511819 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321820 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511821 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321822 controller_.NotifyEntryChanged(entry, entry_index);
1823}
1824
1825void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571826 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461827 const string16& title,
1828 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321829 // If we have a title, that's a pretty good indication that we've started
1830 // getting useful data.
1831 SetNotWaitingForResponse();
1832
[email protected]151a63d2011-12-20 22:32:521833 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231834 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1835 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091836
[email protected]a49e10b2011-08-01 23:57:461837 // TODO(evan): make use of title_direction.
1838 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091839 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321840 return;
1841
1842 // Broadcast notifications when the UI should be updated.
1843 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:461844 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:321845}
1846
[email protected]420ae012009-04-24 05:16:321847void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401848 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311849 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321850}
1851
1852void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511853 if (delegate_)
1854 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321855}
1856
[email protected]420ae012009-04-24 05:16:321857void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291858 // The UI may be in an event-tracking loop, such as between the
1859 // mouse-down and mouse-up in text selection or a button click.
1860 // Defer the close until after tracking is complete, so that we
1861 // don't free objects out from under the UI.
1862 // TODO(shess): This could probably be integrated with the
1863 // IsDoingDrag() test below. Punting for now because I need more
1864 // research to understand how this impacts platforms other than Mac.
1865 // TODO(shess): This could get more fine-grained. For instance,
1866 // closing a tab in another window while selecting text in the
1867 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211868 if (GetView()->IsEventTracking()) {
1869 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291870 return;
1871 }
1872
[email protected]24a4d1062009-07-10 23:10:421873 // If we close the tab while we're in the middle of a drag, we'll crash.
1874 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211875 if (GetView()->IsDoingDrag()) {
1876 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421877 return;
1878 }
1879
[email protected]420ae012009-04-24 05:16:321880 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521881 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511882 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321883}
1884
[email protected]cd9ed79d2011-11-15 19:22:571885void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521886 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511887 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571888}
1889
[email protected]420ae012009-04-24 05:16:321890void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511891 if (delegate_ && delegate_->IsPopupOrPanel(this))
1892 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321893}
1894
[email protected]7ab1e7d62009-10-14 23:32:011895void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321896 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491897
[email protected]6934a702011-12-20 00:04:511898 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211899 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511900 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001901 }
[email protected]3c9e1872010-11-18 16:17:491902
1903 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251904 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321905}
1906
[email protected]7ab1e7d62009-10-14 23:32:011907void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321908 scoped_ptr<LoadNotificationDetails> details;
1909
[email protected]10f417c52011-12-28 21:04:231910 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321911 // An entry may not exist for a stop when loading an initial blank page or
1912 // if an iframe injected by script into a blank page finishes loading.
1913 if (entry) {
[email protected]420ae012009-04-24 05:16:321914 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1915
1916 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511917 entry->GetVirtualURL(),
1918 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321919 elapsed,
1920 &controller_,
1921 controller_.GetCurrentEntryIndex()));
1922 }
1923
[email protected]420ae012009-04-24 05:16:321924 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491925
1926 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251927 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321928}
1929
[email protected]c95fa8b2011-04-28 20:26:161930void TabContents::DidCancelLoading() {
1931 controller_.DiscardNonCommittedEntries();
1932
1933 // Update the URL display.
[email protected]d9083482012-01-06 00:38:461934 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:161935}
1936
[email protected]1a3c3cb2010-12-16 21:03:401937void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511938 if (delegate_)
1939 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401940}
1941
[email protected]952a68e2011-11-17 00:36:101942void TabContents::DocumentAvailableInMainFrame(
1943 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251944 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101945 DocumentAvailableInMainFrame());
1946}
1947
[email protected]25497492010-09-11 15:15:081948void TabContents::DocumentOnLoadCompletedInMainFrame(
1949 RenderViewHost* render_view_host,
1950 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071951 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271952 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321953 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531954 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081955}
1956
[email protected]ae5184d62011-10-06 19:25:581957void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151958 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581959 WindowOpenDisposition disposition,
1960 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481961 // Delegate to RequestTransferURL because this is just the generic
1962 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581963 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481964 GlobalRequestID());
1965}
1966
1967void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581968 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481969 WindowOpenDisposition disposition,
1970 int64 source_frame_id,
1971 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201972 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581973 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581974 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351975 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321976 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1977 // generated suggestions).
1978 //
[email protected]e0112912011-02-02 22:54:351979 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161980 // want web sites to see a referrer of "chrome://blah" (and some
1981 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321982 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581983 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]c63cedf22012-01-17 18:42:221984 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:481985 false /* is_renderer_initiated */);
1986 params.transferred_global_request_id = old_request_id;
1987 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:221988 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:321989 } else {
[email protected]4ad5d77d2011-12-03 02:00:481990 OpenURLParams params(url, referrer, disposition,
1991 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1992 params.transferred_global_request_id = old_request_id;
1993 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581994 }
1995 if (new_contents) {
1996 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251997 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581998 DidOpenRequestedURL(new_contents,
1999 url,
2000 referrer,
2001 disposition,
2002 transition_type,
2003 source_frame_id));
[email protected]420ae012009-04-24 05:16:322004 }
2005}
2006
[email protected]420ae012009-04-24 05:16:322007void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:152008 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412009 const string16& message,
2010 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322011 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472012 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322013 IPC::Message* reply_msg,
2014 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072015 // Suppress JavaScript dialogs when requested. Also suppress messages when
2016 // showing an interstitial as it's shown over the previous page and we don't
2017 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502018 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152019 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272020 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072021 !delegate_ ||
2022 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:322023
2024 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342025 content::JavaScriptDialogCreator::TitleType title_type;
2026 string16 title;
2027
2028 if (!frame_url.has_host()) {
2029 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2030 } else {
2031 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2032 title = net::FormatUrl(
2033 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202034 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302035 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342036 }
2037
[email protected]2e5b90c2011-08-16 21:11:552038 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2039 dialog_creator_->RunJavaScriptDialog(this,
2040 title_type,
2041 title,
[email protected]269f86d2011-12-07 02:43:472042 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:552043 message,
2044 default_prompt,
2045 reply_msg,
2046 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322047 }
[email protected]3ab9cb82011-06-03 18:02:072048
2049 if (suppress_this_message) {
2050 // If we are suppressing messages, just reply as if the user immediately
2051 // pressed "Cancel".
2052 OnDialogClosed(reply_msg, false, string16());
2053 }
2054
2055 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322056}
2057
[email protected]992db4c2011-05-12 15:37:152058void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412059 const string16& message,
[email protected]420ae012009-04-24 05:16:322060 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512061 if (delegate_)
2062 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072063
2064 bool suppress_this_message =
2065 rvh->is_swapped_out() ||
2066 !delegate_ ||
2067 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152068 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522069 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502070 return;
2071 }
[email protected]3ab9cb82011-06-03 18:02:072072
[email protected]7ab1e7d62009-10-14 23:32:012073 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552074 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2075 dialog_creator_->RunBeforeUnloadDialog(this,
2076 message,
2077 reply_msg);
[email protected]420ae012009-04-24 05:16:322078}
2079
[email protected]420ae012009-04-24 05:16:322080WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082081 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362082 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522083 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082084
[email protected]b8299c12011-06-03 19:52:282085 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212086 // chrome-devtools: pages (unless it's specifically allowed).
2087 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572088 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282089 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302090 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2091 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212092 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082093 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432094 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082095 }
2096
2097 return web_prefs;
[email protected]420ae012009-04-24 05:16:322098}
2099
[email protected]7d472472011-01-22 01:30:252100void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272101 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252102 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222103
[email protected]99907362012-01-11 05:41:402104 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172105 if (rdh) // NULL in unittests.
2106 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252107}
2108
[email protected]fa1cf0b82010-01-15 21:49:442109void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442110 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252111 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442112}
2113
[email protected]420ae012009-04-24 05:16:322114void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2115 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152116 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522117 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152118 return;
2119
[email protected]e5fc1632011-08-08 07:51:532120 // Ignore renderer unresponsive event if debugger is attached to the tab
2121 // since the event may be a result of the renderer sitting on a breakpoint.
2122 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442123 DevToolsAgentHost* agent =
2124 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2125 if (agent &&
2126 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532127 return;
2128
[email protected]420ae012009-04-24 05:16:322129 if (is_during_unload) {
2130 // Hang occurred while firing the beforeunload/unload handler.
2131 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112132 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322133
2134 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2135 return;
2136
2137 // If the tab hangs in the beforeunload/unload handler there's really
2138 // nothing we can do to recover. Pretend the unload listeners have
2139 // all fired and close the tab. If the hang is in the beforeunload handler
2140 // then the user will not have the option of cancelling the close.
2141 Close(rvh);
2142 return;
2143 }
2144
[email protected]151a63d2011-12-20 22:32:522145 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472146 return;
2147
[email protected]6934a702011-12-20 00:04:512148 if (delegate_)
2149 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322150}
2151
2152void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512153 if (delegate_)
2154 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322155}
2156
2157void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212158 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562159 uint64 upload_position,
2160 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322161 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562162 upload_position_ = upload_position;
2163 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502164 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202165 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302166 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212167 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322168 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462169 if (IsLoading()) {
2170 NotifyNavigationStateChanged(
2171 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2172 }
[email protected]420ae012009-04-24 05:16:322173}
2174
[email protected]7d472472011-01-22 01:30:252175void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512176 if (delegate_)
2177 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252178}
2179
[email protected]420ae012009-04-24 05:16:322180void TabContents::BeforeUnloadFiredFromRenderManager(
2181 bool proceed,
2182 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512183 if (delegate_)
2184 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322185}
2186
[email protected]3a3d47472010-07-15 21:03:542187void TabContents::DidStartLoadingFromRenderManager(
2188 RenderViewHost* render_view_host) {
2189 DidStartLoading();
2190}
2191
2192void TabContents::RenderViewGoneFromRenderManager(
2193 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232194 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2195 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542196}
2197
[email protected]420ae012009-04-24 05:16:322198void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102199 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262200 gfx::Size size = view_->GetContainerSize();
2201 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2202 // here during container initialization and normal window size will be set
2203 // later. In case of tab duplication this resizing to 0x0 prevents setting
2204 // normal size later so just ignore it.
2205 if (!size.IsEmpty())
2206 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322207}
2208
[email protected]3a3d47472010-07-15 21:03:542209void TabContents::NotifySwappedFromRenderManager() {
2210 NotifySwapped();
2211}
2212
[email protected]d202a7c2012-01-04 07:53:472213NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202214 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542215}
2216
[email protected]d2353452012-01-19 19:53:562217WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2218 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322219}
2220
[email protected]10f417c52011-12-28 21:04:232221NavigationEntry*
2222 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322223 return controller_.GetLastCommittedEntry();
2224}
2225
2226bool TabContents::CreateRenderViewForRenderManager(
2227 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442228 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322229 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522230
[email protected]420ae012009-04-24 05:16:322231 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442232 if (rwh_view)
2233 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322234
[email protected]74ce1ad2011-12-16 21:51:462235 // Make sure we use the correct starting page_id in the new RenderView.
2236 UpdateMaxPageIDIfNecessary(render_view_host);
2237 int32 max_page_id =
2238 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2239
2240 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522241 return false;
2242
[email protected]e60c0232011-11-11 19:56:352243#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502244 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2245 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442246 if (rwh_view) {
2247 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2248 render_widget_host->WasResized();
2249 }
[email protected]f8233cc2011-05-31 20:24:502250#endif
2251
[email protected]420ae012009-04-24 05:16:322252 return true;
2253}
2254
[email protected]3ab9cb82011-06-03 18:02:072255void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2256 bool success,
2257 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542258 if (is_showing_before_unload_dialog_ && !success) {
2259 // If a beforeunload dialog is canceled, we need to stop the throbber from
2260 // spinning, since we forced it to start spinning in Navigate.
2261 DidStopLoading();
2262
2263 tab_close_start_time_ = base::TimeTicks();
2264 }
2265 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522266 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542267}
2268
[email protected]0b08add2011-11-29 03:27:062269gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072270 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542271}
2272
[email protected]a1e97f02011-06-30 14:04:342273void TabContents::OnDialogShown() {
2274 Activate();
[email protected]3a3d47472010-07-15 21:03:542275}
2276
[email protected]be1f56ab2011-12-22 06:55:312277void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122278 encoding_ = content::GetContentClient()->browser()->
2279 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102280}
[email protected]f45d2a72010-03-08 23:28:352281
[email protected]33f74972010-12-08 16:40:362282void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212283 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442284 // Can be NULL during tests.
2285 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212286 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362287}