blob: 90d5eab45314245d7818909b8a3a663a6d044529 [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 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]3d7474ff2011-07-27 17:47:3716#include "content/browser/browser_context.h"
[email protected]567812d2011-02-24 17:40:5017#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5618#include "content/browser/content_browser_client.h"
[email protected]b46442d7e2011-06-29 02:16:0619#include "content/browser/debugger/devtools_manager.h"
[email protected]71bf3f5e2011-08-15 21:05:2220#include "content/browser/download/download_manager.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5022#include "content/browser/host_zoom_map.h"
23#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]37a72af2011-06-13 05:42:0124#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0425#include "content/browser/load_notification_details.h"
[email protected]567812d2011-02-24 17:40:5026#include "content/browser/renderer_host/render_process_host.h"
27#include "content/browser/renderer_host/render_view_host.h"
28#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2229#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5030#include "content/browser/renderer_host/resource_request_details.h"
31#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4432#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1333#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434#include "content/browser/tab_contents/navigation_entry.h"
35#include "content/browser/tab_contents/provisional_load_details.h"
36#include "content/browser/tab_contents/tab_contents_delegate.h"
37#include "content/browser/tab_contents/tab_contents_observer.h"
38#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1439#include "content/browser/tab_contents/title_updated_details.h"
[email protected]afd1e522011-04-27 23:29:5940#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5641#include "content/browser/webui/web_ui_factory.h"
42#include "content/common/content_client.h"
[email protected]19e81142011-10-03 16:19:4043#include "content/common/content_constants.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "content/common/content_restriction.h"
[email protected]ce9751942011-09-21 01:57:2445#include "content/common/intents_messages.h"
[email protected]4dd57932011-03-17 06:06:1246#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3247#include "content/common/notification_service.h"
[email protected]0f012df82011-05-19 14:15:2948#include "content/common/url_constants.h"
[email protected]2c5569662011-03-22 20:45:0249#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2150#include "content/public/common/bindings_policy.h"
[email protected]da4dfc42011-10-12 15:53:5651#include "content/public/common/view_types.h"
[email protected]d686e812009-06-03 19:10:2952#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3453#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3754#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3855#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0356#include "webkit/glue/password_form.h"
[email protected]ce9751942011-09-21 01:57:2457#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3158#include "webkit/glue/webpreferences.h"
59
60#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1261#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3162#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0063
[email protected]420ae012009-04-24 05:16:3264// Cross-Site Navigations
65//
66// If a TabContents is told to navigate to a different web site (as determined
67// by SiteInstance), it will replace its current RenderViewHost with a new
68// RenderViewHost dedicated to the new SiteInstance. This works as follows:
69//
70// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4671// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3272// - The pending RVH is "suspended," so that no navigation messages are sent to
73// its renderer until the onbeforeunload JavaScript handler has a chance to
74// run in the current RVH.
75// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
76// that it has a pending cross-site request. ResourceDispatcherHost will
77// check for this when the response arrives.
78// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4679// cancel all the pending logic. Otherwise we allow the pending RVH to send
80// the navigation request to its renderer.
81// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
82// main resource load on the pending RVH. It checks CrossSiteRequestManager
83// to see that it is a cross-site request, and installs a
84// CrossSiteResourceHandler.
85// - When RDH receives a response, the BufferedResourceHandler determines
86// whether it is a download. If so, it sends a message to the new renderer
87// causing it to cancel the request, and the download proceeds. For now, the
88// pending RVH remains until the next DidNavigate event for this TabContents.
89// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3290// - After RDH receives a response and determines that it is safe and not a
91// download, it pauses the response to first run the old page's onunload
92// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1593// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3294// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1595// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3296// the ResourceDispatcherHost, who unpauses the response. Data is then sent
97// to the pending RVH.
98// - The pending renderer sends a FrameNavigate message that invokes the
99// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46100// pending RVH.
[email protected]992db4c2011-05-12 15:37:15101// - The previous renderer is kept swapped out in RenderViewHostManager in case
102// the user goes back. The process only stays live if another tab is using
103// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32104
105namespace {
106
107// Amount of time we wait between when a key event is received and the renderer
108// is queried for its state and pushed to the NavigationEntry.
109const int kQueryStateDelay = 5000;
110
[email protected]6ebdc9b2010-09-27 16:55:57111const int kSyncWaitDelay = 40;
112
[email protected]ca406032011-07-19 21:53:05113static const char kDotGoogleDotCom[] = ".google.com";
114
[email protected]420ae012009-04-24 05:16:32115#if defined(OS_WIN)
116
117BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
118 // Note: erase is required to properly paint some widgets borders. This can
119 // be seen with textfields.
120 InvalidateRect(hwnd, NULL, TRUE);
121 return TRUE;
122}
123#endif
124
[email protected]2c5569662011-03-22 20:45:02125ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]3d7474ff2011-07-27 17:47:37126 content::BrowserContext* browser_context, const NavigationEntry& entry,
[email protected]1ccb3568d2010-02-19 10:51:16127 NavigationController::ReloadType reload_type) {
128 switch (reload_type) {
129 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02130 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16131 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02132 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16133 case NavigationController::NO_RELOAD:
134 break; // Fall through to rest of function.
135 }
[email protected]5e369672009-11-03 23:48:30136
137 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37138 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02139 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30140
[email protected]2c5569662011-03-22 20:45:02141 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30142}
143
[email protected]876bc832010-09-07 16:29:54144void MakeNavigateParams(const NavigationEntry& entry,
145 const NavigationController& controller,
[email protected]6c6b02d2011-09-02 03:36:47146 TabContentsDelegate* delegate,
[email protected]1ccb3568d2010-02-19 10:51:16147 NavigationController::ReloadType reload_type,
148 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34149 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54150 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00151 params->current_history_list_offset = controller.last_committed_entry_index();
152 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34153 params->url = entry.url();
154 params->referrer = entry.referrer();
155 params->transition = entry.transition_type();
156 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00157 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37158 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34159 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47160 params->extra_headers = entry.extra_headers();
161
162 if (delegate)
163 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34164}
165
[email protected]420ae012009-04-24 05:16:32166} // namespace
167
[email protected]f4f50ef2011-01-21 19:01:19168
169// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32170
[email protected]3d7474ff2011-07-27 17:47:37171TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32172 SiteInstance* site_instance,
173 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07174 const TabContents* base_tab_contents,
175 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42176 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07177 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37178 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13179 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32180 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22181 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34182 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23183 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
184 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34185 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34186 max_page_id_(-1),
[email protected]9c235f042011-08-10 22:28:21187 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56188 upload_size_(0),
189 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47190 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57191 capturing_contents_(false),
192 is_being_destroyed_(false),
193 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55194 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57195#if defined(OS_WIN)
196 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
197#endif
[email protected]7ab1e7d62009-10-14 23:32:01198 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56199 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38200 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25201 minimum_zoom_percent_(
202 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
203 maximum_zoom_percent_(
204 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00205 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59206 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54207
[email protected]3d7474ff2011-07-27 17:47:37208 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32209
[email protected]34ac70502009-09-25 17:07:23210 // We have the initial size of the view be based on the size of the passed in
211 // tab contents (normally a tab from the same window).
212 view_->CreateView(base_tab_contents ?
213 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]332af7732009-03-11 13:21:35214}
initial.commit09911bf2008-07-26 23:55:29215
216TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32217 is_being_destroyed_ = true;
218
[email protected]3ab9cb82011-06-03 18:02:07219 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55220 if (dialog_creator_)
221 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07222
[email protected]420ae012009-04-24 05:16:32223 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32224
[email protected]420ae012009-04-24 05:16:32225 // Notify any observer that have a reference on this tab contents.
226 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27227 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]420ae012009-04-24 05:16:32228 Source<TabContents>(this),
229 NotificationService::NoDetails());
230
231 // TODO(brettw) this should be moved to the view.
232#if defined(OS_WIN)
233 // If we still have a window handle, destroy it. GetNativeView can return
234 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42235 if (GetNativeView()) {
236 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44237 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42238 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42239 }
[email protected]420ae012009-04-24 05:16:32240#endif
[email protected]7ab1e7d62009-10-14 23:32:01241
242 // OnCloseStarted isn't called in unit tests.
243 if (!tab_close_start_time_.is_null()) {
244 UMA_HISTOGRAM_TIMES("Tab.Close",
245 base::TimeTicks::Now() - tab_close_start_time_);
246 }
[email protected]b5a1d11c2011-02-17 03:09:42247
[email protected]07d490bc2011-03-07 17:05:26248 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08249
[email protected]1de2b8b2011-06-29 19:38:46250 set_delegate(NULL);
251}
252
253// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
254void TabContents::set_delegate(TabContentsDelegate* delegate) {
255 if (delegate == delegate_)
256 return;
257 if (delegate_)
258 delegate_->Detach(this);
259 delegate_ = delegate;
260 if (delegate_)
261 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42262}
263
[email protected]724159a2010-12-30 01:11:18264bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17265 if (web_ui() && web_ui()->OnMessageReceived(message))
266 return true;
267
[email protected]585b30362011-01-28 02:30:17268 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
269 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10270 while ((observer = it.GetNext()) != NULL)
271 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53272 return true;
[email protected]403415a2011-01-10 18:57:53273
[email protected]724159a2010-12-30 01:11:18274 bool handled = true;
275 bool message_is_ok = true;
276 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]ce9751942011-09-21 01:57:24277 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
278 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18279 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
280 OnDidStartProvisionalLoadForFrame)
281 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
282 OnDidRedirectProvisionalLoad)
283 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
284 OnDidFailProvisionalLoadWithError)
285 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
286 OnDidLoadResourceFromMemoryCache)
287 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
288 OnDidDisplayInsecureContent)
289 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
290 OnDidRunInsecureContent)
291 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
292 OnDocumentLoadedInFrame)
293 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17294 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
295 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25296 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26297 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
298 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]c7dd2f62011-07-18 15:57:59299 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21300 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20301 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
302 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
303 OnRegisterProtocolHandler)
304 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterIntentHandler,
305 OnRegisterIntentHandler)
[email protected]b888919c2011-09-02 00:32:16306 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45307 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10308 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18309 IPC_MESSAGE_UNHANDLED(handled = false)
310 IPC_END_MESSAGE_MAP_EX()
311
312 if (!message_is_ok) {
313 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
314 GetRenderProcessHost()->ReceivedBadMessage();
315 }
316
317 return handled;
318}
319
[email protected]6c2e472f2011-08-24 23:26:18320void TabContents::RunFileChooser(
321 RenderViewHost* render_view_host,
322 const ViewHostMsg_RunFileChooser_Params& params) {
323 delegate()->RunFileChooser(this, params);
324}
325
[email protected]8cb5d5b2010-02-09 11:36:16326RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03327 if (render_manager_.current_host())
328 return render_manager_.current_host()->process();
329 else
330 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16331}
332
[email protected]d5f942ba2008-09-26 19:30:34333const GURL& TabContents::GetURL() const {
334 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57335 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54336 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34337}
338
[email protected]96d185d2009-04-24 03:28:54339const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55340 // Transient entries take precedence. They are used for interstitial pages
341 // that are shown on top of existing pages.
342 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08343 std::string accept_languages =
344 content::GetContentClient()->browser()->GetAcceptLangs(this);
[email protected]45d0ef7f2011-01-05 13:46:23345 if (entry) {
[email protected]b5cca982011-05-26 04:42:08346 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23347 }
[email protected]7ade2732011-02-10 00:13:58348 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
349 render_manager_.pending_web_ui() : render_manager_.web_ui();
350 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54351 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55352 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54353 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35354 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58355 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54356 if (!title.empty())
357 return title;
358 }
359 }
360
361 // We use the title for the last committed entry rather than a pending
362 // navigation entry. For example, when the user types in a URL, we want to
363 // keep the old page's title until the new load has committed and we get a new
364 // title.
[email protected]96d185d2009-04-24 03:28:54365 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23366 if (entry) {
[email protected]b5cca982011-05-26 04:42:08367 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23368 }
[email protected]987fc3a2011-05-26 14:18:09369
370 // |page_title_when_no_navigation_entry_| is finally used
371 // if no title cannot be retrieved.
372 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54373}
374
[email protected]d5f942ba2008-09-26 19:30:34375int32 TabContents::GetMaxPageID() {
376 if (GetSiteInstance())
377 return GetSiteInstance()->max_page_id();
378 else
379 return max_page_id_;
380}
381
382void TabContents::UpdateMaxPageID(int32 page_id) {
383 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34384 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34385 // testing.
386 if (GetSiteInstance())
387 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16388 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34389}
390
[email protected]96d185d2009-04-24 03:28:54391SiteInstance* TabContents::GetSiteInstance() const {
392 return render_manager_.current_host()->site_instance();
393}
394
[email protected]77362eb2011-08-01 17:18:38395SiteInstance* TabContents::GetPendingSiteInstance() const {
396 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
397 render_manager_.pending_render_view_host() :
398 render_manager_.current_host();
399 return dest_rvh->site_instance();
400}
401
[email protected]f5d978c2011-07-21 14:43:51402bool TabContents::IsLoading() const {
403 return is_loading_ || (web_ui() && web_ui()->IsLoading());
404}
405
[email protected]585b30362011-01-28 02:30:17406void TabContents::AddObserver(TabContentsObserver* observer) {
407 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49408}
409
[email protected]585b30362011-01-28 02:30:17410void TabContents::RemoveObserver(TabContentsObserver* observer) {
411 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49412}
413
[email protected]443b80e2010-12-14 00:42:23414void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
415 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34416 return;
417
[email protected]443b80e2010-12-14 00:42:23418 crashed_status_ = status;
419 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50420 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34421}
422
423void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
424 if (delegate_)
425 delegate_->NavigationStateChanged(this, changed_flags);
426}
427
[email protected]96d185d2009-04-24 03:28:54428void TabContents::DidBecomeSelected() {
429 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16430 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
431 if (rwhv) {
432 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43433#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16434 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43435#endif
436 }
[email protected]96d185d2009-04-24 03:28:54437
[email protected]5ac20162010-11-24 23:33:11438 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38439
440 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54441}
442
443void TabContents::WasHidden() {
444 if (!capturing_contents()) {
445 // |render_view_host()| can be NULL if the user middle clicks a link to open
446 // a tab in then background, then closes the tab before selecting it. This
447 // is because closing the tab calls TabContents::Destroy(), which removes
448 // the |render_view_host()|; then when we actually destroy the window,
449 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16450 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
451 if (rwhv)
452 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54453 }
454
455 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27456 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]96d185d2009-04-24 03:28:54457 Source<TabContents>(this),
458 NotificationService::NoDetails());
459}
460
[email protected]d5f942ba2008-09-26 19:30:34461void TabContents::Activate() {
462 if (delegate_)
463 delegate_->ActivateContents(this);
464}
465
[email protected]ea42e7782010-08-23 23:58:12466void TabContents::Deactivate() {
467 if (delegate_)
468 delegate_->DeactivateContents(this);
469}
470
[email protected]63954792011-07-11 04:17:48471void TabContents::LostCapture() {
472 if (delegate_)
473 delegate_->LostCapture();
474}
475
476bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
477 bool* is_keyboard_shortcut) {
478 return delegate_ &&
479 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
480}
481
482void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
483 if (delegate_)
484 delegate_->HandleKeyboardEvent(event);
485}
486
487void TabContents::HandleMouseUp() {
488 if (delegate_)
489 delegate_->HandleMouseUp();
490}
491
492void TabContents::HandleMouseActivate() {
493 if (delegate_)
494 delegate_->HandleMouseActivate();
495}
496
[email protected]8a5e0ca2011-08-25 06:30:47497void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
498 if (delegate_)
499 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
500}
501
[email protected]5d5f7af2011-10-01 01:38:12502bool TabContents::IsFullscreenForCurrentTab() const {
503 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
504}
505
[email protected]0548c5352011-09-07 00:33:33506void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
507 if (delegate_)
508 delegate_->UpdatePreferredSize(this, pref_size);
509}
510
[email protected]96d185d2009-04-24 03:28:54511void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16512 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
513 if (rwhv)
514 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54515}
516
517void TabContents::HideContents() {
518 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
519 // our superclass HideContents(), because some callers want to be very picky
520 // about the order in which these get called. In addition to making the code
521 // here practically impossible to understand, this also means we end up
522 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34523 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54524 WasHidden();
525}
526
[email protected]5aab5e22010-12-08 22:13:29527bool TabContents::NeedToFireBeforeUnload() {
528 // TODO(creis): Should we fire even for interstitial pages?
529 return notify_disconnection() &&
530 !showing_interstitial_page() &&
531 !render_view_host()->SuddenTerminationAllowed();
532}
533
[email protected]00c37fc2011-08-02 00:22:50534// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25535TabContents* TabContents::OpenURL(const GURL& url,
536 const GURL& referrer,
537 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58538 content::PageTransition transition) {
[email protected]e47ae9472011-10-13 19:48:34539 return OpenURL(OpenURLParams(url, referrer, disposition, transition,
540 false));
[email protected]00c37fc2011-08-02 00:22:50541}
542
543TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49544 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50545 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49546 // Notify observers.
547 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50548 DidOpenURL(params.url, params.referrer,
549 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25550 return new_contents;
[email protected]1c642b52011-04-15 09:05:49551 }
[email protected]992e4542011-07-20 23:09:25552 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34553}
554
[email protected]1ccb3568d2010-02-19 10:51:16555bool TabContents::NavigateToPendingEntry(
556 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54557 return NavigateToEntry(*controller_.pending_entry(), reload_type);
558}
[email protected]96d185d2009-04-24 03:28:54559
[email protected]876bc832010-09-07 16:29:54560bool TabContents::NavigateToEntry(
561 const NavigationEntry& entry,
562 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40563 // The renderer will reject IPC messages with URLs longer than
564 // this limit, so don't attempt to navigate with a longer URL.
565 if (entry.url().spec().size() > content::kMaxURLChars)
566 return false;
567
[email protected]ffc906f2011-10-04 22:55:40568 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
569 if (!dest_render_view_host)
570 return false; // Unable to create the desired render view host.
571
[email protected]80a8fad2011-01-29 04:02:38572 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07573 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58574 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56575 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37576 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]1fd1a502011-03-30 16:55:56577 entry.url());
[email protected]e091df82011-10-11 18:13:21578 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55579 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58580
[email protected]96d185d2009-04-24 03:28:54581 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12582 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32583 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00584 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
585 dest_render_view_host,
586 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32587 }
[email protected]96d185d2009-04-24 03:28:54588
589 // Used for page load time metrics.
590 current_load_start_ = base::TimeTicks::Now();
591
592 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34593 ViewMsg_Navigate_Params navigate_params;
[email protected]6c6b02d2011-09-02 03:36:47594 MakeNavigateParams(entry, controller_, delegate_, reload_type,
595 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34596 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54597
598 if (entry.page_id() == -1) {
599 // HACK!! This code suppresses javascript: URLs from being added to
600 // session history, which is what we want to do for javascript: URLs that
601 // do not generate content. What we really need is a message from the
602 // renderer telling us that a new page was not created. The same message
603 // could be used for mailto: URLs and the like.
604 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
605 return false;
606 }
607
[email protected]3c9e1872010-11-18 16:17:49608 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04609 FOR_EACH_OBSERVER(TabContentsObserver,
610 observers_,
611 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54612
[email protected]09b29342011-06-24 19:18:48613 if (delegate_)
614 delegate_->DidNavigateToPendingEntry(this);
615
[email protected]d5f942ba2008-09-26 19:30:34616 return true;
617}
618
[email protected]9e1ad4b2011-08-14 16:49:19619void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
620 int history_length,
621 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41622 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
623 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19624 if (render_manager_.pending_render_view_host()) {
625 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14626 return;
[email protected]9e1ad4b2011-08-14 16:49:19627 }
628 RenderViewHost* rvh = render_view_host();
629 if (!rvh) {
630 NOTREACHED();
631 return;
632 }
633 if (site_instance && rvh->site_instance() != site_instance) {
634 NOTREACHED();
635 return;
636 }
637 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
638 history_length,
639 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14640}
641
[email protected]96d185d2009-04-24 03:28:54642void TabContents::Stop() {
643 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47644 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54645}
646
[email protected]96d185d2009-04-24 03:28:54647TabContents* TabContents::Clone() {
648 // We create a new SiteInstance so that the new tab won't share processes
649 // with the old one. This can be changed in the future if we need it to share
650 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37651 TabContents* tc = new TabContents(
652 browser_context(),
653 SiteInstance::CreateSiteInstance(browser_context()),
654 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54655 tc->controller().CopyStateFrom(controller_);
656 return tc;
657}
658
[email protected]4d677202009-07-19 07:37:12659void TabContents::ShowPageInfo(const GURL& url,
660 const NavigationEntry::SSLStatus& ssl,
661 bool show_history) {
662 if (!delegate_)
663 return;
664
[email protected]3d7474ff2011-07-27 17:47:37665 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12666}
667
[email protected]e7cfdbd2011-04-22 14:41:37668void TabContents::AddNewContents(TabContents* new_contents,
669 WindowOpenDisposition disposition,
670 const gfx::Rect& initial_pos,
671 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29672 if (!delegate_)
673 return;
674
[email protected]e7cfdbd2011-04-22 14:41:37675 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
676 user_gesture);
[email protected]96d185d2009-04-24 03:28:54677}
678
[email protected]5c9e97a2009-09-09 23:48:30679gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54680 return view_->GetContentNativeView();
681}
682
683gfx::NativeView TabContents::GetNativeView() const {
684 return view_->GetNativeView();
685}
686
687void TabContents::GetContainerBounds(gfx::Rect *out) const {
688 view_->GetContainerBounds(out);
689}
690
691void TabContents::Focus() {
692 view_->Focus();
693}
694
[email protected]90daadb42009-06-08 21:27:28695void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54696 if (showing_interstitial_page()) {
697 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
698 return;
699 }
[email protected]96d185d2009-04-24 03:28:54700 render_view_host()->SetInitialFocus(reverse);
701}
702
703bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40704 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58705 if (web_ui)
706 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43707 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25708 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43709 return true;
[email protected]96d185d2009-04-24 03:28:54710 return false;
711}
712
[email protected]a26dc362010-04-23 01:48:58713void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38714 if (delegate())
[email protected]a26dc362010-04-23 01:48:58715 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38716}
717
[email protected]686493142011-07-15 21:47:22718bool TabContents::CanDownload(int request_id) {
719 TabContentsDelegate* d = delegate();
720 if (d)
721 return d->CanDownload(this, request_id);
722 return true;
723}
724
725void TabContents::OnStartDownload(DownloadItem* download) {
726 TabContentsDelegate* d = delegate();
727 if (d)
728 d->OnStartDownload(this, download);
729}
730
[email protected]c7dd2f62011-07-18 15:57:59731void TabContents::OnSavePage() {
732 // If we can not save the page, try to download it.
733 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37734 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59735 const GURL& current_page_url = GetURL();
736 if (dlm && current_page_url.is_valid()) {
737 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46738 download_stats::RecordDownloadCount(
739 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59740 return;
741 }
742 }
743
744 Stop();
745
746 // Create the save package and possibly prompt the user for the name to save
747 // the page as. The user prompt is an asynchronous operation that runs on
748 // another thread.
749 save_package_ = new SavePackage(this);
750 save_package_->GetSaveInfo();
751}
752
753// Used in automated testing to bypass prompting the user for file names.
754// Instead, the names and paths are hard coded rather than running them through
755// file name sanitation and extension / mime checking.
756bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
757 SavePackage::SavePackageType save_type) {
758 // Stop the page from navigating.
759 Stop();
760
761 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
762 return save_package_->Init();
763}
764
765void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37766 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59767 dlm->DownloadUrl(url, GetURL(), "", this);
768}
769
[email protected]420ae012009-04-24 05:16:32770bool TabContents::IsActiveEntry(int32 page_id) {
771 NavigationEntry* active_entry = controller_.GetActiveEntry();
772 return (active_entry != NULL &&
773 active_entry->site_instance() == GetSiteInstance() &&
774 active_entry->page_id() == page_id);
775}
776
[email protected]b2fe07d12010-02-09 14:38:08777void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16778 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26779 render_view_host()->Send(new ViewMsg_SetPageEncoding(
780 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16781}
782
[email protected]b2fe07d12010-02-09 14:38:08783void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16784 reset_encoding();
[email protected]216813952011-05-19 22:21:26785 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
786 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16787}
788
[email protected]7ab1e7d62009-10-14 23:32:01789void TabContents::OnCloseStarted() {
790 if (tab_close_start_time_.is_null())
791 tab_close_start_time_ = base::TimeTicks::Now();
792}
793
[email protected]46624bf2010-06-09 16:04:19794bool TabContents::ShouldAcceptDragAndDrop() const {
795#if defined(OS_CHROMEOS)
796 // ChromeOS panels (pop-ups) do not take drag-n-drop.
797 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14798 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20799 return false;
800 return true;
[email protected]46624bf2010-06-09 16:04:19801#else
802 return true;
803#endif
804}
805
[email protected]7813bd72011-02-05 02:19:34806void TabContents::SystemDragEnded() {
807 if (render_view_host())
808 render_view_host()->DragSourceSystemDragEnded();
809 if (delegate())
810 delegate()->DragEnded();
811}
812
[email protected]d0b8d092010-10-25 04:05:17813double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37814 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25815 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17816 return 0;
[email protected]b75b8292010-10-01 07:28:25817
818 double zoom_level;
819 if (temporary_zoom_settings_) {
820 zoom_level = zoom_map->GetTemporaryZoomLevel(
821 GetRenderProcessHost()->id(), render_view_host()->routing_id());
822 } else {
[email protected]13ffa32e2011-05-27 16:37:01823 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(GetURL()));
[email protected]b75b8292010-10-01 07:28:25824 }
[email protected]d0b8d092010-10-25 04:05:17825 return zoom_level;
826}
[email protected]b75b8292010-10-01 07:28:25827
[email protected]d0b8d092010-10-25 04:05:17828int TabContents::GetZoomPercent(bool* enable_increment,
829 bool* enable_decrement) {
830 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:25831 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:17832 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:25833 *enable_decrement = percent > minimum_zoom_percent_;
834 *enable_increment = percent < maximum_zoom_percent_;
835 return percent;
836}
837
[email protected]3c733bde2010-12-21 19:56:31838void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50839 if (!delegate_)
840 return;
841
842 NavigationEntry* active_entry = controller().GetActiveEntry();
843 if (!active_entry)
844 return;
845
846 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12847}
848
[email protected]932b7a12011-03-09 12:50:27849void TabContents::ViewFrameSource(const GURL& url,
850 const std::string& content_state) {
851 if (!delegate_)
852 return;
853
854 delegate_->ViewSourceForFrame(this, url, content_state);
855}
856
[email protected]c40d6232011-03-25 00:16:21857void TabContents::SetContentRestrictions(int restrictions) {
858 content_restrictions_ = restrictions;
859 delegate()->ContentRestrictionsChanged(this);
860}
861
[email protected]724159a2010-12-30 01:11:18862void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
863 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59864 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18865 const GURL& url) {
866 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
867 GURL validated_url(url);
868 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
869 GetRenderProcessHost()->id(), &validated_url);
870
[email protected]8093a542011-05-13 07:29:32871 RenderViewHost* rvh =
872 render_manager_.pending_render_view_host() ?
873 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10874 // Notify observers about the start of the provisional load.
875 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
876 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32877 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10878
[email protected]724159a2010-12-30 01:11:18879 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59880 // Notify observers about the provisional change in the main frame URL.
881 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59882 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18883 }
884}
885
886void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59887 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18888 const GURL& source_url,
889 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49890 // TODO(creis): Remove this method and have the pre-rendering code listen to
891 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
892 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18893 NavigationEntry* entry;
894 if (page_id == -1)
895 entry = controller_.pending_entry();
896 else
897 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
898 if (!entry || entry->url() != source_url)
899 return;
[email protected]e7d50892011-01-19 21:47:38900
[email protected]4850a7f2011-03-08 23:36:59901 // Notify observers about the provisional change in the main frame URL.
902 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26903 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59904 opener_url));
[email protected]724159a2010-12-30 01:11:18905}
906
907void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58908 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
909 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
910 << ", error_code: " << params.error_code
911 << ", error_description: " << params.error_description
912 << ", is_main_frame: " << params.is_main_frame
913 << ", showing_repost_interstitial: " <<
914 params.showing_repost_interstitial
915 << ", frame_id: " << params.frame_id;
916 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18917 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
918 GetRenderProcessHost()->id(), &validated_url);
919
[email protected]d7b175e2011-10-11 15:31:58920 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18921 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
922 // This means that the interstitial won't be torn down properly, which is
923 // bad. But if we have an interstitial, go back to another tab type, and
924 // then load the same interstitial again, we could end up getting the first
925 // interstitial's "failed" message (as a result of the cancel) when we're on
926 // the second one.
927 //
928 // We can't tell this apart, so we think we're tearing down the current page
929 // which will cause a crash later one. There is also some code in
930 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
931 // out because of this problem.
932 //
933 // http://code.google.com/p/chromium/issues/detail?id=2855
934 // Because this will not tear down the interstitial properly, if "back" is
935 // back to another tab type, the interstitial will still be somewhat alive
936 // in the previous tab type. If you navigate somewhere that activates the
937 // tab with the interstitial again, you'll see a flash before the new load
938 // commits of the interstitial page.
939 if (showing_interstitial_page()) {
940 LOG(WARNING) << "Discarding message during interstitial.";
941 return;
942 }
943
[email protected]02102f82011-06-13 20:37:02944 // Discard our pending entry if the load canceled (e.g. if we decided to
945 // download the file instead of load it). We do not verify that the URL
946 // being canceled matches the pending entry's URL because they will not
947 // match if a redirect occurred (in which case we do not want to leave a
948 // stale redirect URL showing). This means that we also cancel the pending
949 // entry if the user started a new navigation. As a result, the navigation
950 // controller may not remember that a load is in progress, but the
951 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:18952 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:02953 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:16954 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:18955
956 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
957 }
958
959 // Send out a notification that we failed a provisional load with an error.
960 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:58961 params.is_main_frame,
962 controller_.IsURLInPageNavigation(validated_url),
963 validated_url,
964 std::string(),
965 false,
966 params.frame_id);
967 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:18968
969 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27970 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]724159a2010-12-30 01:11:18971 Source<NavigationController>(&controller_),
972 Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:10973
[email protected]d7b175e2011-10-11 15:31:58974 FOR_EACH_OBSERVER(TabContentsObserver,
975 observers_,
976 DidFailProvisionalLoad(params.frame_id,
977 params.is_main_frame,
978 validated_url,
979 params.error_code,
980 params.error_description));
[email protected]724159a2010-12-30 01:11:18981}
982
983void TabContents::OnDidLoadResourceFromMemoryCache(
984 const GURL& url,
[email protected]70435962011-08-02 20:13:28985 const std::string& security_info,
986 const std::string& http_method,
987 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:19988 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:18989 cache.Increment();
990
991 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:08992 int cert_id = 0;
993 net::CertStatus cert_status = 0;
994 int security_bits = -1;
995 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:18996 SSLManager::DeserializeSecurityInfo(security_info,
997 &cert_id, &cert_status,
998 &security_bits,
999 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161000 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1001 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181002
1003 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271004 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]724159a2010-12-30 01:11:181005 Source<NavigationController>(&controller_),
1006 Details<LoadFromMemoryCacheDetails>(&details));
1007}
1008
1009void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161010 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181011 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071012 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181013}
1014
1015void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021016 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231017 LOG(INFO) << security_origin << " ran insecure content from "
1018 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161019 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051020 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
1021 UserMetrics::RecordAction(
1022 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1023 }
[email protected]724159a2010-12-30 01:11:181024 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411025 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071026 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181027}
1028
1029void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1030 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101031 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1032 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181033}
1034
1035void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:101036 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1037 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:181038}
1039
[email protected]c8f73ab2011-01-22 00:05:171040void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211041 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171042}
1043
[email protected]216813952011-05-19 22:21:261044void TabContents::OnGoToEntryAtOffset(int offset) {
1045 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1046 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1047 if (!entry)
1048 return;
1049 // Note that we don't call NavigationController::GotToOffset() as we don't
1050 // want to create a pending navigation entry (it might end up lingering
1051 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581052 entry->set_transition_type(
1053 content::PageTransitionFromInt(
1054 entry->transition_type() |
1055 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]216813952011-05-19 22:21:261056 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571057
1058 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1059 // it in now that we know. This allows us to find the entry when it commits.
1060 if (!entry->site_instance() &&
1061 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381062 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571063 }
[email protected]216813952011-05-19 22:21:261064 }
1065}
1066
1067void TabContents::OnUpdateZoomLimits(int minimum_percent,
1068 int maximum_percent,
1069 bool remember) {
1070 minimum_zoom_percent_ = minimum_percent;
1071 maximum_zoom_percent_ = maximum_percent;
1072 temporary_zoom_settings_ = !remember;
1073}
1074
1075void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
1076 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271077 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]216813952011-05-19 22:21:261078 Source<TabContents>(this),
1079 Details<const bool>(&is_editable_node));
1080}
1081
[email protected]3a29a6e2011-08-24 18:26:211082void TabContents::OnEnumerateDirectory(int request_id,
1083 const FilePath& path) {
1084 delegate()->EnumerateDirectory(this, request_id, path);
1085}
1086
[email protected]7d189022011-08-25 22:54:201087void TabContents::OnJSOutOfMemory() {
1088 delegate()->JSOutOfMemory(this);
1089}
1090
1091void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1092 const GURL& url,
1093 const string16& title) {
1094 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1095}
1096
1097void TabContents::OnRegisterIntentHandler(const string16& action,
1098 const string16& type,
1099 const string16& href,
1100 const string16& title) {
1101 delegate()->RegisterIntentHandler(this, action, type, href, title);
1102}
1103
1104void TabContents::OnWebIntentDispatch(const IPC::Message& message,
[email protected]ce9751942011-09-21 01:57:241105 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:201106 int intent_id) {
[email protected]ce9751942011-09-21 01:57:241107 delegate()->WebIntentDispatch(this, message.routing_id(), intent, intent_id);
[email protected]7d189022011-08-25 22:54:201108}
1109
[email protected]b888919c2011-09-02 00:32:161110void TabContents::OnFindReply(int request_id,
1111 int number_of_matches,
1112 const gfx::Rect& selection_rect,
1113 int active_match_ordinal,
1114 bool final_update) {
1115 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1116 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001117 // Send a notification to the renderer that we are ready to receive more
1118 // results from the scoping effort of the Find operation. The FindInPage
1119 // scoping is asynchronous and periodically sends results back up to the
1120 // browser using IPC. In an effort to not spam the browser we have the
1121 // browser send an ACK for each FindReply message and have the renderer
1122 // queue up the latest status message while waiting for this ACK.
1123 render_view_host()->Send(
1124 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161125}
1126
[email protected]d952a052011-09-06 18:42:451127void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1128 delegate()->CrashedPlugin(this, plugin_path);
1129}
1130
[email protected]7fc4bbb2011-09-08 21:23:101131void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1132 bool blocked_by_policy) {
1133 // Notify observers about navigation.
1134 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1135 AppCacheAccessed(manifest_url, blocked_by_policy));
1136}
1137
[email protected]96d185d2009-04-24 03:28:541138// Notifies the RenderWidgetHost instance about the fact that the page is
1139// loading, or done loading and calls the base implementation.
1140void TabContents::SetIsLoading(bool is_loading,
1141 LoadNotificationDetails* details) {
1142 if (is_loading == is_loading_)
1143 return;
1144
1145 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211146 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541147 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561148 upload_size_ = 0;
1149 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541150 }
1151
1152 render_manager_.SetIsLoading(is_loading);
1153
1154 is_loading_ = is_loading;
1155 waiting_for_response_ = is_loading;
1156
[email protected]6ebdc9b2010-09-27 16:55:571157 if (delegate_)
1158 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351159 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541160
[email protected]432115822011-07-10 15:52:271161 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1162 content::NOTIFICATION_LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111163 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541164 if (details)
1165 det = Details<LoadNotificationDetails>(details);
1166 NotificationService::current()->Notify(type,
1167 Source<NavigationController>(&controller_),
1168 det);
1169}
1170
[email protected]d0980792011-02-13 19:41:401171WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581172 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541173 // that goes along with it to control the basic flags. For example, we want to
1174 // show the pending URL in the URL bar, so we want the display_url flag to
1175 // be from the pending entry.
1176 //
1177 // The confusion comes because there are multiple possibilities for the
1178 // initial load in a tab as a side effect of the way the RenderViewHostManager
1179 // works.
1180 //
[email protected]e0112912011-02-02 22:54:351181 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541182 // the pending one, and we want it to apply here.
1183 //
1184 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1185 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581186 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351187 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541188 //
1189 // This condition handles all of these cases:
1190 //
1191 // - First load in first tab: no committed nav entry + pending nav entry +
1192 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351193 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541194 //
1195 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351196 // no pending Web UI:
1197 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541198 //
1199 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351200 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541201 //
1202 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351203 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541204 if (controller_.pending_entry() &&
1205 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581206 render_manager_.pending_web_ui()))
1207 return render_manager_.pending_web_ui();
1208 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541209}
[email protected]420ae012009-04-24 05:16:321210
[email protected]1fd1a502011-03-30 16:55:561211WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371212 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1213 GetURL());
[email protected]1fd1a502011-03-30 16:55:561214}
1215
[email protected]420ae012009-04-24 05:16:321216void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131217 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321218 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561219 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381220 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441221 // that opened the window, as long as both renderers have the same
1222 // privileges.
[email protected]1fd1a502011-03-30 16:55:561223 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1224 WebUI* web_ui = content::GetContentClient()->browser()->
1225 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581226 // web_ui might be NULL if the URL refers to a non-existent extension.
1227 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401228 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581229 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441230 }
1231 }
[email protected]1fd1a502011-03-30 16:55:561232 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441233 }
1234
[email protected]4e697b042011-07-08 06:44:561235 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321236 // Clear the status bubble. This is a workaround for a bug where WebKit
1237 // doesn't let us know that the cursor left an element during a
1238 // transition (this is also why the mouse cursor remains as a hand after
1239 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1240 // clear the bubble when a user navigates to a named anchor in the same
1241 // page.
1242 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321243 }
1244
[email protected]a6e82fc2010-02-24 22:28:141245 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471246 // Once the main frame is navigated, we're no longer considered to have
1247 // displayed insecure content.
1248 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171249 }
[email protected]ce5c4502009-05-06 16:46:111250
[email protected]3c9e1872010-11-18 16:17:491251 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171252 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491253 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321254}
1255
1256void TabContents::DidNavigateAnyFramePostCommit(
1257 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131258 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321259 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071260 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321261 // a malicious script from spamming messages, since the script could just
1262 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551263 if (dialog_creator_) {
1264 dialog_creator_->ResetJavaScriptState(this);
1265 dialog_creator_ = NULL;
1266 }
[email protected]420ae012009-04-24 05:16:321267
[email protected]3c9e1872010-11-18 16:17:491268 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171269 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491270 DidNavigateAnyFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321271}
1272
[email protected]420ae012009-04-24 05:16:321273void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1274 RenderViewHost* rvh) {
1275 // If we are creating a RVH for a restored controller, then we might
1276 // have more page IDs than the SiteInstance's current max page ID. We must
1277 // make sure that the max page ID is larger than any restored page ID.
1278 // Note that it is ok for conflicting page IDs to exist in another tab
1279 // (i.e., NavigationController), but if any page ID is larger than the max,
1280 // the back/forward list will get confused.
1281 int max_restored_page_id = controller_.max_restored_page_id();
1282 if (max_restored_page_id > 0) {
1283 int curr_max_page_id = site_instance->max_page_id();
1284 if (max_restored_page_id > curr_max_page_id) {
1285 // Need to update the site instance immediately.
1286 site_instance->UpdateMaxPageID(max_restored_page_id);
1287
1288 // Also tell the renderer to update its internal representation. We
1289 // need to reserve enough IDs to make all restored page IDs less than
1290 // the max.
1291 if (curr_max_page_id < 0)
1292 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261293 rvh->Send(new ViewMsg_ReservePageIDRange(
1294 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321295 }
1296 }
1297}
1298
[email protected]6b2f7a82011-04-25 19:30:511299bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571300 const string16& title) {
[email protected]420ae012009-04-24 05:16:321301 // For file URLs without a title, use the pathname instead. In the case of a
1302 // synthesized title, we don't want the update to count toward the "one set
1303 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511304 string16 final_title;
[email protected]420ae012009-04-24 05:16:321305 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091306 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511307 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321308 explicit_set = false; // Don't count synthetic titles toward the set limit.
1309 } else {
[email protected]acafd272011-07-26 17:35:571310 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321311 explicit_set = true;
1312 }
1313
[email protected]987fc3a2011-05-26 14:18:091314 // If a page is created via window.open and never navigated,
1315 // there will be no navigation entry. In this situation,
1316 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1317 if (entry) {
1318 if (final_title == entry->title())
1319 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321320
[email protected]987fc3a2011-05-26 14:18:091321 entry->set_title(final_title);
1322 } else {
1323 if (page_title_when_no_navigation_entry_ == final_title)
1324 return false; // Nothing changed, don't bother.
1325
1326 page_title_when_no_navigation_entry_ = final_title;
1327 }
[email protected]420ae012009-04-24 05:16:321328
[email protected]420ae012009-04-24 05:16:321329 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231330 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321331
[email protected]105bb0f2011-05-24 17:12:141332 TitleUpdatedDetails details(entry, explicit_set);
1333
[email protected]cbc0e1b2010-04-12 18:33:041334 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271335 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]cbc0e1b2010-04-12 18:33:041336 Source<TabContents>(this),
[email protected]105bb0f2011-05-24 17:12:141337 Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041338
[email protected]420ae012009-04-24 05:16:321339 return true;
1340}
1341
1342void TabContents::NotifySwapped() {
1343 // After sending out a swap notification, we need to send a disconnect
1344 // notification so that clients that pick up a pointer to |this| can NULL the
1345 // pointer. See Bug 1230284.
1346 notify_disconnection_ = true;
1347 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271348 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221349 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321350 NotificationService::NoDetails());
1351}
1352
1353void TabContents::NotifyConnected() {
1354 notify_disconnection_ = true;
1355 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271356 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221357 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321358 NotificationService::NoDetails());
1359}
1360
1361void TabContents::NotifyDisconnected() {
1362 if (!notify_disconnection_)
1363 return;
1364
1365 notify_disconnection_ = false;
1366 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271367 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221368 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321369 NotificationService::NoDetails());
1370}
1371
[email protected]8d3347f2009-07-09 22:00:211372RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321373 return view_.get();
1374}
1375
[email protected]8d3347f2009-07-09 22:00:211376RenderViewHostDelegate::RendererManagement*
1377TabContents::GetRendererManagementDelegate() {
1378 return &render_manager_;
1379}
1380
[email protected]3d7474ff2011-07-27 17:47:371381RendererPreferences TabContents::GetRendererPrefs(
1382 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461383 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511384}
1385
[email protected]57c6a652009-05-04 07:58:341386TabContents* TabContents::GetAsTabContents() {
1387 return this;
1388}
1389
[email protected]da4dfc42011-10-12 15:53:561390content::ViewType TabContents::GetRenderViewType() const {
1391 return content::VIEW_TYPE_TAB_CONTENTS;
[email protected]7b291f92009-08-14 05:43:531392}
1393
[email protected]420ae012009-04-24 05:16:321394void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061395 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271396 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]2e4633c2009-07-09 16:58:061397 Source<TabContents>(this),
1398 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321399 NavigationEntry* entry = controller_.GetActiveEntry();
1400 if (!entry)
1401 return;
1402
1403 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351404 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561405 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581406 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321407
1408 if (entry->IsViewSourceMode()) {
1409 // Put the renderer in view source mode.
1410 render_view_host->Send(
1411 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1412 }
[email protected]0666aef2009-05-13 19:48:081413
1414 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261415
1416 FOR_EACH_OBSERVER(
1417 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321418}
1419
1420void TabContents::RenderViewReady(RenderViewHost* rvh) {
1421 if (rvh != render_view_host()) {
1422 // Don't notify the world, since this came from a renderer in the
1423 // background.
1424 return;
1425 }
1426
1427 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301428 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231429 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301430
1431 // Restore the focus to the tab (otherwise the focus will be on the top
1432 // window).
[email protected]484ae5912010-09-29 19:16:141433 if (was_crashed && !FocusLocationBarByDefault() &&
1434 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301435 Focus();
[email protected]484ae5912010-09-29 19:16:141436 }
[email protected]420ae012009-04-24 05:16:321437}
1438
[email protected]443b80e2010-12-14 00:42:231439void TabContents::RenderViewGone(RenderViewHost* rvh,
1440 base::TerminationStatus status,
1441 int error_code) {
[email protected]420ae012009-04-24 05:16:321442 if (rvh != render_view_host()) {
1443 // The pending page's RenderViewHost is gone.
1444 return;
1445 }
1446
1447 SetIsLoading(false, NULL);
1448 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231449 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541450 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321451
[email protected]55452902011-06-01 21:57:471452 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
[email protected]420ae012009-04-24 05:16:321453}
1454
[email protected]2e4633c2009-07-09 16:58:061455void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481456 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061457}
1458
[email protected]420ae012009-04-24 05:16:321459void TabContents::DidNavigate(RenderViewHost* rvh,
1460 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581461 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321462 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371463
[email protected]420ae012009-04-24 05:16:321464 // Update the site of the SiteInstance if it doesn't have one yet.
1465 if (!GetSiteInstance()->has_site())
1466 GetSiteInstance()->SetSite(params.url);
1467
1468 // Need to update MIME type here because it's referred to in
1469 // UpdateNavigationCommands() called by RendererDidNavigate() to
1470 // determine whether or not to enable the encoding menu.
1471 // It's updated only for the main frame. For a subframe,
1472 // RenderView::UpdateURL does not set params.contents_mime_type.
1473 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1474 // TODO(jungshik): Add a test for the encoding menu to avoid
1475 // regressing it again.
[email protected]2905f742011-10-13 03:51:581476 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321477 contents_mime_type_ = params.contents_mime_type;
1478
[email protected]8286f51a2011-05-31 17:39:131479 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001480 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391481
[email protected]a9c0bfe2010-09-17 08:35:221482 // Send notification about committed provisional loads. This notification is
1483 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1484 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1485 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071486 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1487 // that is not recorded in the navigation history. For the purpose of
1488 // tracking navigation events, we treat this event as a sub frame navigation
1489 // event.
1490 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581491 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221492 // Whether or not a page transition was triggered by going backward or
1493 // forward in the history is only stored in the navigation controller's
1494 // entry list.
1495 if (did_navigate &&
1496 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581497 content::PAGE_TRANSITION_FORWARD_BACK)) {
1498 transition_type = content::PageTransitionFromInt(
1499 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221500 }
[email protected]0d60f0192011-04-14 12:40:101501 // Notify observers about the commit of the provisional load.
1502 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1503 DidCommitProvisionalLoadForFrame(params.frame_id,
1504 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221505 }
1506
[email protected]76543b92009-08-31 17:27:451507 if (!did_navigate)
1508 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321509
1510 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1511 // for the appropriate notification (best) or you can add it to
1512 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1513 // necessary, please).
1514
1515 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001516 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321517 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481518 if (delegate())
1519 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001520 }
[email protected]420ae012009-04-24 05:16:321521 DidNavigateAnyFramePostCommit(rvh, details, params);
1522}
1523
1524void TabContents::UpdateState(RenderViewHost* rvh,
1525 int32 page_id,
1526 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151527 // Ensure that this state update comes from either the active RVH or one of
1528 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1529 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321530
1531 // We must be prepared to handle state updates for any page, these occur
1532 // when the user is scrolling and entering form data, as well as when we're
1533 // leaving a page, in which case our state may have already been moved to
1534 // the next page. The navigation controller will look up the appropriate
1535 // NavigationEntry and update it when it is notified via the delegate.
1536
1537 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151538 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321539 if (entry_index < 0)
1540 return;
1541 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1542
1543 if (state == entry->content_state())
1544 return; // Nothing to update.
1545 entry->set_content_state(state);
1546 controller_.NotifyEntryChanged(entry, entry_index);
1547}
1548
1549void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571550 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461551 const string16& title,
1552 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321553 // If we have a title, that's a pretty good indication that we've started
1554 // getting useful data.
1555 SetNotWaitingForResponse();
1556
1557 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481558 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581559 page_id);
[email protected]987fc3a2011-05-26 14:18:091560
[email protected]a49e10b2011-08-01 23:57:461561 // TODO(evan): make use of title_direction.
1562 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091563 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321564 return;
1565
1566 // Broadcast notifications when the UI should be updated.
1567 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031568 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321569}
1570
[email protected]420ae012009-04-24 05:16:321571void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401572 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321573 set_encoding(encoding);
1574}
1575
1576void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1577 if (delegate())
[email protected]d952a052011-09-06 18:42:451578 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321579}
1580
[email protected]420ae012009-04-24 05:16:321581void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291582 // The UI may be in an event-tracking loop, such as between the
1583 // mouse-down and mouse-up in text selection or a button click.
1584 // Defer the close until after tracking is complete, so that we
1585 // don't free objects out from under the UI.
1586 // TODO(shess): This could probably be integrated with the
1587 // IsDoingDrag() test below. Punting for now because I need more
1588 // research to understand how this impacts platforms other than Mac.
1589 // TODO(shess): This could get more fine-grained. For instance,
1590 // closing a tab in another window while selecting text in the
1591 // current window's Omnibox should be just fine.
1592 if (view()->IsEventTracking()) {
1593 view()->CloseTabAfterEventTracking();
1594 return;
1595 }
1596
[email protected]24a4d1062009-07-10 23:10:421597 // If we close the tab while we're in the middle of a drag, we'll crash.
1598 // Instead, cancel the drag and close it as soon as the drag ends.
1599 if (view()->IsDoingDrag()) {
1600 view()->CancelDragAndCloseTab();
1601 return;
1602 }
1603
[email protected]420ae012009-04-24 05:16:321604 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1605 if (delegate() && rvh == render_view_host())
1606 delegate()->CloseContents(this);
1607}
1608
1609void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141610 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321611 delegate()->MoveContents(this, new_bounds);
1612}
1613
[email protected]7ab1e7d62009-10-14 23:32:011614void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321615 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491616
[email protected]c40d6232011-03-25 00:16:211617 if (delegate() && content_restrictions_) {
1618 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211619 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001620 }
[email protected]3c9e1872010-11-18 16:17:491621
1622 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171623 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321624}
1625
[email protected]7ab1e7d62009-10-14 23:32:011626void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321627 scoped_ptr<LoadNotificationDetails> details;
1628
1629 NavigationEntry* entry = controller_.GetActiveEntry();
1630 // An entry may not exist for a stop when loading an initial blank page or
1631 // if an iframe injected by script into a blank page finishes loading.
1632 if (entry) {
[email protected]420ae012009-04-24 05:16:321633 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1634
1635 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541636 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321637 entry->transition_type(),
1638 elapsed,
1639 &controller_,
1640 controller_.GetCurrentEntryIndex()));
1641 }
1642
[email protected]420ae012009-04-24 05:16:321643 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491644
1645 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171646 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321647}
1648
[email protected]c95fa8b2011-04-28 20:26:161649void TabContents::DidCancelLoading() {
1650 controller_.DiscardNonCommittedEntries();
1651
1652 // Update the URL display.
1653 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1654}
1655
[email protected]1a3c3cb2010-12-16 21:03:401656void TabContents::DidChangeLoadProgress(double progress) {
1657 if (delegate())
1658 delegate()->LoadProgressChanged(progress);
1659}
1660
[email protected]25497492010-09-11 15:15:081661void TabContents::DocumentOnLoadCompletedInMainFrame(
1662 RenderViewHost* render_view_host,
1663 int32 page_id) {
1664 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271665 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]25497492010-09-11 15:15:081666 Source<TabContents>(this),
1667 Details<int>(&page_id));
1668}
1669
[email protected]ae5184d62011-10-06 19:25:581670void TabContents::RequestOpenURL(const GURL& url,
1671 const GURL& referrer,
1672 WindowOpenDisposition disposition,
1673 int64 source_frame_id) {
1674 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581675 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581676 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351677 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321678 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1679 // generated suggestions).
1680 //
[email protected]e0112912011-02-02 22:54:351681 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161682 // want web sites to see a referrer of "chrome://blah" (and some
1683 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321684 // send to the site), so we send no referrer.
[email protected]ae5184d62011-10-06 19:25:581685 new_contents = OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:581686 render_manager_.web_ui()->link_transition_type());
[email protected]ae5184d62011-10-06 19:25:581687 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321688 } else {
[email protected]e47ae9472011-10-13 19:48:341689 new_contents = OpenURL(OpenURLParams(
1690 url, referrer, disposition, content::PAGE_TRANSITION_LINK,
1691 true /* is_renderer_initiated */));
[email protected]ae5184d62011-10-06 19:25:581692 }
1693 if (new_contents) {
1694 // Notify observers.
1695 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1696 DidOpenRequestedURL(new_contents,
1697 url,
1698 referrer,
1699 disposition,
1700 transition_type,
1701 source_frame_id));
[email protected]420ae012009-04-24 05:16:321702 }
1703}
1704
[email protected]420ae012009-04-24 05:16:321705void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151706 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411707 const string16& message,
1708 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321709 const GURL& frame_url,
1710 const int flags,
1711 IPC::Message* reply_msg,
1712 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071713 // Suppress JavaScript dialogs when requested. Also suppress messages when
1714 // showing an interstitial as it's shown over the previous page and we don't
1715 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501716 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151717 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501718 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071719 !delegate_ ||
1720 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321721
1722 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341723 content::JavaScriptDialogCreator::TitleType title_type;
1724 string16 title;
1725
1726 if (!frame_url.has_host()) {
1727 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1728 } else {
1729 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1730 title = net::FormatUrl(
1731 frame_url.GetOrigin(),
1732 content::GetContentClient()->browser()->GetAcceptLangs(this));
1733 }
1734
[email protected]2e5b90c2011-08-16 21:11:551735 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1736 dialog_creator_->RunJavaScriptDialog(this,
1737 title_type,
1738 title,
1739 flags,
1740 message,
1741 default_prompt,
1742 reply_msg,
1743 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321744 }
[email protected]3ab9cb82011-06-03 18:02:071745
1746 if (suppress_this_message) {
1747 // If we are suppressing messages, just reply as if the user immediately
1748 // pressed "Cancel".
1749 OnDialogClosed(reply_msg, false, string16());
1750 }
1751
1752 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321753}
1754
[email protected]992db4c2011-05-12 15:37:151755void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411756 const string16& message,
[email protected]420ae012009-04-24 05:16:321757 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291758 if (delegate())
1759 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071760
1761 bool suppress_this_message =
1762 rvh->is_swapped_out() ||
1763 !delegate_ ||
1764 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151765 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411766 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501767 return;
1768 }
[email protected]3ab9cb82011-06-03 18:02:071769
[email protected]7ab1e7d62009-10-14 23:32:011770 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551771 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1772 dialog_creator_->RunBeforeUnloadDialog(this,
1773 message,
1774 reply_msg);
[email protected]420ae012009-04-24 05:16:321775}
1776
[email protected]420ae012009-04-24 05:16:321777WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081778 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361779 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]3d7474ff2011-07-27 17:47:371780 render_view_host()->process()->browser_context(), false);
[email protected]447021c2010-09-08 21:29:081781
[email protected]b8299c12011-06-03 19:52:281782 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211783 // chrome-devtools: pages (unless it's specifically allowed).
1784 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571785#if !defined(TOUCH_UI)
1786 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281787 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571788#endif
[email protected]cd4a5bd22011-09-13 06:46:301789 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1790 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211791 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081792 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431793 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081794 }
1795
[email protected]2f7830b32011-08-26 18:22:251796#if defined(TOUCH_UI)
1797 web_prefs.force_compositing_mode = true;
1798#endif
1799
[email protected]447021c2010-09-08 21:29:081800 return web_prefs;
[email protected]420ae012009-04-24 05:16:321801}
1802
[email protected]7d472472011-01-22 01:30:251803void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271804 // Notify observers.
1805 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221806
1807 ResourceDispatcherHost* rdh =
1808 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1809 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301810 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251811}
1812
[email protected]fa1cf0b82010-01-15 21:49:441813void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441814 // Notify observers.
1815 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441816}
1817
[email protected]420ae012009-04-24 05:16:321818void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1819 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151820 // Don't show hung renderer dialog for a swapped out RVH.
1821 if (rvh != render_view_host())
1822 return;
1823
[email protected]e5fc1632011-08-08 07:51:531824 // Ignore renderer unresponsive event if debugger is attached to the tab
1825 // since the event may be a result of the renderer sitting on a breakpoint.
1826 // See http://crbug.com/65458
1827 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
1828 if (devtools_manager &&
1829 devtools_manager->GetDevToolsClientHostFor(rvh) != NULL)
1830 return;
1831
[email protected]420ae012009-04-24 05:16:321832 if (is_during_unload) {
1833 // Hang occurred while firing the beforeunload/unload handler.
1834 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111835 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321836
1837 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1838 return;
1839
1840 // If the tab hangs in the beforeunload/unload handler there's really
1841 // nothing we can do to recover. Pretend the unload listeners have
1842 // all fired and close the tab. If the hang is in the beforeunload handler
1843 // then the user will not have the option of cancelling the close.
1844 Close(rvh);
1845 return;
1846 }
1847
[email protected]55452902011-06-01 21:57:471848 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1849 return;
1850
1851 if (delegate())
1852 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321853}
1854
1855void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471856 if (delegate())
1857 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321858}
1859
1860void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211861 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561862 uint64 upload_position,
1863 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321864 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561865 upload_position_ = upload_position;
1866 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501867 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]b5cca982011-05-26 04:42:081868 content::GetContentClient()->browser()->GetAcceptLangs(this));
[email protected]9c235f042011-08-10 22:28:211869 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321870 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511871 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501872 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321873}
1874
[email protected]7d472472011-01-22 01:30:251875void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441876 if (delegate())
[email protected]55452902011-06-01 21:57:471877 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251878}
1879
[email protected]420ae012009-04-24 05:16:321880void TabContents::BeforeUnloadFiredFromRenderManager(
1881 bool proceed,
1882 bool* proceed_to_fire_unload) {
1883 if (delegate())
1884 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1885}
1886
[email protected]3a3d47472010-07-15 21:03:541887void TabContents::DidStartLoadingFromRenderManager(
1888 RenderViewHost* render_view_host) {
1889 DidStartLoading();
1890}
1891
1892void TabContents::RenderViewGoneFromRenderManager(
1893 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231894 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1895 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541896}
1897
[email protected]420ae012009-04-24 05:16:321898void TabContents::UpdateRenderViewSizeForRenderManager() {
1899 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261900 gfx::Size size = view_->GetContainerSize();
1901 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1902 // here during container initialization and normal window size will be set
1903 // later. In case of tab duplication this resizing to 0x0 prevents setting
1904 // normal size later so just ignore it.
1905 if (!size.IsEmpty())
1906 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321907}
1908
[email protected]3a3d47472010-07-15 21:03:541909void TabContents::NotifySwappedFromRenderManager() {
1910 NotifySwapped();
1911}
1912
1913NavigationController& TabContents::GetControllerForRenderManager() {
1914 return controller();
1915}
1916
[email protected]d0980792011-02-13 19:41:401917WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561918 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321919}
1920
1921NavigationEntry*
1922TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1923 return controller_.GetLastCommittedEntry();
1924}
1925
1926bool TabContents::CreateRenderViewForRenderManager(
1927 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:321928 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:521929
[email protected]420ae012009-04-24 05:16:321930 // Now that the RenderView has been created, we need to tell it its size.
1931 rwh_view->SetSize(view_->GetContainerSize());
1932
[email protected]a4127722011-04-27 23:13:521933 if (!render_view_host->CreateRenderView(string16()))
1934 return false;
1935
[email protected]f8233cc2011-05-31 20:24:501936#if defined(OS_LINUX)
1937 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
1938 // linux. See crbug.com/83941.
1939 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1940 render_widget_host->WasResized();
1941#endif
1942
[email protected]420ae012009-04-24 05:16:321943 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
1944 render_view_host);
1945 return true;
1946}
1947
[email protected]3ab9cb82011-06-03 18:02:071948void TabContents::OnDialogClosed(IPC::Message* reply_msg,
1949 bool success,
1950 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:541951 if (is_showing_before_unload_dialog_ && !success) {
1952 // If a beforeunload dialog is canceled, we need to stop the throbber from
1953 // spinning, since we forced it to start spinning in Navigate.
1954 DidStopLoading();
1955
1956 tab_close_start_time_ = base::TimeTicks();
1957 }
1958 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:411959 render_view_host()->JavaScriptDialogClosed(reply_msg,
1960 success,
[email protected]3ab9cb82011-06-03 18:02:071961 user_input);
[email protected]beb440c2009-11-06 04:08:541962}
1963
[email protected]3ab9cb82011-06-03 18:02:071964gfx::NativeWindow TabContents::GetDialogRootWindow() {
1965 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:541966}
1967
[email protected]a1e97f02011-06-30 14:04:341968void TabContents::OnDialogShown() {
1969 Activate();
[email protected]3a3d47472010-07-15 21:03:541970}
1971
[email protected]41fc0322009-09-04 22:23:401972void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:121973 encoding_ = content::GetContentClient()->browser()->
1974 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:101975}
[email protected]f45d2a72010-03-08 23:28:351976
[email protected]33f74972010-12-08 16:40:361977void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
1978 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
1979 rwh_view->SetSize(view()->GetContainerSize());
1980}