blob: 5fdf88886f462ae567d1e144aa10f7ecebb64931 [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]cf68b092010-01-15 20:05:5516#include "chrome/browser/browser_shutdown.h"
[email protected]96d185d2009-04-24 03:28:5417#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1418#include "chrome/browser/defaults.h"
[email protected]3c733bde2010-12-21 19:56:3119#include "chrome/browser/external_protocol_handler.h"
[email protected]ef0d04c2010-12-15 23:34:2120#include "chrome/browser/history/history.h"
[email protected]420ae012009-04-24 05:16:3221#include "chrome/browser/load_from_memory_cache_details.h"
22#include "chrome/browser/load_notification_details.h"
[email protected]f364d1392011-04-08 21:03:1023#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5324#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]14a000d2010-04-29 21:44:2425#include "chrome/browser/platform_util.h"
[email protected]36fb2c7c2011-04-04 15:49:0826#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3327#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3229#include "chrome/browser/renderer_preferences_util.h"
[email protected]1caa1522010-12-01 20:23:3530#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2931#include "chrome/browser/ui/browser_dialogs.h"
[email protected]1698f612011-03-11 11:28:1532#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3234#include "chrome/common/render_messages.h"
[email protected]567812d2011-02-24 17:40:5035#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5636#include "content/browser/content_browser_client.h"
[email protected]567812d2011-02-24 17:40:5037#include "content/browser/host_zoom_map.h"
38#include "content/browser/in_process_webkit/session_storage_namespace.h"
39#include "content/browser/renderer_host/render_process_host.h"
40#include "content/browser/renderer_host/render_view_host.h"
41#include "content/browser/renderer_host/render_widget_host_view.h"
42#include "content/browser/renderer_host/resource_request_details.h"
43#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4444#include "content/browser/tab_contents/interstitial_page.h"
45#include "content/browser/tab_contents/navigation_entry.h"
46#include "content/browser/tab_contents/provisional_load_details.h"
47#include "content/browser/tab_contents/tab_contents_delegate.h"
48#include "content/browser/tab_contents/tab_contents_observer.h"
49#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]afd1e522011-04-27 23:29:5950#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5651#include "content/browser/webui/web_ui_factory.h"
[email protected]9966325b2011-04-18 05:00:1052#include "content/common/bindings_policy.h"
[email protected]1fd1a502011-03-30 16:55:5653#include "content/common/content_client.h"
[email protected]763ec4ca2011-04-29 15:48:1254#include "content/common/content_restriction.h"
[email protected]4dd57932011-03-17 06:06:1255#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3256#include "content/common/notification_service.h"
[email protected]0f012df82011-05-19 14:15:2957#include "content/common/url_constants.h"
[email protected]2c5569662011-03-22 20:45:0258#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2959#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3260#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3461#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4663#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3864#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0365#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3166#include "webkit/glue/webpreferences.h"
67
68#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1269#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3170#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0071
[email protected]420ae012009-04-24 05:16:3272// Cross-Site Navigations
73//
74// If a TabContents is told to navigate to a different web site (as determined
75// by SiteInstance), it will replace its current RenderViewHost with a new
76// RenderViewHost dedicated to the new SiteInstance. This works as follows:
77//
78// - Navigate determines whether the destination is cross-site, and if so,
79// it creates a pending_render_view_host_ and moves into the PENDING
80// RendererState.
81// - The pending RVH is "suspended," so that no navigation messages are sent to
82// its renderer until the onbeforeunload JavaScript handler has a chance to
83// run in the current RVH.
84// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
85// that it has a pending cross-site request. ResourceDispatcherHost will
86// check for this when the response arrives.
87// - The current RVH runs its onbeforeunload handler. If it returns false, we
88// cancel all the pending logic and go back to NORMAL. Otherwise we allow
89// the pending RVH to send the navigation request to its renderer.
90// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
91// checks CrossSiteRequestManager to see that the RVH responsible has a
92// pending cross-site request, and then installs a CrossSiteEventHandler.
93// - When RDH receives a response, the BufferedEventHandler determines whether
94// it is a download. If so, it sends a message to the new renderer causing
95// it to cancel the request, and the download proceeds in the download
96// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:3497// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:3298// doesn't affect any functionality.
99// - After RDH receives a response and determines that it is safe and not a
100// download, it pauses the response to first run the old page's onunload
101// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15102// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32103// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15104// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32105// the ResourceDispatcherHost, who unpauses the response. Data is then sent
106// to the pending RVH.
107// - The pending renderer sends a FrameNavigate message that invokes the
108// DidNavigate method. This replaces the current RVH with the
109// pending RVH and goes back to the NORMAL RendererState.
[email protected]992db4c2011-05-12 15:37:15110// - The previous renderer is kept swapped out in RenderViewHostManager in case
111// the user goes back. The process only stays live if another tab is using
112// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32113
114namespace {
115
116// Amount of time we wait between when a key event is received and the renderer
117// is queried for its state and pushed to the NavigationEntry.
118const int kQueryStateDelay = 5000;
119
[email protected]6ebdc9b2010-09-27 16:55:57120const int kSyncWaitDelay = 40;
121
[email protected]420ae012009-04-24 05:16:32122// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51123const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32124 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17125 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32126 prefs::kWebKitJavaEnabled,
127 prefs::kWebKitJavascriptEnabled,
128 prefs::kWebKitLoadsImagesAutomatically,
129 prefs::kWebKitPluginsEnabled,
130 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10131 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32132 prefs::kWebKitSerifFontFamily,
133 prefs::kWebKitSansSerifFontFamily,
134 prefs::kWebKitFixedFontFamily,
135 prefs::kWebKitDefaultFontSize,
136 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13137 prefs::kWebKitMinimumFontSize,
138 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36139 prefs::kWebkitTabsToLinks,
[email protected]839fee772011-05-05 03:21:37140 prefs::kWebKitAllowRunningInsecureContent,
141 prefs::kWebKitAllowDisplayingInsecureContent,
[email protected]0a8db0d2011-04-13 15:15:40142 prefs::kDefaultCharset,
143 prefs::kEnableReferrers
[email protected]420ae012009-04-24 05:16:32144};
145
146const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
147
[email protected]420ae012009-04-24 05:16:32148#if defined(OS_WIN)
149
150BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
151 // Note: erase is required to properly paint some widgets borders. This can
152 // be seen with textfields.
153 InvalidateRect(hwnd, NULL, TRUE);
154 return TRUE;
155}
156#endif
157
[email protected]2c5569662011-03-22 20:45:02158ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16159 Profile* profile, const NavigationEntry& entry,
160 NavigationController::ReloadType reload_type) {
161 switch (reload_type) {
162 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02163 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16164 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02165 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16166 case NavigationController::NO_RELOAD:
167 break; // Fall through to rest of function.
168 }
[email protected]5e369672009-11-03 23:48:30169
170 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
171 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02172 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30173
[email protected]2c5569662011-03-22 20:45:02174 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30175}
176
[email protected]876bc832010-09-07 16:29:54177void MakeNavigateParams(const NavigationEntry& entry,
178 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16179 NavigationController::ReloadType reload_type,
180 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34181 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54182 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00183 params->current_history_list_offset = controller.last_committed_entry_index();
184 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34185 params->url = entry.url();
186 params->referrer = entry.referrer();
187 params->transition = entry.transition_type();
188 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00189 params->navigation_type =
190 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34191 params->request_time = base::Time::Now();
192}
193
[email protected]420ae012009-04-24 05:16:32194} // namespace
195
[email protected]f4f50ef2011-01-21 19:01:19196
197// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32198
[email protected]420ae012009-04-24 05:16:32199TabContents::TabContents(Profile* profile,
200 SiteInstance* site_instance,
201 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07202 const TabContents* base_tab_contents,
203 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42204 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07205 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
206 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13207 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22208 TabContentsView::Create(this))),
209 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06210 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34211 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23212 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
213 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34214 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34215 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57216 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56217 upload_size_(0),
218 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57219 received_page_title_(false),
[email protected]f17a0ee2010-05-17 17:38:47220 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57221 capturing_contents_(false),
222 is_being_destroyed_(false),
223 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57224#if defined(OS_WIN)
225 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
226#endif
[email protected]c2e74fe82009-09-03 17:57:44227 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01228 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56229 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38230 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25231 minimum_zoom_percent_(
232 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
233 maximum_zoom_percent_(
234 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00235 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59236 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54237 renderer_preferences_util::UpdateFromSystemSettings(
238 &renderer_preferences_, profile);
239
[email protected]12636df2009-09-28 22:32:21240 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32241
[email protected]34ac70502009-09-25 17:07:23242 // We have the initial size of the view be based on the size of the passed in
243 // tab contents (normally a tab from the same window).
244 view_->CreateView(base_tab_contents ?
245 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32246
247 // Register for notifications about all interested prefs change.
248 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28249 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32250 if (prefs) {
251 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28252 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32253 }
254
[email protected]420ae012009-04-24 05:16:32255 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
256 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09257#if defined(OS_LINUX)
258 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
259 NotificationService::AllSources());
260#endif
[email protected]420ae012009-04-24 05:16:32261
[email protected]6c32ce72010-03-08 05:18:06262 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
263 NotificationService::AllSources());
264
[email protected]969182a2011-03-03 14:53:23265 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18266 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
267 NotificationService::AllSources());
268
[email protected]b5a1d11c2011-02-17 03:09:42269 // Can only add observers after render_manager_.Init() is called, since that's
270 // what sets up the render_view_host which TabContentObserver's constructor
271 // uses to get the routing_id.
272 AddObservers();
[email protected]332af7732009-03-11 13:21:35273}
initial.commit09911bf2008-07-26 23:55:29274
275TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32276 is_being_destroyed_ = true;
277
[email protected]bfe4c1582009-10-02 18:11:09278 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32279 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28280 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32281
[email protected]420ae012009-04-24 05:16:32282 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29283 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32284
[email protected]420ae012009-04-24 05:16:32285 // First cleanly close all child windows.
286 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
287 // some of these to close. CloseWindows is async, so it might get called
288 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49289 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32290
[email protected]420ae012009-04-24 05:16:32291 // Notify any observer that have a reference on this tab contents.
292 NotificationService::current()->Notify(
293 NotificationType::TAB_CONTENTS_DESTROYED,
294 Source<TabContents>(this),
295 NotificationService::NoDetails());
296
297 // TODO(brettw) this should be moved to the view.
298#if defined(OS_WIN)
299 // If we still have a window handle, destroy it. GetNativeView can return
300 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42301 if (GetNativeView()) {
302 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44303 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42304 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42305 }
[email protected]420ae012009-04-24 05:16:32306#endif
[email protected]7ab1e7d62009-10-14 23:32:01307
308 // OnCloseStarted isn't called in unit tests.
309 if (!tab_close_start_time_.is_null()) {
310 UMA_HISTOGRAM_TIMES("Tab.Close",
311 base::TimeTicks::Now() - tab_close_start_time_);
312 }
[email protected]b5a1d11c2011-02-17 03:09:42313
[email protected]07d490bc2011-03-07 17:05:26314 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08315
316 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42317}
318
319void TabContents::AddObservers() {
[email protected]232a5812011-03-04 22:42:08320 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29321}
322
[email protected]724159a2010-12-30 01:11:18323bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17324 if (web_ui() && web_ui()->OnMessageReceived(message))
325 return true;
326
[email protected]585b30362011-01-28 02:30:17327 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
328 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10329 while ((observer = it.GetNext()) != NULL)
330 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53331 return true;
[email protected]403415a2011-01-10 18:57:53332
[email protected]724159a2010-12-30 01:11:18333 bool handled = true;
334 bool message_is_ok = true;
335 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
336 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
337 OnDidStartProvisionalLoadForFrame)
338 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
339 OnDidRedirectProvisionalLoad)
340 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
341 OnDidFailProvisionalLoadWithError)
342 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
343 OnDidLoadResourceFromMemoryCache)
344 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
345 OnDidDisplayInsecureContent)
346 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
347 OnDidRunInsecureContent)
348 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
349 OnDocumentLoadedInFrame)
350 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17351 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
352 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25353 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26354 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
355 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]724159a2010-12-30 01:11:18356 IPC_MESSAGE_UNHANDLED(handled = false)
357 IPC_END_MESSAGE_MAP_EX()
358
359 if (!message_is_ok) {
360 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
361 GetRenderProcessHost()->ReceivedBadMessage();
362 }
363
364 return handled;
365}
366
[email protected]13367f72009-07-08 16:39:02367// Returns true if contains content rendered by an extension.
368bool TabContents::HostsExtension() const {
369 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34370}
371
[email protected]8cb5d5b2010-02-09 11:36:16372RenderProcessHost* TabContents::GetRenderProcessHost() const {
373 return render_manager_.current_host()->process();
374}
375
[email protected]d5f942ba2008-09-26 19:30:34376const GURL& TabContents::GetURL() const {
377 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57378 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54379 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34380}
381
[email protected]96d185d2009-04-24 03:28:54382const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55383 // Transient entries take precedence. They are used for interstitial pages
384 // that are shown on top of existing pages.
385 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23386 if (entry) {
387 return entry->GetTitleForDisplay(profile()->GetPrefs()->
[email protected]6b2f7a82011-04-25 19:30:51388 GetString(prefs::kAcceptLanguages));
[email protected]45d0ef7f2011-01-05 13:46:23389 }
[email protected]7ade2732011-02-10 00:13:58390 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
391 render_manager_.pending_web_ui() : render_manager_.web_ui();
392 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54393 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55394 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54395 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35396 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58397 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54398 if (!title.empty())
399 return title;
400 }
401 }
402
403 // We use the title for the last committed entry rather than a pending
404 // navigation entry. For example, when the user types in a URL, we want to
405 // keep the old page's title until the new load has committed and we get a new
406 // title.
[email protected]96d185d2009-04-24 03:28:54407 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23408 if (entry) {
409 return entry->GetTitleForDisplay(profile()->GetPrefs()->
[email protected]6b2f7a82011-04-25 19:30:51410 GetString(prefs::kAcceptLanguages));
[email protected]45d0ef7f2011-01-05 13:46:23411 }
[email protected]96d185d2009-04-24 03:28:54412 return EmptyString16();
413}
414
[email protected]d5f942ba2008-09-26 19:30:34415int32 TabContents::GetMaxPageID() {
416 if (GetSiteInstance())
417 return GetSiteInstance()->max_page_id();
418 else
419 return max_page_id_;
420}
421
422void TabContents::UpdateMaxPageID(int32 page_id) {
423 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34424 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34425 // testing.
426 if (GetSiteInstance())
427 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16428 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34429}
430
[email protected]96d185d2009-04-24 03:28:54431SiteInstance* TabContents::GetSiteInstance() const {
432 return render_manager_.current_host()->site_instance();
433}
434
[email protected]96d185d2009-04-24 03:28:54435bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15436 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54437 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15438 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01439 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54440 return true;
[email protected]8ab24cc2009-11-13 20:56:15441 }
[email protected]83e3895b2009-06-11 00:07:16442
[email protected]2b9a06402011-02-16 04:57:10443 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56444 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10445 return true;
446
[email protected]d0980792011-02-13 19:41:40447 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58448 if (web_ui)
449 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54450 return true;
451}
452
[email protected]585b30362011-01-28 02:30:17453void TabContents::AddObserver(TabContentsObserver* observer) {
454 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49455}
456
[email protected]585b30362011-01-28 02:30:17457void TabContents::RemoveObserver(TabContentsObserver* observer) {
458 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49459}
460
[email protected]443b80e2010-12-14 00:42:23461void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
462 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34463 return;
464
[email protected]443b80e2010-12-14 00:42:23465 crashed_status_ = status;
466 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50467 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34468}
469
470void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
471 if (delegate_)
472 delegate_->NavigationStateChanged(this, changed_flags);
473}
474
[email protected]96d185d2009-04-24 03:28:54475void TabContents::DidBecomeSelected() {
476 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16477 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
478 if (rwhv) {
479 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43480#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16481 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43482#endif
483 }
[email protected]96d185d2009-04-24 03:28:54484
[email protected]8cb5d5b2010-02-09 11:36:16485 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11486 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54487}
488
489void TabContents::WasHidden() {
490 if (!capturing_contents()) {
491 // |render_view_host()| can be NULL if the user middle clicks a link to open
492 // a tab in then background, then closes the tab before selecting it. This
493 // is because closing the tab calls TabContents::Destroy(), which removes
494 // the |render_view_host()|; then when we actually destroy the window,
495 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16496 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
497 if (rwhv)
498 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54499 }
500
501 NotificationService::current()->Notify(
502 NotificationType::TAB_CONTENTS_HIDDEN,
503 Source<TabContents>(this),
504 NotificationService::NoDetails());
505}
506
[email protected]d5f942ba2008-09-26 19:30:34507void TabContents::Activate() {
508 if (delegate_)
509 delegate_->ActivateContents(this);
510}
511
[email protected]ea42e7782010-08-23 23:58:12512void TabContents::Deactivate() {
513 if (delegate_)
514 delegate_->DeactivateContents(this);
515}
516
[email protected]96d185d2009-04-24 03:28:54517void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16518 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
519 if (rwhv)
520 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54521}
522
523void TabContents::HideContents() {
524 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
525 // our superclass HideContents(), because some callers want to be very picky
526 // about the order in which these get called. In addition to making the code
527 // here practically impossible to understand, this also means we end up
528 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34529 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54530 WasHidden();
531}
532
[email protected]5aab5e22010-12-08 22:13:29533bool TabContents::NeedToFireBeforeUnload() {
534 // TODO(creis): Should we fire even for interstitial pages?
535 return notify_disconnection() &&
536 !showing_interstitial_page() &&
537 !render_view_host()->SuddenTerminationAllowed();
538}
539
[email protected]c0588052008-10-27 23:01:50540void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34541 WindowOpenDisposition disposition,
542 PageTransition::Type transition) {
[email protected]1c642b52011-04-15 09:05:49543 if (delegate_) {
[email protected]c0588052008-10-27 23:01:50544 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]1c642b52011-04-15 09:05:49545 // Notify observers.
546 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
547 DidOpenURL(url, referrer, disposition, transition));
548 }
[email protected]d5f942ba2008-09-26 19:30:34549}
550
[email protected]1ccb3568d2010-02-19 10:51:16551bool TabContents::NavigateToPendingEntry(
552 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54553 return NavigateToEntry(*controller_.pending_entry(), reload_type);
554}
[email protected]96d185d2009-04-24 03:28:54555
[email protected]876bc832010-09-07 16:29:54556bool TabContents::NavigateToEntry(
557 const NavigationEntry& entry,
558 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54559 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
560 if (!dest_render_view_host)
561 return false; // Unable to create the desired render view host.
562
[email protected]770dd8b2010-05-24 18:11:39563 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
[email protected]216813952011-05-19 22:21:26564 dest_render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
565 dest_render_view_host->routing_id(),
566 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow));
[email protected]770dd8b2010-05-24 18:11:39567 }
[email protected]9fb325e2010-05-06 18:23:24568
[email protected]80a8fad2011-01-29 04:02:38569 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07570 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58571 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56572 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
573 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
574 entry.url());
[email protected]c09163a2011-02-15 00:05:55575 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
576 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58577
[email protected]96d185d2009-04-24 03:28:54578 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12579 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32580 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00581 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
582 dest_render_view_host,
583 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32584 }
[email protected]96d185d2009-04-24 03:28:54585
586 // Used for page load time metrics.
587 current_load_start_ = base::TimeTicks::Now();
588
589 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34590 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54591 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04592 if (delegate_) {
593 navigate_params.extra_headers =
594 delegate_->GetNavigationHeaders(navigate_params.url);
595 }
[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]d5f942ba2008-09-26 19:30:34613 return true;
614}
615
[email protected]96d185d2009-04-24 03:28:54616void TabContents::Stop() {
617 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47618 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54619}
620
[email protected]96d185d2009-04-24 03:28:54621TabContents* TabContents::Clone() {
622 // We create a new SiteInstance so that the new tab won't share processes
623 // with the old one. This can be changed in the future if we need it to share
624 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32625 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54626 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07627 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54628 tc->controller().CopyStateFrom(controller_);
629 return tc;
630}
631
[email protected]4d677202009-07-19 07:37:12632void TabContents::ShowPageInfo(const GURL& url,
633 const NavigationEntry::SSLStatus& ssl,
634 bool show_history) {
635 if (!delegate_)
636 return;
637
[email protected]bb678332009-07-21 00:15:50638 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12639}
640
initial.commit09911bf2008-07-26 23:55:29641ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28642 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29643 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28644 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33645 AddConstrainedDialog(window);
646 return window;
647}
648
649void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29650 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44651
652 if (child_windows_.size() == 1) {
653 window->ShowConstrainedWindow();
654 BlockTabContent(true);
655 }
initial.commit09911bf2008-07-26 23:55:29656}
657
[email protected]fa1cf0b82010-01-15 21:49:44658void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55659 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45660 // 70% opaque grey.
661 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55662 if (rwhv)
[email protected]1b072562010-12-13 19:37:45663 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]a7eccac2011-04-15 03:05:19664 // RenderViewHost may be NULL during shutdown.
665 if (render_view_host())
666 render_view_host()->set_ignore_input_events(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44667 if (delegate_)
668 delegate_->SetTabContentBlocked(this, blocked);
669}
670
[email protected]e7cfdbd2011-04-22 14:41:37671void TabContents::AddNewContents(TabContents* new_contents,
672 WindowOpenDisposition disposition,
673 const gfx::Rect& initial_pos,
674 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29675 if (!delegate_)
676 return;
677
[email protected]e7cfdbd2011-04-22 14:41:37678 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
679 user_gesture);
[email protected]96d185d2009-04-24 03:28:54680}
681
[email protected]5c9e97a2009-09-09 23:48:30682gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54683 return view_->GetContentNativeView();
684}
685
686gfx::NativeView TabContents::GetNativeView() const {
687 return view_->GetNativeView();
688}
689
690void TabContents::GetContainerBounds(gfx::Rect *out) const {
691 view_->GetContainerBounds(out);
692}
693
694void TabContents::Focus() {
695 view_->Focus();
696}
697
[email protected]90daadb42009-06-08 21:27:28698void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54699 if (showing_interstitial_page()) {
700 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
701 return;
702 }
[email protected]96d185d2009-04-24 03:28:54703 render_view_host()->SetInitialFocus(reverse);
704}
705
706bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40707 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58708 if (web_ui)
709 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43710 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25711 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43712 return true;
[email protected]96d185d2009-04-24 03:28:54713 return false;
714}
715
[email protected]a26dc362010-04-23 01:48:58716void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38717 if (delegate())
[email protected]a26dc362010-04-23 01:48:58718 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38719}
720
[email protected]20ede072009-10-06 00:28:35721bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:27722 if (showing_interstitial_page())
723 return false;
724
[email protected]c8f74942010-09-03 10:04:14725 // Do not show bookmarks bar if bookmarks aren't enabled.
726 if (!browser_defaults::bookmarks_enabled)
727 return false;
728
[email protected]b3be10fa2011-04-11 15:43:15729 if (!profile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar))
730 return false;
731
[email protected]d0980792011-02-13 19:41:40732 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:54733 // similar, but for non-first loads, we want to use the committed entry. This
734 // is so the bookmarks bar disappears at the same time the page does.
735 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:35736 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:58737 return (render_manager_.web_ui() == NULL) ?
738 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54739 }
740
741 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:40742 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:54743 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:58744 if (render_manager_.pending_web_ui())
745 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
746 return (render_manager_.web_ui() == NULL) ?
747 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54748}
749
[email protected]d5f942ba2008-09-26 19:30:34750void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:37751 ConstrainedWindowList::iterator i(
752 std::find(child_windows_.begin(), child_windows_.end(), window));
753 bool removed_topmost_window = i == child_windows_.begin();
754 if (i != child_windows_.end())
755 child_windows_.erase(i);
756 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:44757 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:37758 } else {
759 if (removed_topmost_window)
760 child_windows_[0]->ShowConstrainedWindow();
761 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:44762 }
[email protected]66ba4932009-06-04 19:22:13763}
[email protected]d5f942ba2008-09-26 19:30:34764
[email protected]89d6e6e2009-12-03 23:06:51765void TabContents::EmailPageLocation() {
766 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
767 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
768 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
769 title + "&body=%0A%0A" + page_url;
770 platform_util::OpenExternal(GURL(mailto));
771}
772
[email protected]420ae012009-04-24 05:16:32773bool TabContents::IsActiveEntry(int32 page_id) {
774 NavigationEntry* active_entry = controller_.GetActiveEntry();
775 return (active_entry != NULL &&
776 active_entry->site_instance() == GetSiteInstance() &&
777 active_entry->page_id() == page_id);
778}
779
[email protected]b2fe07d12010-02-09 14:38:08780void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16781 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26782 render_view_host()->Send(new ViewMsg_SetPageEncoding(
783 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16784}
785
[email protected]b2fe07d12010-02-09 14:38:08786void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16787 reset_encoding();
[email protected]216813952011-05-19 22:21:26788 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
789 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16790}
791
[email protected]7ab1e7d62009-10-14 23:32:01792void TabContents::OnCloseStarted() {
793 if (tab_close_start_time_.is_null())
794 tab_close_start_time_ = base::TimeTicks::Now();
795}
796
[email protected]46624bf2010-06-09 16:04:19797bool TabContents::ShouldAcceptDragAndDrop() const {
798#if defined(OS_CHROMEOS)
799 // ChromeOS panels (pop-ups) do not take drag-n-drop.
800 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14801 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20802 return false;
803 return true;
[email protected]46624bf2010-06-09 16:04:19804#else
805 return true;
806#endif
807}
808
[email protected]7813bd72011-02-05 02:19:34809void TabContents::SystemDragEnded() {
810 if (render_view_host())
811 render_view_host()->DragSourceSystemDragEnded();
812 if (delegate())
813 delegate()->DragEnded();
814}
815
[email protected]ec0b6c42010-08-26 03:16:58816void TabContents::UpdateHistoryForNavigation(
817 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
818 if (profile()->IsOffTheRecord())
819 return;
820
821 // Add to history service.
822 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
823 if (hs)
824 hs->AddPage(*add_page_args);
825}
826
827void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
828 if (profile()->IsOffTheRecord())
829 return;
830
831 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
[email protected]6b2f7a82011-04-25 19:30:51832 if (hs)
833 hs->SetPageTitle(entry.virtual_url(), entry.title());
[email protected]ec0b6c42010-08-26 03:16:58834}
835
[email protected]d0b8d092010-10-25 04:05:17836double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:25837 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
838 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17839 return 0;
[email protected]b75b8292010-10-01 07:28:25840
841 double zoom_level;
842 if (temporary_zoom_settings_) {
843 zoom_level = zoom_map->GetTemporaryZoomLevel(
844 GetRenderProcessHost()->id(), render_view_host()->routing_id());
845 } else {
846 zoom_level = zoom_map->GetZoomLevel(GetURL());
847 }
[email protected]d0b8d092010-10-25 04:05:17848 return zoom_level;
849}
[email protected]b75b8292010-10-01 07:28:25850
[email protected]d0b8d092010-10-25 04:05:17851int TabContents::GetZoomPercent(bool* enable_increment,
852 bool* enable_decrement) {
853 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:25854 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:17855 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:25856 *enable_decrement = percent > minimum_zoom_percent_;
857 *enable_increment = percent < maximum_zoom_percent_;
858 return percent;
859}
860
[email protected]3c733bde2010-12-21 19:56:31861void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50862 if (!delegate_)
863 return;
864
865 NavigationEntry* active_entry = controller().GetActiveEntry();
866 if (!active_entry)
867 return;
868
869 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12870}
871
[email protected]932b7a12011-03-09 12:50:27872void TabContents::ViewFrameSource(const GURL& url,
873 const std::string& content_state) {
874 if (!delegate_)
875 return;
876
877 delegate_->ViewSourceForFrame(this, url, content_state);
878}
879
[email protected]c40d6232011-03-25 00:16:21880void TabContents::SetContentRestrictions(int restrictions) {
881 content_restrictions_ = restrictions;
882 delegate()->ContentRestrictionsChanged(this);
883}
884
[email protected]724159a2010-12-30 01:11:18885void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
886 bool is_main_frame,
[email protected]eacb080b2011-05-22 19:40:26887 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18888 const GURL& url) {
889 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
890 GURL validated_url(url);
891 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
892 GetRenderProcessHost()->id(), &validated_url);
893
[email protected]8093a542011-05-13 07:29:32894 RenderViewHost* rvh =
895 render_manager_.pending_render_view_host() ?
896 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10897 // Notify observers about the start of the provisional load.
898 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
899 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32900 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10901
[email protected]724159a2010-12-30 01:11:18902 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59903 // Notify observers about the provisional change in the main frame URL.
904 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26905 ProvisionalChangeToMainFrameUrl(url, has_opener_set));
[email protected]724159a2010-12-30 01:11:18906 }
907}
908
909void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26910 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18911 const GURL& source_url,
912 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49913 // TODO(creis): Remove this method and have the pre-rendering code listen to
914 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
915 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18916 NavigationEntry* entry;
917 if (page_id == -1)
918 entry = controller_.pending_entry();
919 else
920 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
921 if (!entry || entry->url() != source_url)
922 return;
[email protected]e7d50892011-01-19 21:47:38923
[email protected]4850a7f2011-03-08 23:36:59924 // Notify observers about the provisional change in the main frame URL.
925 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26926 ProvisionalChangeToMainFrameUrl(target_url,
927 has_opener_set));
[email protected]724159a2010-12-30 01:11:18928}
929
930void TabContents::OnDidFailProvisionalLoadWithError(
931 int64 frame_id,
932 bool is_main_frame,
933 int error_code,
934 const GURL& url,
935 bool showing_repost_interstitial) {
936 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
937 << ", error_code: " << error_code
938 << " is_main_frame: " << is_main_frame
939 << " showing_repost_interstitial: " << showing_repost_interstitial
940 << " frame_id: " << frame_id;
941 GURL validated_url(url);
942 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
943 GetRenderProcessHost()->id(), &validated_url);
944
945 if (net::ERR_ABORTED == error_code) {
946 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
947 // This means that the interstitial won't be torn down properly, which is
948 // bad. But if we have an interstitial, go back to another tab type, and
949 // then load the same interstitial again, we could end up getting the first
950 // interstitial's "failed" message (as a result of the cancel) when we're on
951 // the second one.
952 //
953 // We can't tell this apart, so we think we're tearing down the current page
954 // which will cause a crash later one. There is also some code in
955 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
956 // out because of this problem.
957 //
958 // http://code.google.com/p/chromium/issues/detail?id=2855
959 // Because this will not tear down the interstitial properly, if "back" is
960 // back to another tab type, the interstitial will still be somewhat alive
961 // in the previous tab type. If you navigate somewhere that activates the
962 // tab with the interstitial again, you'll see a flash before the new load
963 // commits of the interstitial page.
964 if (showing_interstitial_page()) {
965 LOG(WARNING) << "Discarding message during interstitial.";
966 return;
967 }
968
969 // This will discard our pending entry if we cancelled the load (e.g., if we
970 // decided to download the file instead of load it). Only discard the
971 // pending entry if the URLs match, otherwise the user initiated a navigate
972 // before the page loaded so that the discard would discard the wrong entry.
973 NavigationEntry* pending_entry = controller_.pending_entry();
974 if (pending_entry && pending_entry->url() == validated_url) {
[email protected]c95fa8b2011-04-28 20:26:16975 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:18976 }
977
978 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
979 }
980
981 // Send out a notification that we failed a provisional load with an error.
982 ProvisionalLoadDetails details(
983 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:09984 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:18985 details.set_error_code(error_code);
986
987 NotificationService::current()->Notify(
988 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
989 Source<NavigationController>(&controller_),
990 Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:10991
992 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
993 DidFailProvisionalLoad(frame_id, is_main_frame,
994 validated_url, error_code));
[email protected]724159a2010-12-30 01:11:18995}
996
997void TabContents::OnDidLoadResourceFromMemoryCache(
998 const GURL& url,
[email protected]724159a2010-12-30 01:11:18999 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191000 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181001 cache.Increment();
1002
1003 // Send out a notification that we loaded a resource from our memory cache.
1004 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1005 SSLManager::DeserializeSecurityInfo(security_info,
1006 &cert_id, &cert_status,
1007 &security_bits,
1008 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161009 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1010 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181011
1012 NotificationService::current()->Notify(
1013 NotificationType::LOAD_FROM_MEMORY_CACHE,
1014 Source<NavigationController>(&controller_),
1015 Details<LoadFromMemoryCacheDetails>(&details));
1016}
1017
1018void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161019 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181020 displayed_insecure_content_ = true;
1021 SSLManager::NotifySSLInternalStateChanged();
1022}
1023
1024void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021025 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231026 LOG(INFO) << security_origin << " ran insecure content from "
1027 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161028 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]724159a2010-12-30 01:11:181029 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1030}
1031
1032void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1033 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101034 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1035 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181036}
1037
1038void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:101039 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1040 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:181041}
1042
[email protected]c8f73ab2011-01-22 00:05:171043void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211044 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171045}
1046
[email protected]216813952011-05-19 22:21:261047void TabContents::OnGoToEntryAtOffset(int offset) {
1048 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1049 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1050 if (!entry)
1051 return;
1052 // Note that we don't call NavigationController::GotToOffset() as we don't
1053 // want to create a pending navigation entry (it might end up lingering
1054 // http://crbug.com/51680).
1055 entry->set_transition_type(entry->transition_type() |
1056 PageTransition::FORWARD_BACK);
1057 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1058 }
1059}
1060
1061void TabContents::OnUpdateZoomLimits(int minimum_percent,
1062 int maximum_percent,
1063 bool remember) {
1064 minimum_zoom_percent_ = minimum_percent;
1065 maximum_zoom_percent_ = maximum_percent;
1066 temporary_zoom_settings_ = !remember;
1067}
1068
1069void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
1070 NotificationService::current()->Notify(
1071 NotificationType::FOCUS_CHANGED_IN_PAGE,
1072 Source<TabContents>(this),
1073 Details<const bool>(&is_editable_node));
1074}
1075
[email protected]96d185d2009-04-24 03:28:541076// Notifies the RenderWidgetHost instance about the fact that the page is
1077// loading, or done loading and calls the base implementation.
1078void TabContents::SetIsLoading(bool is_loading,
1079 LoadNotificationDetails* details) {
1080 if (is_loading == is_loading_)
1081 return;
1082
1083 if (!is_loading) {
1084 load_state_ = net::LOAD_STATE_IDLE;
1085 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561086 upload_size_ = 0;
1087 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541088 }
1089
1090 render_manager_.SetIsLoading(is_loading);
1091
1092 is_loading_ = is_loading;
1093 waiting_for_response_ = is_loading;
1094
[email protected]6ebdc9b2010-09-27 16:55:571095 if (delegate_)
1096 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351097 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541098
1099 NotificationType type = is_loading ? NotificationType::LOAD_START :
1100 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111101 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541102 if (details)
1103 det = Details<LoadNotificationDetails>(details);
1104 NotificationService::current()->Notify(type,
1105 Source<NavigationController>(&controller_),
1106 det);
1107}
1108
[email protected]d0980792011-02-13 19:41:401109WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581110 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541111 // that goes along with it to control the basic flags. For example, we want to
1112 // show the pending URL in the URL bar, so we want the display_url flag to
1113 // be from the pending entry.
1114 //
1115 // The confusion comes because there are multiple possibilities for the
1116 // initial load in a tab as a side effect of the way the RenderViewHostManager
1117 // works.
1118 //
[email protected]e0112912011-02-02 22:54:351119 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541120 // the pending one, and we want it to apply here.
1121 //
1122 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1123 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581124 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351125 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541126 //
1127 // This condition handles all of these cases:
1128 //
1129 // - First load in first tab: no committed nav entry + pending nav entry +
1130 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351131 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541132 //
1133 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351134 // no pending Web UI:
1135 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541136 //
1137 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351138 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541139 //
1140 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351141 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541142 if (controller_.pending_entry() &&
1143 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581144 render_manager_.pending_web_ui()))
1145 return render_manager_.pending_web_ui();
1146 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541147}
[email protected]420ae012009-04-24 05:16:321148
[email protected]1fd1a502011-03-30 16:55:561149WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1150 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1151}
1152
[email protected]420ae012009-04-24 05:16:321153void TabContents::DidNavigateMainFramePostCommit(
1154 const NavigationController::LoadCommittedDetails& details,
1155 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561156 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381157 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441158 // that opened the window, as long as both renderers have the same
1159 // privileges.
[email protected]1fd1a502011-03-30 16:55:561160 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1161 WebUI* web_ui = content::GetContentClient()->browser()->
1162 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581163 // web_ui might be NULL if the URL refers to a non-existent extension.
1164 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401165 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581166 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441167 }
1168 }
[email protected]1fd1a502011-03-30 16:55:561169 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441170 }
1171
[email protected]420ae012009-04-24 05:16:321172 if (details.is_user_initiated_main_frame_load()) {
1173 // Clear the status bubble. This is a workaround for a bug where WebKit
1174 // doesn't let us know that the cursor left an element during a
1175 // transition (this is also why the mouse cursor remains as a hand after
1176 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1177 // clear the bubble when a user navigates to a named anchor in the same
1178 // page.
1179 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321180 }
1181
[email protected]420ae012009-04-24 05:16:321182 // Allow the new page to set the title again.
1183 received_page_title_ = false;
1184
[email protected]a6e82fc2010-02-24 22:28:141185 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471186 // Once the main frame is navigated, we're no longer considered to have
1187 // displayed insecure content.
1188 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171189 }
[email protected]ce5c4502009-05-06 16:46:111190
[email protected]8cc8d492010-02-02 10:40:491191 // Close constrained windows if necessary.
1192 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1193 details.previous_url, details.entry->url()))
1194 CloseConstrainedWindows();
1195
[email protected]3c9e1872010-11-18 16:17:491196 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171197 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491198 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321199}
1200
1201void TabContents::DidNavigateAnyFramePostCommit(
1202 RenderViewHost* render_view_host,
1203 const NavigationController::LoadCommittedDetails& details,
1204 const ViewHostMsg_FrameNavigate_Params& params) {
1205 // If we navigate, start showing messages again. This does nothing to prevent
1206 // a malicious script from spamming messages, since the script could just
1207 // reload the page to stop blocking.
1208 suppress_javascript_messages_ = false;
1209
[email protected]3c9e1872010-11-18 16:17:491210 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171211 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491212 DidNavigateAnyFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321213}
1214
[email protected]8cc8d492010-02-02 10:40:491215void TabContents::CloseConstrainedWindows() {
1216 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331217 // To ensure that we iterate over every element in child_windows_ we
1218 // need to use a copy of child_windows_. Otherwise if
1219 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1220 // skipping some elements.
1221 ConstrainedWindowList child_windows_copy(child_windows_);
1222 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1223 it != child_windows_copy.end(); ++it) {
1224 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441225 if (window) {
[email protected]420ae012009-04-24 05:16:321226 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441227 BlockTabContent(false);
1228 }
[email protected]420ae012009-04-24 05:16:321229 }
1230}
1231
[email protected]420ae012009-04-24 05:16:321232void TabContents::UpdateAlternateErrorPageURL() {
1233 GURL url = GetAlternateErrorPageURL();
[email protected]216813952011-05-19 22:21:261234 render_view_host()->Send(new ViewMsg_SetAltErrorPageURL(
1235 render_view_host()->routing_id(), url));
[email protected]420ae012009-04-24 05:16:321236}
1237
1238void TabContents::UpdateWebPreferences() {
[email protected]216813952011-05-19 22:21:261239 render_view_host()->Send(new ViewMsg_UpdateWebPreferences(
1240 render_view_host()->routing_id(), GetWebkitPrefs()));
[email protected]420ae012009-04-24 05:16:321241}
1242
[email protected]d0b8d092010-10-25 04:05:171243void TabContents::UpdateZoomLevel() {
[email protected]216813952011-05-19 22:21:261244 render_view_host()->Send(new ViewMsg_SetZoomLevel(
1245 render_view_host()->routing_id(), GetZoomLevel()));
[email protected]d0b8d092010-10-25 04:05:171246}
1247
[email protected]420ae012009-04-24 05:16:321248void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1249 RenderViewHost* rvh) {
1250 // If we are creating a RVH for a restored controller, then we might
1251 // have more page IDs than the SiteInstance's current max page ID. We must
1252 // make sure that the max page ID is larger than any restored page ID.
1253 // Note that it is ok for conflicting page IDs to exist in another tab
1254 // (i.e., NavigationController), but if any page ID is larger than the max,
1255 // the back/forward list will get confused.
1256 int max_restored_page_id = controller_.max_restored_page_id();
1257 if (max_restored_page_id > 0) {
1258 int curr_max_page_id = site_instance->max_page_id();
1259 if (max_restored_page_id > curr_max_page_id) {
1260 // Need to update the site instance immediately.
1261 site_instance->UpdateMaxPageID(max_restored_page_id);
1262
1263 // Also tell the renderer to update its internal representation. We
1264 // need to reserve enough IDs to make all restored page IDs less than
1265 // the max.
1266 if (curr_max_page_id < 0)
1267 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261268 rvh->Send(new ViewMsg_ReservePageIDRange(
1269 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321270 }
1271 }
1272}
1273
[email protected]ec0b6c42010-08-26 03:16:581274scoped_refptr<history::HistoryAddPageArgs>
1275TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541276 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471277 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321278 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581279 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1280 new history::HistoryAddPageArgs(
1281 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1282 params.redirects, params.transition, history::SOURCE_BROWSED,
1283 details.did_replace_entry));
1284 if (PageTransition::IsMainFrame(params.transition) &&
1285 virtual_url != params.url) {
1286 // Hack on the "virtual" URL so that it will appear in history. For some
1287 // types of URLs, we will display a magic URL that is different from where
1288 // the page is actually navigated. We want the user to see in history what
1289 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1290 // only applies to the main frame, as the virtual URL doesn't apply to
1291 // sub-frames.
1292 add_page_args->url = virtual_url;
1293 if (!add_page_args->redirects.empty())
1294 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321295 }
[email protected]ec0b6c42010-08-26 03:16:581296 return add_page_args;
[email protected]420ae012009-04-24 05:16:321297}
1298
[email protected]6b2f7a82011-04-25 19:30:511299bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1300 const std::wstring& 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]6b2f7a82011-04-25 19:30:511306 if (entry->url().SchemeIsFile() && title.empty()) {
1307 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]6b2f7a82011-04-25 19:30:511310 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321311 explicit_set = true;
1312 }
1313
[email protected]e53668962010-06-23 15:35:251314 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321315 return false; // Nothing changed, don't bother.
1316
[email protected]e53668962010-06-23 15:35:251317 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321318
[email protected]ec0b6c42010-08-26 03:16:581319 if (!received_page_title_) {
1320 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321321 received_page_title_ = explicit_set;
1322 }
1323
1324 // Lastly, set the title for the view.
[email protected]6b2f7a82011-04-25 19:30:511325 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321326
[email protected]cbc0e1b2010-04-12 18:33:041327 NotificationService::current()->Notify(
1328 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1329 Source<TabContents>(this),
1330 NotificationService::NoDetails());
1331
[email protected]420ae012009-04-24 05:16:321332 return true;
1333}
1334
1335void TabContents::NotifySwapped() {
1336 // After sending out a swap notification, we need to send a disconnect
1337 // notification so that clients that pick up a pointer to |this| can NULL the
1338 // pointer. See Bug 1230284.
1339 notify_disconnection_ = true;
1340 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341341 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221342 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321343 NotificationService::NoDetails());
1344}
1345
1346void TabContents::NotifyConnected() {
1347 notify_disconnection_ = true;
1348 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341349 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221350 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321351 NotificationService::NoDetails());
1352}
1353
1354void TabContents::NotifyDisconnected() {
1355 if (!notify_disconnection_)
1356 return;
1357
1358 notify_disconnection_ = false;
1359 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341360 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221361 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321362 NotificationService::NoDetails());
1363}
1364
[email protected]8d3347f2009-07-09 22:00:211365RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321366 return view_.get();
1367}
1368
[email protected]8d3347f2009-07-09 22:00:211369RenderViewHostDelegate::RendererManagement*
1370TabContents::GetRendererManagementDelegate() {
1371 return &render_manager_;
1372}
1373
[email protected]ced90ae12010-02-20 02:06:161374RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1375 return bookmark_drag_;
1376}
1377
1378void TabContents::SetBookmarkDragDelegate(
1379 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1380 bookmark_drag_ = bookmark_drag;
1381}
1382
[email protected]93623c5d2009-12-10 21:40:321383RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461384 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511385}
1386
[email protected]57c6a652009-05-04 07:58:341387TabContents* TabContents::GetAsTabContents() {
1388 return this;
1389}
1390
[email protected]7b291f92009-08-14 05:43:531391ViewType::Type TabContents::GetRenderViewType() const {
1392 return ViewType::TAB_CONTENTS;
1393}
1394
1395int TabContents::GetBrowserWindowID() const {
1396 return controller().window_id().id();
1397}
1398
[email protected]420ae012009-04-24 05:16:321399void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061400 NotificationService::current()->Notify(
1401 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1402 Source<TabContents>(this),
1403 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321404 NavigationEntry* entry = controller_.GetActiveEntry();
1405 if (!entry)
1406 return;
1407
1408 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351409 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561410 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581411 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321412
1413 if (entry->IsViewSourceMode()) {
1414 // Put the renderer in view source mode.
1415 render_view_host->Send(
1416 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1417 }
[email protected]0666aef2009-05-13 19:48:081418
1419 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321420}
1421
1422void TabContents::RenderViewReady(RenderViewHost* rvh) {
1423 if (rvh != render_view_host()) {
1424 // Don't notify the world, since this came from a renderer in the
1425 // background.
1426 return;
1427 }
1428
1429 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301430 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231431 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301432
1433 // Restore the focus to the tab (otherwise the focus will be on the top
1434 // window).
[email protected]484ae5912010-09-29 19:16:141435 if (was_crashed && !FocusLocationBarByDefault() &&
1436 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301437 Focus();
[email protected]484ae5912010-09-29 19:16:141438 }
[email protected]420ae012009-04-24 05:16:321439}
1440
[email protected]443b80e2010-12-14 00:42:231441void TabContents::RenderViewGone(RenderViewHost* rvh,
1442 base::TerminationStatus status,
1443 int error_code) {
[email protected]420ae012009-04-24 05:16:321444 if (rvh != render_view_host()) {
1445 // The pending page's RenderViewHost is gone.
1446 return;
1447 }
1448
[email protected]2e3f4572011-03-25 19:24:471449 // Let observers know first and give them a chance to act.
1450 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
1451
[email protected]420ae012009-04-24 05:16:321452 SetIsLoading(false, NULL);
1453 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231454 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321455
[email protected]8e537302009-06-10 21:19:581456 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:551457 // Only do this if we're not in browser shutdown, so that TabContents
1458 // objects that are not in a browser (e.g., HTML dialogs) and thus are
1459 // visible do not flash a sad tab page.
1460 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:161461 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321462
1463 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:291464 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:321465}
1466
[email protected]2e4633c2009-07-09 16:58:061467void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481468 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061469}
1470
[email protected]420ae012009-04-24 05:16:321471void TabContents::DidNavigate(RenderViewHost* rvh,
1472 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:371473 int extra_invalidate_flags = 0;
1474
1475 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:351476 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:371477
[email protected]420ae012009-04-24 05:16:321478 render_manager_.DidNavigateMainFrame(rvh);
1479
[email protected]20ede072009-10-06 00:28:351480 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:371481 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:371482 }
1483
[email protected]420ae012009-04-24 05:16:321484 // Update the site of the SiteInstance if it doesn't have one yet.
1485 if (!GetSiteInstance()->has_site())
1486 GetSiteInstance()->SetSite(params.url);
1487
1488 // Need to update MIME type here because it's referred to in
1489 // UpdateNavigationCommands() called by RendererDidNavigate() to
1490 // determine whether or not to enable the encoding menu.
1491 // It's updated only for the main frame. For a subframe,
1492 // RenderView::UpdateURL does not set params.contents_mime_type.
1493 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1494 // TODO(jungshik): Add a test for the encoding menu to avoid
1495 // regressing it again.
1496 if (PageTransition::IsMainFrame(params.transition))
1497 contents_mime_type_ = params.contents_mime_type;
1498
1499 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:371500 bool did_navigate = controller_.RendererDidNavigate(
1501 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:391502
[email protected]a9c0bfe2010-09-17 08:35:221503 // Send notification about committed provisional loads. This notification is
1504 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1505 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1506 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071507 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1508 // that is not recorded in the navigation history. For the purpose of
1509 // tracking navigation events, we treat this event as a sub frame navigation
1510 // event.
1511 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]0d60f0192011-04-14 12:40:101512 PageTransition::Type transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221513 // Whether or not a page transition was triggered by going backward or
1514 // forward in the history is only stored in the navigation controller's
1515 // entry list.
1516 if (did_navigate &&
1517 (controller_.GetActiveEntry()->transition_type() &
1518 PageTransition::FORWARD_BACK)) {
[email protected]0d60f0192011-04-14 12:40:101519 transition_type = params.transition | PageTransition::FORWARD_BACK;
[email protected]a9c0bfe2010-09-17 08:35:221520 }
[email protected]0d60f0192011-04-14 12:40:101521 // Notify observers about the commit of the provisional load.
1522 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1523 DidCommitProvisionalLoadForFrame(params.frame_id,
1524 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221525 }
1526
[email protected]3e90d4a2009-07-03 17:38:391527 // Update history. Note that this needs to happen after the entry is complete,
1528 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:581529 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:391530 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:581531 // URLs, we use a data: URL as the real value. We actually want to save the
1532 // about: URL to the history db and keep the data: URL hidden. This is what
1533 // the TabContents' URL getter does.
1534 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1535 CreateHistoryAddPageArgs(GetURL(), details, params));
1536 if (!delegate() ||
1537 delegate()->ShouldAddNavigationToHistory(*add_page_args,
1538 details.type)) {
1539 UpdateHistoryForNavigation(add_page_args);
1540 }
[email protected]3e90d4a2009-07-03 17:38:391541 }
1542
[email protected]76543b92009-08-31 17:27:451543 if (!did_navigate)
1544 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321545
1546 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1547 // for the appropriate notification (best) or you can add it to
1548 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1549 // necessary, please).
1550
1551 // Run post-commit tasks.
1552 if (details.is_main_frame)
1553 DidNavigateMainFramePostCommit(details, params);
1554 DidNavigateAnyFramePostCommit(rvh, details, params);
1555}
1556
1557void TabContents::UpdateState(RenderViewHost* rvh,
1558 int32 page_id,
1559 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151560 // Ensure that this state update comes from either the active RVH or one of
1561 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1562 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321563
1564 // We must be prepared to handle state updates for any page, these occur
1565 // when the user is scrolling and entering form data, as well as when we're
1566 // leaving a page, in which case our state may have already been moved to
1567 // the next page. The navigation controller will look up the appropriate
1568 // NavigationEntry and update it when it is notified via the delegate.
1569
1570 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151571 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321572 if (entry_index < 0)
1573 return;
1574 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1575
1576 if (state == entry->content_state())
1577 return; // Nothing to update.
1578 entry->set_content_state(state);
1579 controller_.NotifyEntryChanged(entry, entry_index);
1580}
1581
1582void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]6b2f7a82011-04-25 19:30:511583 int32 page_id, const std::wstring& title) {
[email protected]420ae012009-04-24 05:16:321584 // If we have a title, that's a pretty good indication that we've started
1585 // getting useful data.
1586 SetNotWaitingForResponse();
1587
1588 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481589 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581590 page_id);
[email protected]40ead7b62011-04-23 03:17:281591 if (!entry || !UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321592 return;
1593
1594 // Broadcast notifications when the UI should be updated.
1595 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031596 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321597}
1598
[email protected]420ae012009-04-24 05:16:321599void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401600 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321601 set_encoding(encoding);
1602}
1603
1604void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1605 if (delegate())
1606 delegate()->UpdateTargetURL(this, url);
1607}
1608
[email protected]c4e98902010-06-01 10:20:141609void TabContents::UpdateInspectorSetting(const std::string& key,
1610 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:051611 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:081612}
1613
[email protected]45aafc92010-06-07 14:18:531614void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:051615 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:531616}
1617
[email protected]420ae012009-04-24 05:16:321618void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291619 // The UI may be in an event-tracking loop, such as between the
1620 // mouse-down and mouse-up in text selection or a button click.
1621 // Defer the close until after tracking is complete, so that we
1622 // don't free objects out from under the UI.
1623 // TODO(shess): This could probably be integrated with the
1624 // IsDoingDrag() test below. Punting for now because I need more
1625 // research to understand how this impacts platforms other than Mac.
1626 // TODO(shess): This could get more fine-grained. For instance,
1627 // closing a tab in another window while selecting text in the
1628 // current window's Omnibox should be just fine.
1629 if (view()->IsEventTracking()) {
1630 view()->CloseTabAfterEventTracking();
1631 return;
1632 }
1633
[email protected]24a4d1062009-07-10 23:10:421634 // If we close the tab while we're in the middle of a drag, we'll crash.
1635 // Instead, cancel the drag and close it as soon as the drag ends.
1636 if (view()->IsDoingDrag()) {
1637 view()->CancelDragAndCloseTab();
1638 return;
1639 }
1640
[email protected]420ae012009-04-24 05:16:321641 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1642 if (delegate() && rvh == render_view_host())
1643 delegate()->CloseContents(this);
1644}
1645
1646void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141647 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321648 delegate()->MoveContents(this, new_bounds);
1649}
1650
[email protected]7ab1e7d62009-10-14 23:32:011651void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321652 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491653
[email protected]c40d6232011-03-25 00:16:211654 if (delegate() && content_restrictions_) {
1655 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211656 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001657 }
[email protected]3c9e1872010-11-18 16:17:491658
1659 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171660 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321661}
1662
[email protected]7ab1e7d62009-10-14 23:32:011663void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321664 scoped_ptr<LoadNotificationDetails> details;
1665
1666 NavigationEntry* entry = controller_.GetActiveEntry();
1667 // An entry may not exist for a stop when loading an initial blank page or
1668 // if an iframe injected by script into a blank page finishes loading.
1669 if (entry) {
[email protected]420ae012009-04-24 05:16:321670 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1671
1672 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541673 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321674 entry->transition_type(),
1675 elapsed,
1676 &controller_,
1677 controller_.GetCurrentEntryIndex()));
1678 }
1679
[email protected]420ae012009-04-24 05:16:321680 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491681
1682 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171683 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321684}
1685
[email protected]c95fa8b2011-04-28 20:26:161686void TabContents::DidCancelLoading() {
1687 controller_.DiscardNonCommittedEntries();
1688
1689 // Update the URL display.
1690 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1691}
1692
[email protected]1a3c3cb2010-12-16 21:03:401693void TabContents::DidChangeLoadProgress(double progress) {
1694 if (delegate())
1695 delegate()->LoadProgressChanged(progress);
1696}
1697
[email protected]25497492010-09-11 15:15:081698void TabContents::DocumentOnLoadCompletedInMainFrame(
1699 RenderViewHost* render_view_host,
1700 int32 page_id) {
1701 NotificationService::current()->Notify(
1702 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
1703 Source<TabContents>(this),
1704 Details<int>(&page_id));
1705}
1706
[email protected]420ae012009-04-24 05:16:321707void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
1708 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:581709 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351710 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321711 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1712 // generated suggestions).
1713 //
[email protected]e0112912011-02-02 22:54:351714 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161715 // want web sites to see a referrer of "chrome://blah" (and some
1716 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321717 // send to the site), so we send no referrer.
1718 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:581719 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:321720 } else {
1721 OpenURL(url, referrer, disposition, PageTransition::LINK);
1722 }
1723}
1724
[email protected]420ae012009-04-24 05:16:321725void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151726 const RenderViewHost* rvh,
[email protected]420ae012009-04-24 05:16:321727 const std::wstring& message,
1728 const std::wstring& default_prompt,
1729 const GURL& frame_url,
1730 const int flags,
1731 IPC::Message* reply_msg,
1732 bool* did_suppress_message) {
1733 // Suppress javascript messages when requested and when inside a constrained
1734 // popup window (because that activates them and breaks them out of the
1735 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:551736 // Also suppress messages when showing an interstitial. The interstitial is
1737 // shown over the previous page, we don't want the hidden page dialogs to
1738 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501739 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151740 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501741 suppress_javascript_messages_ ||
1742 showing_interstitial_page() ||
1743 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:321744 if (delegate())
1745 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:311746 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:321747
1748 *did_suppress_message = suppress_this_message;
1749
1750 if (!suppress_this_message) {
1751 base::TimeDelta time_since_last_message(
1752 base::TimeTicks::Now() - last_javascript_message_dismissal_);
1753 bool show_suppress_checkbox = false;
1754 // Show a checkbox offering to suppress further messages if this message is
1755 // being displayed within kJavascriptMessageExpectedDelay of the last one.
1756 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:151757 base::TimeDelta::FromMilliseconds(
1758 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:321759 show_suppress_checkbox = true;
1760
[email protected]d6ad7442010-09-05 19:06:521761 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
1762 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:321763 } else {
1764 // If we are suppressing messages, just reply as is if the user immediately
1765 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:541766 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:321767 }
1768}
1769
[email protected]992db4c2011-05-12 15:37:151770void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
1771 const std::wstring& message,
[email protected]420ae012009-04-24 05:16:321772 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291773 if (delegate())
1774 delegate()->WillRunBeforeUnloadConfirm();
[email protected]992db4c2011-05-12 15:37:151775 bool suppress_this_message = rvh->is_swapped_out() ||
1776 (delegate() && delegate()->ShouldSuppressDialogs());
1777 if (suppress_this_message) {
[email protected]8f55e802010-12-06 18:11:501778 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
1779 std::wstring());
1780 return;
1781 }
[email protected]7ab1e7d62009-10-14 23:32:011782 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:221783 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:321784}
1785
[email protected]420ae012009-04-24 05:16:321786GURL TabContents::GetAlternateErrorPageURL() const {
[email protected]763ec4ca2011-04-29 15:48:121787 return content::GetContentClient()->browser()->GetAlternateErrorPageURL(this);
[email protected]420ae012009-04-24 05:16:321788}
1789
1790WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:061791 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:581792 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:081793 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:581794 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:081795
[email protected]9beff752010-09-22 19:35:431796 // Force accelerated compositing and 2d canvas off for chrome: and
1797 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:431798 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
1799 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:081800 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431801 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081802 }
1803
[email protected]39553442010-09-09 00:01:551804#if defined(OS_MACOSX)
1805 // Disable accelerated compositing if IOSurface's are not supported,
1806 // as is the case in 10.5.
1807 if (!IOSurfaceSupport::Initialize())
1808 web_prefs.accelerated_compositing_enabled = false;
1809#endif
1810
[email protected]447021c2010-09-08 21:29:081811 return web_prefs;
[email protected]420ae012009-04-24 05:16:321812}
1813
[email protected]7d472472011-01-22 01:30:251814void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271815 // Notify observers.
1816 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]7d472472011-01-22 01:30:251817 ExternalProtocolHandler::PermitLaunchUrl();
1818}
1819
[email protected]fa1cf0b82010-01-15 21:49:441820void TabContents::OnIgnoredUIEvent() {
1821 if (constrained_window_count()) {
1822 ConstrainedWindow* window = *constrained_window_begin();
1823 window->FocusConstrainedWindow();
1824 }
1825}
1826
[email protected]420ae012009-04-24 05:16:321827void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
1828 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:341829 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:321830 // delivered to a pending RenderViewHost. We must first run the onunload
1831 // handler of the old RenderViewHost before we can allow it to proceed.
1832 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
1833 new_request_id);
1834}
1835
[email protected]420ae012009-04-24 05:16:321836void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1837 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151838 // Don't show hung renderer dialog for a swapped out RVH.
1839 if (rvh != render_view_host())
1840 return;
1841
[email protected]420ae012009-04-24 05:16:321842 if (is_during_unload) {
1843 // Hang occurred while firing the beforeunload/unload handler.
1844 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111845 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321846
1847 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1848 return;
1849
1850 // If the tab hangs in the beforeunload/unload handler there's really
1851 // nothing we can do to recover. Pretend the unload listeners have
1852 // all fired and close the tab. If the hang is in the beforeunload handler
1853 // then the user will not have the option of cancelling the close.
1854 Close(rvh);
1855 return;
1856 }
1857
[email protected]61b50092011-02-03 18:02:191858 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
1859 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:291860 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:191861 }
[email protected]420ae012009-04-24 05:16:321862}
1863
1864void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:291865 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:321866}
1867
1868void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:561869 net::LoadState load_state,
1870 uint64 upload_position,
1871 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321872 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561873 upload_position_ = upload_position;
1874 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501875 load_state_host_ = net::IDNToUnicode(url.host(),
1876 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]420ae012009-04-24 05:16:321877 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
1878 SetNotWaitingForResponse();
1879 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:501880 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321881}
1882
[email protected]1ee614862009-07-06 20:29:181883bool TabContents::IsExternalTabContainer() const {
1884 if (!delegate())
1885 return false;
1886
1887 return delegate()->IsExternalTabContainer();
1888}
1889
[email protected]7d472472011-01-22 01:30:251890void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441891 if (delegate())
1892 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:251893}
1894
[email protected]f364d1392011-04-08 21:03:101895void TabContents::RequestDesktopNotificationPermission(
1896 const GURL& source_origin, int callback_context) {
1897 DesktopNotificationService* service =
[email protected]dcb72d52011-04-13 12:36:531898 DesktopNotificationServiceFactory::GetForProfile(profile());
[email protected]f364d1392011-04-08 21:03:101899 service->RequestPermission(
1900 source_origin, GetRenderProcessHost()->id(),
1901 render_view_host()->routing_id(), callback_context, this);
1902}
1903
[email protected]420ae012009-04-24 05:16:321904void TabContents::BeforeUnloadFiredFromRenderManager(
1905 bool proceed,
1906 bool* proceed_to_fire_unload) {
1907 if (delegate())
1908 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1909}
1910
[email protected]3a3d47472010-07-15 21:03:541911void TabContents::DidStartLoadingFromRenderManager(
1912 RenderViewHost* render_view_host) {
1913 DidStartLoading();
1914}
1915
1916void TabContents::RenderViewGoneFromRenderManager(
1917 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231918 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1919 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541920}
1921
[email protected]420ae012009-04-24 05:16:321922void TabContents::UpdateRenderViewSizeForRenderManager() {
1923 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261924 gfx::Size size = view_->GetContainerSize();
1925 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1926 // here during container initialization and normal window size will be set
1927 // later. In case of tab duplication this resizing to 0x0 prevents setting
1928 // normal size later so just ignore it.
1929 if (!size.IsEmpty())
1930 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321931}
1932
[email protected]3a3d47472010-07-15 21:03:541933void TabContents::NotifySwappedFromRenderManager() {
1934 NotifySwapped();
1935}
1936
1937NavigationController& TabContents::GetControllerForRenderManager() {
1938 return controller();
1939}
1940
[email protected]d0980792011-02-13 19:41:401941WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561942 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321943}
1944
1945NavigationEntry*
1946TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1947 return controller_.GetLastCommittedEntry();
1948}
1949
1950bool TabContents::CreateRenderViewForRenderManager(
1951 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:321952 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:521953
[email protected]420ae012009-04-24 05:16:321954 // Now that the RenderView has been created, we need to tell it its size.
1955 rwh_view->SetSize(view_->GetContainerSize());
1956
[email protected]a4127722011-04-27 23:13:521957 if (!render_view_host->CreateRenderView(string16()))
1958 return false;
1959
[email protected]420ae012009-04-24 05:16:321960 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
1961 render_view_host);
1962 return true;
1963}
1964
1965void TabContents::Observe(NotificationType type,
1966 const NotificationSource& source,
1967 const NotificationDetails& details) {
1968 switch (type.value) {
[email protected]420ae012009-04-24 05:16:321969 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:511970 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:321971 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
1972 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
1973 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:531974 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
1975 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:321976 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:171977 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
1978 UpdateZoomLevel();
[email protected]0a8db0d2011-04-13 15:15:401979 } else if (*pref_name_in == prefs::kEnableReferrers) {
1980 renderer_preferences_util::UpdateFromSystemSettings(
1981 &renderer_preferences_, profile());
1982 render_view_host()->SyncRendererPrefs();
[email protected]420ae012009-04-24 05:16:321983 } else {
1984 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
1985 }
1986 break;
1987 }
1988 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
1989 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
1990 break;
1991
[email protected]d3ba77272009-09-03 00:06:091992#if defined(OS_LINUX)
1993 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:541994 renderer_preferences_util::UpdateFromSystemSettings(
1995 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:091996 render_view_host()->SyncRendererPrefs();
1997 break;
1998 }
1999#endif
2000
[email protected]6c32ce72010-03-08 05:18:062001 case NotificationType::USER_STYLE_SHEET_UPDATED:
2002 UpdateWebPreferences();
2003 break;
2004
[email protected]88152052010-10-01 04:05:182005 case NotificationType::GOOGLE_URL_UPDATED:
2006 UpdateAlternateErrorPageURL();
2007 break;
2008
[email protected]420ae012009-04-24 05:16:322009 default:
2010 NOTREACHED();
2011 }
2012}
[email protected]aacd7cc2009-09-02 14:51:102013
[email protected]beb440c2009-11-06 04:08:542014gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2015 return view_->GetTopLevelNativeWindow();
2016}
2017
2018void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2019 bool success,
2020 const std::wstring& prompt) {
2021 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2022 if (is_showing_before_unload_dialog_ && !success) {
2023 // If a beforeunload dialog is canceled, we need to stop the throbber from
2024 // spinning, since we forced it to start spinning in Navigate.
2025 DidStopLoading();
2026
2027 tab_close_start_time_ = base::TimeTicks();
2028 }
2029 is_showing_before_unload_dialog_ = false;
2030 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2031}
2032
2033void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2034 set_suppress_javascript_messages(suppress_message_boxes);
2035}
2036
[email protected]3a3d47472010-07-15 21:03:542037TabContents* TabContents::AsTabContents() {
2038 return this;
2039}
2040
2041ExtensionHost* TabContents::AsExtensionHost() {
2042 return NULL;
2043}
2044
[email protected]41fc0322009-09-04 22:23:402045void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122046 encoding_ = content::GetContentClient()->browser()->
2047 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102048}
[email protected]f45d2a72010-03-08 23:28:352049
[email protected]33f74972010-12-08 16:40:362050void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2051 render_manager_.SwapInRenderViewHost(rvh);
2052}
2053
2054void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2055 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2056 rwh_view->SetSize(view()->GetContainerSize());
2057}
[email protected]e7d50892011-01-19 21:47:382058
[email protected]232a5812011-03-04 22:42:082059void TabContents::OnOnlineStateChanged(bool online) {
2060 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2061 render_view_host()->routing_id(), online));
2062}