blob: 26b6ea3df7ed1b58f770fc2cfeed35708eaec77d [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]8cc8d492010-02-02 10:40:499#include "base/auto_reset.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]c65e2f152010-10-14 15:30:4016#include "chrome/browser/blocked_content_container.h"
[email protected]96d185d2009-04-24 03:28:5417#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5518#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1019#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4520#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3321#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5422#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1423#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2724#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3225#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0226#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0128#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0029#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3130#include "chrome/browser/external_protocol_handler.h"
31#include "chrome/browser/favicon_service.h"
[email protected]3c733bde2010-12-21 19:56:3132#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2133#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5834#include "chrome/browser/history/history_types.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/load_from_memory_cache_details.h"
36#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4437#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1838#include "chrome/browser/metrics/user_metrics.h"
[email protected]c8865482009-07-23 20:40:1039#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1740#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2441#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5842#include "chrome/browser/plugin_observer.h"
[email protected]8ecad5e2010-12-02 21:18:3343#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5444#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3245#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1346#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1747#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2948#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4949#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5250#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1651#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3552#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2953#include "chrome/browser/ui/browser_dialogs.h"
[email protected]54ec6472010-04-09 19:39:5854#include "chrome/common/bindings_policy.h"
[email protected]1698f612011-03-11 11:28:1555#include "chrome/common/chrome_constants.h"
[email protected]35f7d212009-04-29 21:19:2756#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2157#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4958#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5759#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4860#include "chrome/common/extensions/extension_icon_set.h"
[email protected]44c49c92011-03-28 16:17:2361#include "chrome/common/extensions/extension_messages.h"
[email protected]942690b132010-05-11 06:42:1462#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0963#include "chrome/common/extensions/url_pattern.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3265#include "chrome/common/render_messages.h"
[email protected]96d185d2009-04-24 03:28:5466#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5067#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5668#include "content/browser/content_browser_client.h"
[email protected]567812d2011-02-24 17:40:5069#include "content/browser/host_zoom_map.h"
70#include "content/browser/in_process_webkit/session_storage_namespace.h"
71#include "content/browser/renderer_host/render_process_host.h"
72#include "content/browser/renderer_host/render_view_host.h"
73#include "content/browser/renderer_host/render_widget_host_view.h"
74#include "content/browser/renderer_host/resource_request_details.h"
75#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4476#include "content/browser/tab_contents/interstitial_page.h"
77#include "content/browser/tab_contents/navigation_entry.h"
78#include "content/browser/tab_contents/provisional_load_details.h"
79#include "content/browser/tab_contents/tab_contents_delegate.h"
80#include "content/browser/tab_contents/tab_contents_observer.h"
81#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]1fd1a502011-03-30 16:55:5682#include "content/browser/webui/web_ui_factory.h"
83#include "content/common/content_client.h"
[email protected]4dd57932011-03-17 06:06:1284#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3285#include "content/common/notification_service.h"
[email protected]2c5569662011-03-22 20:45:0286#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2987#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3288#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3489#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3790#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4691#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3892#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0393#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3194#include "webkit/glue/webpreferences.h"
95
96#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1297#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3198#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0099
[email protected]420ae012009-04-24 05:16:32100// Cross-Site Navigations
101//
102// If a TabContents is told to navigate to a different web site (as determined
103// by SiteInstance), it will replace its current RenderViewHost with a new
104// RenderViewHost dedicated to the new SiteInstance. This works as follows:
105//
106// - Navigate determines whether the destination is cross-site, and if so,
107// it creates a pending_render_view_host_ and moves into the PENDING
108// RendererState.
109// - The pending RVH is "suspended," so that no navigation messages are sent to
110// its renderer until the onbeforeunload JavaScript handler has a chance to
111// run in the current RVH.
112// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
113// that it has a pending cross-site request. ResourceDispatcherHost will
114// check for this when the response arrives.
115// - The current RVH runs its onbeforeunload handler. If it returns false, we
116// cancel all the pending logic and go back to NORMAL. Otherwise we allow
117// the pending RVH to send the navigation request to its renderer.
118// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
119// checks CrossSiteRequestManager to see that the RVH responsible has a
120// pending cross-site request, and then installs a CrossSiteEventHandler.
121// - When RDH receives a response, the BufferedEventHandler determines whether
122// it is a download. If so, it sends a message to the new renderer causing
123// it to cancel the request, and the download proceeds in the download
124// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34125// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32126// doesn't affect any functionality.
127// - After RDH receives a response and determines that it is safe and not a
128// download, it pauses the response to first run the old page's onunload
129// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34130// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32131// to the current RVH.
132// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
133// the ResourceDispatcherHost, who unpauses the response. Data is then sent
134// to the pending RVH.
135// - The pending renderer sends a FrameNavigate message that invokes the
136// DidNavigate method. This replaces the current RVH with the
137// pending RVH and goes back to the NORMAL RendererState.
138
139namespace {
140
141// Amount of time we wait between when a key event is received and the renderer
142// is queried for its state and pushed to the NavigationEntry.
143const int kQueryStateDelay = 5000;
144
[email protected]6ebdc9b2010-09-27 16:55:57145const int kSyncWaitDelay = 40;
146
[email protected]420ae012009-04-24 05:16:32147// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51148const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32149 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17150 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32151 prefs::kWebKitJavaEnabled,
152 prefs::kWebKitJavascriptEnabled,
153 prefs::kWebKitLoadsImagesAutomatically,
154 prefs::kWebKitPluginsEnabled,
155 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10156 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32157 prefs::kWebKitSerifFontFamily,
158 prefs::kWebKitSansSerifFontFamily,
159 prefs::kWebKitFixedFontFamily,
160 prefs::kWebKitDefaultFontSize,
161 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13162 prefs::kWebKitMinimumFontSize,
163 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36164 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32165 prefs::kDefaultCharset
[email protected]420ae012009-04-24 05:16:32166};
167
168const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
169
[email protected]420ae012009-04-24 05:16:32170#if defined(OS_WIN)
171
172BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
173 // Note: erase is required to properly paint some widgets borders. This can
174 // be seen with textfields.
175 InvalidateRect(hwnd, NULL, TRUE);
176 return TRUE;
177}
178#endif
179
[email protected]2c5569662011-03-22 20:45:02180ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16181 Profile* profile, const NavigationEntry& entry,
182 NavigationController::ReloadType reload_type) {
183 switch (reload_type) {
184 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16186 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16188 case NavigationController::NO_RELOAD:
189 break; // Fall through to rest of function.
190 }
[email protected]5e369672009-11-03 23:48:30191
192 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
193 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30195
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30197}
198
[email protected]876bc832010-09-07 16:29:54199void MakeNavigateParams(const NavigationEntry& entry,
200 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16201 NavigationController::ReloadType reload_type,
202 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34203 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54204 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00205 params->current_history_list_offset = controller.last_committed_entry_index();
206 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34207 params->url = entry.url();
208 params->referrer = entry.referrer();
209 params->transition = entry.transition_type();
210 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00211 params->navigation_type =
212 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34213 params->request_time = base::Time::Now();
214}
215
[email protected]420ae012009-04-24 05:16:32216} // namespace
217
[email protected]f4f50ef2011-01-21 19:01:19218
219// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32220
[email protected]420ae012009-04-24 05:16:32221TabContents::TabContents(Profile* profile,
222 SiteInstance* site_instance,
223 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07224 const TabContents* base_tab_contents,
225 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42226 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07227 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
228 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13229 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22230 TabContentsView::Create(this))),
231 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06232 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34233 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23234 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
235 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34236 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34237 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57238 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56239 upload_size_(0),
240 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57241 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40242 blocked_contents_(NULL),
243 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49244 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47245 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08246 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57247 capturing_contents_(false),
248 is_being_destroyed_(false),
249 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57250#if defined(OS_WIN)
251 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
252#endif
[email protected]c2e74fe82009-09-03 17:57:44253 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01254 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56255 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16256 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38257 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25258 minimum_zoom_percent_(
259 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
260 maximum_zoom_percent_(
261 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00262 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59263 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54264 renderer_preferences_util::UpdateFromSystemSettings(
265 &renderer_preferences_, profile);
266
[email protected]9fb83e82010-07-02 18:24:55267 content_settings_delegate_.reset(
268 new TabSpecificContentSettings(this, profile));
269
[email protected]12636df2009-09-28 22:32:21270 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32271
[email protected]34ac70502009-09-25 17:07:23272 // We have the initial size of the view be based on the size of the passed in
273 // tab contents (normally a tab from the same window).
274 view_->CreateView(base_tab_contents ?
275 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32276
277 // Register for notifications about all interested prefs change.
278 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28279 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32280 if (prefs) {
281 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28282 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32283 }
284
[email protected]420ae012009-04-24 05:16:32285 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
286 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09287#if defined(OS_LINUX)
288 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
289 NotificationService::AllSources());
290#endif
[email protected]420ae012009-04-24 05:16:32291
[email protected]6c32ce72010-03-08 05:18:06292 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
293 NotificationService::AllSources());
294
[email protected]79580c62010-02-02 02:36:25295 // Register for notifications about content setting changes.
296 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
297 NotificationService::AllSources());
298
[email protected]a888b29e62010-04-01 13:38:57299 // Listen for extension changes so we can update extension_for_current_page_.
300 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
301 NotificationService::AllSources());
302 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
303 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57304
[email protected]969182a2011-03-03 14:53:23305 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18306 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
307 NotificationService::AllSources());
308
[email protected]c8865482009-07-23 20:40:10309 // Set-up the showing of the omnibox search infobar if applicable.
310 if (OmniboxSearchHint::IsEnabled(profile))
311 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53312
[email protected]b5a1d11c2011-02-17 03:09:42313 // Can only add observers after render_manager_.Init() is called, since that's
314 // what sets up the render_view_host which TabContentObserver's constructor
315 // uses to get the routing_id.
316 AddObservers();
[email protected]332af7732009-03-11 13:21:35317}
initial.commit09911bf2008-07-26 23:55:29318
319TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32320 is_being_destroyed_ = true;
321
[email protected]bfe4c1582009-10-02 18:11:09322 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32323 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28324 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32325
[email protected]420ae012009-04-24 05:16:32326 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29327 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32328
[email protected]420ae012009-04-24 05:16:32329 // First cleanly close all child windows.
330 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
331 // some of these to close. CloseWindows is async, so it might get called
332 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49333 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32334
[email protected]c65e2f152010-10-14 15:30:40335 // Close all blocked contents.
336 if (blocked_contents_)
337 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13338
[email protected]420ae012009-04-24 05:16:32339 // Notify any observer that have a reference on this tab contents.
340 NotificationService::current()->Notify(
341 NotificationType::TAB_CONTENTS_DESTROYED,
342 Source<TabContents>(this),
343 NotificationService::NoDetails());
344
[email protected]1e5e74f2009-05-27 20:55:12345 // Notify any lasting InfobarDelegates that have not yet been removed that
346 // whatever infobar they were handling in this TabContents has closed,
347 // because the TabContents is going away entirely.
348 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
349 // notification may trigger infobars calls that access their delegate. (and
350 // some implementations of InfoBarDelegate do delete themselves on
351 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40352 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12353 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
354 delegate->InfoBarClosed();
355 }
356 infobar_delegates_.clear();
357
[email protected]420ae012009-04-24 05:16:32358 // TODO(brettw) this should be moved to the view.
359#if defined(OS_WIN)
360 // If we still have a window handle, destroy it. GetNativeView can return
361 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42362 if (GetNativeView()) {
363 RenderViewHost* host = render_view_host();
364 if (host && host->view()) {
365 host->view()->WillWmDestroy();
366 }
[email protected]420ae012009-04-24 05:16:32367 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42368 }
[email protected]420ae012009-04-24 05:16:32369#endif
[email protected]7ab1e7d62009-10-14 23:32:01370
371 // OnCloseStarted isn't called in unit tests.
372 if (!tab_close_start_time_.is_null()) {
373 UMA_HISTOGRAM_TIMES("Tab.Close",
374 base::TimeTicks::Now() - tab_close_start_time_);
375 }
[email protected]b5a1d11c2011-02-17 03:09:42376
[email protected]07d490bc2011-03-07 17:05:26377 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08378
379 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42380}
381
382void TabContents::AddObservers() {
[email protected]16be5c32011-03-15 17:52:03383 favicon_helper_.reset(new FaviconHelper(this));
[email protected]b5a1d11c2011-02-17 03:09:42384 desktop_notification_handler_.reset(
385 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
386 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13387 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
388 this));
[email protected]232a5812011-03-04 22:42:08389 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29390}
391
[email protected]724159a2010-12-30 01:11:18392bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17393 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
394 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10395 while ((observer = it.GetNext()) != NULL)
396 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53397 return true;
[email protected]403415a2011-01-10 18:57:53398
[email protected]724159a2010-12-30 01:11:18399 bool handled = true;
400 bool message_is_ok = true;
401 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
402 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
403 OnDidStartProvisionalLoadForFrame)
404 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
405 OnDidRedirectProvisionalLoad)
406 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
407 OnDidFailProvisionalLoadWithError)
408 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
409 OnDidLoadResourceFromMemoryCache)
410 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
411 OnDidDisplayInsecureContent)
412 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
413 OnDidRunInsecureContent)
414 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
415 OnDocumentLoadedInFrame)
416 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17417 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
418 OnUpdateContentRestrictions)
419 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
420 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25421 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]44c49c92011-03-28 16:17:23422 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo,
[email protected]7d472472011-01-22 01:30:25423 OnDidGetApplicationInfo)
[email protected]44c49c92011-03-28 16:17:23424 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication,
[email protected]7d472472011-01-22 01:30:25425 OnInstallApplication)
426 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
427 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
[email protected]724159a2010-12-30 01:11:18428 IPC_MESSAGE_UNHANDLED(handled = false)
429 IPC_END_MESSAGE_MAP_EX()
430
431 if (!message_is_ok) {
432 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
433 GetRenderProcessHost()->ReceivedBadMessage();
434 }
435
436 return handled;
437}
438
[email protected]13367f72009-07-08 16:39:02439// Returns true if contains content rendered by an extension.
440bool TabContents::HostsExtension() const {
441 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34442}
443
[email protected]1f18184a2010-07-21 19:34:49444TabContentsSSLHelper* TabContents::GetSSLHelper() {
445 if (ssl_helper_.get() == NULL)
446 ssl_helper_.reset(new TabContentsSSLHelper(this));
447 return ssl_helper_.get();
448}
449
[email protected]8cb5d5b2010-02-09 11:36:16450RenderProcessHost* TabContents::GetRenderProcessHost() const {
451 return render_manager_.current_host()->process();
452}
453
[email protected]9adb9692010-10-29 23:14:02454void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46455 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08456 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10457
[email protected]98aa0b52010-05-06 17:03:08458 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57459
[email protected]fca656c2010-02-10 20:30:10460 NotificationService::current()->Notify(
461 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
462 Source<TabContents>(this),
463 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49464}
465
[email protected]98aa0b52010-05-06 17:03:08466void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
467 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40468 return;
469
[email protected]eaa7dd182010-12-14 11:09:00470 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50471 if (!extension_service || !extension_service->is_ready())
472 return;
473
474 const Extension* extension =
475 extension_service->GetExtensionById(extension_app_id, false);
476 if (extension)
477 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40478}
479
[email protected]98aa0b52010-05-06 17:03:08480SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08481 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51482 return NULL;
483
[email protected]98aa0b52010-05-06 17:03:08484 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51485}
486
[email protected]d5f942ba2008-09-26 19:30:34487const GURL& TabContents::GetURL() const {
488 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57489 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54490 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34491}
492
[email protected]96d185d2009-04-24 03:28:54493const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55494 // Transient entries take precedence. They are used for interstitial pages
495 // that are shown on top of existing pages.
496 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23497 if (entry) {
498 return entry->GetTitleForDisplay(profile()->GetPrefs()->
499 GetString(prefs::kAcceptLanguages));
500 }
[email protected]7ade2732011-02-10 00:13:58501 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
502 render_manager_.pending_web_ui() : render_manager_.web_ui();
503 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54504 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55505 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54506 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35507 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58508 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54509 if (!title.empty())
510 return title;
511 }
512 }
513
514 // We use the title for the last committed entry rather than a pending
515 // navigation entry. For example, when the user types in a URL, we want to
516 // keep the old page's title until the new load has committed and we get a new
517 // title.
[email protected]96d185d2009-04-24 03:28:54518 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23519 if (entry) {
520 return entry->GetTitleForDisplay(profile()->GetPrefs()->
521 GetString(prefs::kAcceptLanguages));
522 }
[email protected]96d185d2009-04-24 03:28:54523 return EmptyString16();
524}
525
[email protected]d5f942ba2008-09-26 19:30:34526int32 TabContents::GetMaxPageID() {
527 if (GetSiteInstance())
528 return GetSiteInstance()->max_page_id();
529 else
530 return max_page_id_;
531}
532
533void TabContents::UpdateMaxPageID(int32 page_id) {
534 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34535 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34536 // testing.
537 if (GetSiteInstance())
538 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16539 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34540}
541
[email protected]96d185d2009-04-24 03:28:54542SiteInstance* TabContents::GetSiteInstance() const {
543 return render_manager_.current_host()->site_instance();
544}
545
[email protected]96d185d2009-04-24 03:28:54546bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15547 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54548 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15549 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01550 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54551 return true;
[email protected]8ab24cc2009-11-13 20:56:15552 }
[email protected]83e3895b2009-06-11 00:07:16553
[email protected]2b9a06402011-02-16 04:57:10554 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56555 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10556 return true;
557
[email protected]d0980792011-02-13 19:41:40558 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58559 if (web_ui)
560 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54561 return true;
562}
563
[email protected]9b488bda2011-03-15 14:42:27564SkBitmap TabContents::GetFavicon() const {
[email protected]d5f942ba2008-09-26 19:30:34565 // Like GetTitle(), we also want to use the favicon for the last committed
566 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57567 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47568 if (entry)
569 return entry->favicon().bitmap();
570
[email protected]ce3fa3c2009-04-20 19:55:57571 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34572 if (entry)
573 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34574 return SkBitmap();
575}
576
[email protected]d8e74e82011-03-15 19:38:48577bool TabContents::FaviconIsValid() const {
[email protected]0b303cc2009-09-28 22:35:15578 NavigationEntry* entry = controller_.GetTransientEntry();
579 if (entry)
580 return entry->favicon().is_valid();
581
582 entry = controller_.GetLastCommittedEntry();
583 if (entry)
584 return entry->favicon().is_valid();
585
586 return false;
587}
588
[email protected]d8e74e82011-03-15 19:38:48589bool TabContents::ShouldDisplayFavicon() {
[email protected]96d185d2009-04-24 03:28:54590 // Always display a throbber during pending loads.
591 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
592 return true;
593
[email protected]d0980792011-02-13 19:41:40594 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58595 if (web_ui)
596 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54597 return true;
598}
599
[email protected]585b30362011-01-28 02:30:17600void TabContents::AddObserver(TabContentsObserver* observer) {
601 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49602}
603
[email protected]585b30362011-01-28 02:30:17604void TabContents::RemoveObserver(TabContentsObserver* observer) {
605 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49606}
607
[email protected]443b80e2010-12-14 00:42:23608void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
609 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34610 return;
611
[email protected]443b80e2010-12-14 00:42:23612 crashed_status_ = status;
613 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50614 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34615}
616
[email protected]744ef172009-10-16 21:53:46617void TabContents::PageActionStateChanged() {
618 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00619}
[email protected]ce5c4502009-05-06 16:46:11620
[email protected]d5f942ba2008-09-26 19:30:34621void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
622 if (delegate_)
623 delegate_->NavigationStateChanged(this, changed_flags);
624}
625
[email protected]96d185d2009-04-24 03:28:54626void TabContents::DidBecomeSelected() {
627 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16628 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
629 if (rwhv) {
630 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43631#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16632 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43633#endif
634 }
[email protected]96d185d2009-04-24 03:28:54635
[email protected]8cb5d5b2010-02-09 11:36:16636 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11637 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54638}
639
640void TabContents::WasHidden() {
641 if (!capturing_contents()) {
642 // |render_view_host()| can be NULL if the user middle clicks a link to open
643 // a tab in then background, then closes the tab before selecting it. This
644 // is because closing the tab calls TabContents::Destroy(), which removes
645 // the |render_view_host()|; then when we actually destroy the window,
646 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16647 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
648 if (rwhv)
649 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54650 }
651
652 NotificationService::current()->Notify(
653 NotificationType::TAB_CONTENTS_HIDDEN,
654 Source<TabContents>(this),
655 NotificationService::NoDetails());
656}
657
[email protected]d5f942ba2008-09-26 19:30:34658void TabContents::Activate() {
659 if (delegate_)
660 delegate_->ActivateContents(this);
661}
662
[email protected]ea42e7782010-08-23 23:58:12663void TabContents::Deactivate() {
664 if (delegate_)
665 delegate_->DeactivateContents(this);
666}
667
[email protected]96d185d2009-04-24 03:28:54668void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16669 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
670 if (rwhv)
671 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54672}
673
674void TabContents::HideContents() {
675 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
676 // our superclass HideContents(), because some callers want to be very picky
677 // about the order in which these get called. In addition to making the code
678 // here practically impossible to understand, this also means we end up
679 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34680 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54681 WasHidden();
682}
683
[email protected]5aab5e22010-12-08 22:13:29684bool TabContents::NeedToFireBeforeUnload() {
685 // TODO(creis): Should we fire even for interstitial pages?
686 return notify_disconnection() &&
687 !showing_interstitial_page() &&
688 !render_view_host()->SuddenTerminationAllowed();
689}
690
[email protected]c0588052008-10-27 23:01:50691void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34692 WindowOpenDisposition disposition,
693 PageTransition::Type transition) {
694 if (delegate_)
[email protected]c0588052008-10-27 23:01:50695 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34696}
697
[email protected]1ccb3568d2010-02-19 10:51:16698bool TabContents::NavigateToPendingEntry(
699 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54700 return NavigateToEntry(*controller_.pending_entry(), reload_type);
701}
[email protected]96d185d2009-04-24 03:28:54702
[email protected]876bc832010-09-07 16:29:54703bool TabContents::NavigateToEntry(
704 const NavigationEntry& entry,
705 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54706 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
707 if (!dest_render_view_host)
708 return false; // Unable to create the desired render view host.
709
[email protected]770dd8b2010-05-24 18:11:39710 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
711 dest_render_view_host->EnablePreferredSizeChangedMode(
712 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
713 }
[email protected]9fb325e2010-05-06 18:23:24714
[email protected]80a8fad2011-01-29 04:02:38715 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07716 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58717 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56718 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
719 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
720 entry.url());
[email protected]c09163a2011-02-15 00:05:55721 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
722 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58723
[email protected]96d185d2009-04-24 03:28:54724 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12725 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32726 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00727 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
728 dest_render_view_host,
729 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32730 }
[email protected]96d185d2009-04-24 03:28:54731
732 // Used for page load time metrics.
733 current_load_start_ = base::TimeTicks::Now();
734
735 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34736 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54737 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04738 if (delegate_) {
739 navigate_params.extra_headers =
740 delegate_->GetNavigationHeaders(navigate_params.url);
741 }
[email protected]056de2d2009-06-26 16:41:34742 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54743
744 if (entry.page_id() == -1) {
745 // HACK!! This code suppresses javascript: URLs from being added to
746 // session history, which is what we want to do for javascript: URLs that
747 // do not generate content. What we really need is a message from the
748 // renderer telling us that a new page was not created. The same message
749 // could be used for mailto: URLs and the like.
750 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
751 return false;
752 }
753
[email protected]3c9e1872010-11-18 16:17:49754 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17755 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54756
[email protected]1ccb3568d2010-02-19 10:51:16757 if (reload_type != NavigationController::NO_RELOAD &&
758 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48759 FaviconService* favicon_service =
760 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
761 if (favicon_service)
762 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54763 }
764
[email protected]d5f942ba2008-09-26 19:30:34765 return true;
766}
767
[email protected]96d185d2009-04-24 03:28:54768void TabContents::Stop() {
769 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47770 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54771}
772
[email protected]96d185d2009-04-24 03:28:54773void TabContents::DisassociateFromPopupCount() {
774 render_view_host()->DisassociateFromPopupCount();
775}
776
777TabContents* TabContents::Clone() {
778 // We create a new SiteInstance so that the new tab won't share processes
779 // with the old one. This can be changed in the future if we need it to share
780 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32781 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54782 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07783 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54784 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08785 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08786 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54787 return tc;
788}
789
[email protected]4d677202009-07-19 07:37:12790void TabContents::ShowPageInfo(const GURL& url,
791 const NavigationEntry::SSLStatus& ssl,
792 bool show_history) {
793 if (!delegate_)
794 return;
795
[email protected]bb678332009-07-21 00:15:50796 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12797}
798
[email protected]ef0d04c2010-12-15 23:34:21799void TabContents::SaveFavicon() {
800 NavigationEntry* entry = controller_.GetActiveEntry();
801 if (!entry || entry->url().is_empty())
802 return;
803
804 // Make sure the page is in history, otherwise adding the favicon does
805 // nothing.
806 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
807 Profile::IMPLICIT_ACCESS);
808 if (!history)
809 return;
810 history->AddPageNoVisitForBookmark(entry->url());
811
812 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
813 Profile::IMPLICIT_ACCESS);
814 if (!service)
815 return;
816 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
817 if (!favicon.is_valid() || favicon.url().is_empty() ||
818 favicon.bitmap().empty()) {
819 return;
820 }
821 std::vector<unsigned char> image_data;
822 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
[email protected]849ccee2011-03-16 17:05:30823 service->SetFavicon(
824 entry->url(), favicon.url(), image_data, history::FAVICON);
[email protected]ef0d04c2010-12-15 23:34:21825}
826
initial.commit09911bf2008-07-26 23:55:29827ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28828 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29829 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28830 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33831 AddConstrainedDialog(window);
832 return window;
833}
834
835void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29836 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44837
838 if (child_windows_.size() == 1) {
839 window->ShowConstrainedWindow();
840 BlockTabContent(true);
841 }
initial.commit09911bf2008-07-26 23:55:29842}
843
[email protected]fa1cf0b82010-01-15 21:49:44844void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55845 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45846 // 70% opaque grey.
847 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55848 if (rwhv)
[email protected]1b072562010-12-13 19:37:45849 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44850 render_view_host()->set_ignore_input_events(blocked);
851 if (delegate_)
852 delegate_->SetTabContentBlocked(this, blocked);
853}
854
initial.commit09911bf2008-07-26 23:55:29855void TabContents::AddNewContents(TabContents* new_contents,
856 WindowOpenDisposition disposition,
857 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29858 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40859 if (all_contents_blocked_) {
860 if (!blocked_contents_)
861 blocked_contents_ = new BlockedContentContainer(this);
862 blocked_contents_->AddTabContents(
863 new_contents, disposition, initial_pos, user_gesture);
864 return;
865 }
866
initial.commit09911bf2008-07-26 23:55:29867 if (!delegate_)
868 return;
869
[email protected]35f7d212009-04-29 21:19:27870 if ((disposition == NEW_POPUP) && !user_gesture &&
871 !CommandLine::ForCurrentProcess()->HasSwitch(
872 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22873 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31874 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29875 delegate_->GetConstrainingContents(this)->AddPopup(
876 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31877 } else {
[email protected]0aa55312008-10-17 21:53:08878 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29879 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
880 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49881 NotificationService::current()->Notify(
882 NotificationType::TAB_ADDED,
883 Source<TabContentsDelegate>(delegate_),
884 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29885 }
initial.commit09911bf2008-07-26 23:55:29886
[email protected]8cc8d492010-02-02 10:40:49887 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40888 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29889}
890
[email protected]bcd9dc42010-01-23 16:38:18891bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:20892 bool is_js_code, const std::string& code_string,
893 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51894 RenderViewHost* host = render_view_host();
895 if (!host)
896 return false;
897
[email protected]44c49c92011-03-28 16:17:23898 ExtensionMsg_ExecuteCode_Params params;
899 params.request_id = request_id;
900 params.extension_id = extension_id;
901 params.is_javascript = is_js_code;
902 params.code = code_string;
903 params.all_frames = all_frames;
904 return host->Send(new ExtensionMsg_ExecuteCode(host->routing_id(), params));
[email protected]912256b32009-09-18 09:47:35905}
906
[email protected]96d185d2009-04-24 03:28:54907void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49908 if (is_being_destroyed_)
909 return;
[email protected]9fb83e82010-07-02 18:24:55910 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49911 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40912 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54913}
914
[email protected]5c9e97a2009-09-09 23:48:30915gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54916 return view_->GetContentNativeView();
917}
918
919gfx::NativeView TabContents::GetNativeView() const {
920 return view_->GetNativeView();
921}
922
923void TabContents::GetContainerBounds(gfx::Rect *out) const {
924 view_->GetContainerBounds(out);
925}
926
927void TabContents::Focus() {
928 view_->Focus();
929}
930
[email protected]90daadb42009-06-08 21:27:28931void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54932 if (showing_interstitial_page()) {
933 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
934 return;
935 }
[email protected]96d185d2009-04-24 03:28:54936 render_view_host()->SetInitialFocus(reverse);
937}
938
939bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40940 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58941 if (web_ui)
942 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43943 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25944 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43945 return true;
[email protected]96d185d2009-04-24 03:28:54946 return false;
947}
948
[email protected]a26dc362010-04-23 01:48:58949void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38950 if (delegate())
[email protected]a26dc362010-04-23 01:48:58951 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38952}
953
[email protected]616ed5a2008-11-21 22:27:24954void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32955 if (delegate_ && !delegate_->infobars_enabled()) {
956 delegate->InfoBarClosed();
957 return;
958 }
959
[email protected]616ed5a2008-11-21 22:27:24960 // Look through the existing InfoBarDelegates we have for a match. If we've
961 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40962 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45963 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
964 // Tell the new infobar to close so that it can clean itself up.
965 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24966 return;
[email protected]6d27a7b2009-12-18 23:25:45967 }
[email protected]616ed5a2008-11-21 22:27:24968 }
969
970 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56971 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19972 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56973 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24974
975 // Add ourselves as an observer for navigations the first time a delegate is
976 // added. We use this notification to expire InfoBars that need to expire on
977 // page transitions.
978 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56979 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57980 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24981 }
982}
983
984void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32985 if (delegate_ && !delegate_->infobars_enabled()) {
986 return;
987 }
988
[email protected]616ed5a2008-11-21 22:27:24989 std::vector<InfoBarDelegate*>::iterator it =
990 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
991 if (it != infobar_delegates_.end()) {
992 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56993 NotificationService::current()->Notify(
994 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
995 Source<TabContents>(this),
996 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24997
[email protected]f4f50ef2011-01-21 19:01:19998 infobar_delegates_.erase(it);
999 // Remove ourselves as an observer if we are tracking no more InfoBars.
1000 if (infobar_delegates_.empty()) {
1001 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1002 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031003 }
[email protected]616ed5a2008-11-21 22:27:241004 }
1005}
[email protected]3edd9522009-03-04 22:19:411006
[email protected]f81821c2009-08-07 01:29:471007void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1008 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321009 if (delegate_ && !delegate_->infobars_enabled()) {
1010 new_delegate->InfoBarClosed();
1011 return;
1012 }
1013
[email protected]f81821c2009-08-07 01:29:471014 std::vector<InfoBarDelegate*>::iterator it =
1015 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1016 DCHECK(it != infobar_delegates_.end());
1017
1018 // Notify the container about the change of plans.
1019 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1020 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1021 old_delegate, new_delegate));
1022 NotificationService::current()->Notify(
1023 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1024 Source<TabContents>(this),
1025 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1026
[email protected]f4f50ef2011-01-21 19:01:191027 // Remove the old one.
1028 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471029
1030 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081031 DCHECK(find(infobar_delegates_.begin(),
1032 infobar_delegates_.end(), new_delegate) ==
1033 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471034 infobar_delegates_.push_back(new_delegate);
1035}
1036
[email protected]20ede072009-10-06 00:28:351037bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271038 if (showing_interstitial_page())
1039 return false;
1040
[email protected]c8f74942010-09-03 10:04:141041 // Do not show bookmarks bar if bookmarks aren't enabled.
1042 if (!browser_defaults::bookmarks_enabled)
1043 return false;
1044
[email protected]d0980792011-02-13 19:41:401045 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541046 // similar, but for non-first loads, we want to use the committed entry. This
1047 // is so the bookmarks bar disappears at the same time the page does.
1048 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351049 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581050 return (render_manager_.web_ui() == NULL) ?
1051 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541052 }
1053
1054 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401055 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541056 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581057 if (render_manager_.pending_web_ui())
1058 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1059 return (render_manager_.web_ui() == NULL) ?
1060 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541061}
1062
[email protected]3edd9522009-03-04 22:19:411063void TabContents::ToolbarSizeChanged(bool is_animating) {
1064 TabContentsDelegate* d = delegate();
1065 if (d)
1066 d->ToolbarSizeChanged(this, is_animating);
1067}
[email protected]616ed5a2008-11-21 22:27:241068
[email protected]fc6fb7fb2009-11-07 02:35:041069bool TabContents::CanDownload(int request_id) {
1070 TabContentsDelegate* d = delegate();
1071 if (d)
1072 return d->CanDownload(request_id);
1073 return true;
1074}
1075
[email protected]d5f942ba2008-09-26 19:30:341076void TabContents::OnStartDownload(DownloadItem* download) {
1077 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341078
1079 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311080 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341081
[email protected]5b928b62010-08-03 11:46:511082 if (tab_contents && tab_contents->delegate())
1083 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411084}
[email protected]3edd9522009-03-04 22:19:411085
[email protected]d5f942ba2008-09-26 19:30:341086void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371087 ConstrainedWindowList::iterator i(
1088 std::find(child_windows_.begin(), child_windows_.end(), window));
1089 bool removed_topmost_window = i == child_windows_.begin();
1090 if (i != child_windows_.end())
1091 child_windows_.erase(i);
1092 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441093 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371094 } else {
1095 if (removed_topmost_window)
1096 child_windows_[0]->ShowConstrainedWindow();
1097 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441098 }
[email protected]66ba4932009-06-04 19:22:131099}
[email protected]d5f942ba2008-09-26 19:30:341100
[email protected]c65e2f152010-10-14 15:30:401101void TabContents::WillCloseBlockedContentContainer(
1102 BlockedContentContainer* container) {
1103 DCHECK(blocked_contents_ == container);
1104 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491105 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341106}
1107
[email protected]d5f942ba2008-09-26 19:30:341108void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351109#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061110 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351111#endif
[email protected]d5f942ba2008-09-26 19:30:341112}
1113
[email protected]420ae012009-04-24 05:16:321114void TabContents::OnSavePage() {
1115 // If we can not save the page, try to download it.
1116 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1117 DownloadManager* dlm = profile()->GetDownloadManager();
1118 const GURL& current_page_url = GetURL();
1119 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221120 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321121 return;
1122 }
1123
1124 Stop();
1125
1126 // Create the save package and possibly prompt the user for the name to save
1127 // the page as. The user prompt is an asynchronous operation that runs on
1128 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421129 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321130 save_package_->GetSaveInfo();
1131}
1132
1133// Used in automated testing to bypass prompting the user for file names.
1134// Instead, the names and paths are hard coded rather than running them through
1135// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111136bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321137 SavePackage::SavePackageType save_type) {
1138 // Stop the page from navigating.
1139 Stop();
1140
[email protected]b5a1d11c2011-02-17 03:09:421141 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591142 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321143}
1144
[email protected]89d6e6e2009-12-03 23:06:511145void TabContents::EmailPageLocation() {
1146 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1147 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1148 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1149 title + "&body=%0A%0A" + page_url;
1150 platform_util::OpenExternal(GURL(mailto));
1151}
1152
[email protected]420ae012009-04-24 05:16:321153bool TabContents::PrintNow() {
1154 // We can't print interstitial page for now.
1155 if (showing_interstitial_page())
1156 return false;
1157
1158 return render_view_host()->PrintPages();
1159}
1160
[email protected]82270452009-06-19 15:58:011161void TabContents::PrintingDone(int document_cookie, bool success) {
1162 render_view_host()->PrintingDone(document_cookie, success);
1163}
1164
[email protected]420ae012009-04-24 05:16:321165bool TabContents::IsActiveEntry(int32 page_id) {
1166 NavigationEntry* active_entry = controller_.GetActiveEntry();
1167 return (active_entry != NULL &&
1168 active_entry->site_instance() == GetSiteInstance() &&
1169 active_entry->page_id() == page_id);
1170}
1171
[email protected]b2fe07d12010-02-09 14:38:081172void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161173 set_encoding(encoding);
1174 render_view_host()->SetPageEncoding(encoding);
1175}
1176
[email protected]b2fe07d12010-02-09 14:38:081177void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161178 reset_encoding();
1179 render_view_host()->ResetPageEncodingToDefault();
1180}
1181
1182void TabContents::WindowMoveOrResizeStarted() {
1183 render_view_host()->WindowMoveOrResizeStarted();
1184}
1185
[email protected]c65e2f152010-10-14 15:30:401186void TabContents::SetAllContentsBlocked(bool value) {
1187 if (all_contents_blocked_ == value)
1188 return;
1189
1190 all_contents_blocked_ = value;
1191 if (!all_contents_blocked_ && blocked_contents_) {
1192 std::vector<TabContents*> blocked;
1193 blocked_contents_->GetBlockedContents(&blocked);
1194 for (size_t i = 0; i < blocked.size(); ++i)
1195 blocked_contents_->LaunchForContents(blocked[i]);
1196 }
1197}
1198
[email protected]3f8eb7f2009-10-02 23:58:051199void TabContents::LogNewTabTime(const std::string& event_name) {
1200 // Not all new tab pages get timed. In those cases, we don't have a
1201 // new_tab_start_time_.
1202 if (new_tab_start_time_.is_null())
1203 return;
1204
1205 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441206 MetricEventDurationDetails details(event_name,
1207 static_cast<int>(duration.InMilliseconds()));
1208
[email protected]7ab1e7d62009-10-14 23:32:011209 if (event_name == "Tab.NewTabScriptStart") {
1210 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1211 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1212 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1213 } else if (event_name == "Tab.NewTabOnload") {
1214 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051215 // The new tab page has finished loading; reset it.
1216 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441217 } else {
1218 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051219 }
[email protected]84abba62009-10-07 17:01:441220 NotificationService::current()->Notify(
1221 NotificationType::METRIC_EVENT_DURATION,
1222 Source<TabContents>(this),
1223 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051224}
1225
[email protected]7ab1e7d62009-10-14 23:32:011226void TabContents::OnCloseStarted() {
1227 if (tab_close_start_time_.is_null())
1228 tab_close_start_time_ = base::TimeTicks::Now();
1229}
1230
[email protected]46624bf2010-06-09 16:04:191231bool TabContents::ShouldAcceptDragAndDrop() const {
1232#if defined(OS_CHROMEOS)
1233 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1234 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201235 if (delegate() && delegate()->IsPopup(this))
1236 return false;
1237 return true;
[email protected]46624bf2010-06-09 16:04:191238#else
1239 return true;
1240#endif
1241}
1242
[email protected]7813bd72011-02-05 02:19:341243void TabContents::SystemDragEnded() {
1244 if (render_view_host())
1245 render_view_host()->DragSourceSystemDragEnded();
1246 if (delegate())
1247 delegate()->DragEnded();
1248}
1249
[email protected]ec0b6c42010-08-26 03:16:581250void TabContents::UpdateHistoryForNavigation(
1251 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1252 if (profile()->IsOffTheRecord())
1253 return;
1254
1255 // Add to history service.
1256 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1257 if (hs)
1258 hs->AddPage(*add_page_args);
1259}
1260
1261void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1262 if (profile()->IsOffTheRecord())
1263 return;
1264
1265 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1266 if (hs)
1267 hs->SetPageTitle(entry.virtual_url(), entry.title());
1268}
1269
[email protected]d0b8d092010-10-25 04:05:171270double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251271 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1272 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171273 return 0;
[email protected]b75b8292010-10-01 07:28:251274
1275 double zoom_level;
1276 if (temporary_zoom_settings_) {
1277 zoom_level = zoom_map->GetTemporaryZoomLevel(
1278 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1279 } else {
1280 zoom_level = zoom_map->GetZoomLevel(GetURL());
1281 }
[email protected]d0b8d092010-10-25 04:05:171282 return zoom_level;
1283}
[email protected]b75b8292010-10-01 07:28:251284
[email protected]d0b8d092010-10-25 04:05:171285int TabContents::GetZoomPercent(bool* enable_increment,
1286 bool* enable_decrement) {
1287 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251288 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171289 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251290 *enable_decrement = percent > minimum_zoom_percent_;
1291 *enable_increment = percent < maximum_zoom_percent_;
1292 return percent;
1293}
1294
[email protected]3c733bde2010-12-21 19:56:311295void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501296 if (!delegate_)
1297 return;
1298
1299 NavigationEntry* active_entry = controller().GetActiveEntry();
1300 if (!active_entry)
1301 return;
1302
1303 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121304}
1305
[email protected]932b7a12011-03-09 12:50:271306void TabContents::ViewFrameSource(const GURL& url,
1307 const std::string& content_state) {
1308 if (!delegate_)
1309 return;
1310
1311 delegate_->ViewSourceForFrame(this, url, content_state);
1312}
1313
[email protected]c40d6232011-03-25 00:16:211314void TabContents::SetContentRestrictions(int restrictions) {
1315 content_restrictions_ = restrictions;
1316 delegate()->ContentRestrictionsChanged(this);
1317}
1318
[email protected]724159a2010-12-30 01:11:181319void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1320 bool is_main_frame,
1321 const GURL& url) {
1322 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1323 GURL validated_url(url);
1324 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1325 GetRenderProcessHost()->id(), &validated_url);
1326
1327 ProvisionalLoadDetails details(
1328 is_main_frame,
1329 controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091330 validated_url, std::string(), is_error_page, frame_id);
[email protected]724159a2010-12-30 01:11:181331 NotificationService::current()->Notify(
1332 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1333 Source<NavigationController>(&controller_),
1334 Details<ProvisionalLoadDetails>(&details));
1335 if (is_main_frame) {
1336 // If we're displaying a network error page do not reset the content
1337 // settings delegate's cookies so the user has a chance to modify cookie
1338 // settings.
1339 if (!is_error_page)
1340 content_settings_delegate_->ClearCookieSpecificContentSettings();
1341 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381342
[email protected]4850a7f2011-03-08 23:36:591343 // Notify observers about the provisional change in the main frame URL.
1344 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1345 OnProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181346 }
1347}
1348
1349void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1350 const GURL& source_url,
1351 const GURL& target_url) {
1352 NavigationEntry* entry;
1353 if (page_id == -1)
1354 entry = controller_.pending_entry();
1355 else
1356 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1357 if (!entry || entry->url() != source_url)
1358 return;
1359 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381360
[email protected]4850a7f2011-03-08 23:36:591361 // Notify observers about the provisional change in the main frame URL.
1362 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1363 OnProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181364}
1365
1366void TabContents::OnDidFailProvisionalLoadWithError(
1367 int64 frame_id,
1368 bool is_main_frame,
1369 int error_code,
1370 const GURL& url,
1371 bool showing_repost_interstitial) {
1372 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1373 << ", error_code: " << error_code
1374 << " is_main_frame: " << is_main_frame
1375 << " showing_repost_interstitial: " << showing_repost_interstitial
1376 << " frame_id: " << frame_id;
1377 GURL validated_url(url);
1378 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1379 GetRenderProcessHost()->id(), &validated_url);
1380
1381 if (net::ERR_ABORTED == error_code) {
1382 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1383 // This means that the interstitial won't be torn down properly, which is
1384 // bad. But if we have an interstitial, go back to another tab type, and
1385 // then load the same interstitial again, we could end up getting the first
1386 // interstitial's "failed" message (as a result of the cancel) when we're on
1387 // the second one.
1388 //
1389 // We can't tell this apart, so we think we're tearing down the current page
1390 // which will cause a crash later one. There is also some code in
1391 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1392 // out because of this problem.
1393 //
1394 // http://code.google.com/p/chromium/issues/detail?id=2855
1395 // Because this will not tear down the interstitial properly, if "back" is
1396 // back to another tab type, the interstitial will still be somewhat alive
1397 // in the previous tab type. If you navigate somewhere that activates the
1398 // tab with the interstitial again, you'll see a flash before the new load
1399 // commits of the interstitial page.
1400 if (showing_interstitial_page()) {
1401 LOG(WARNING) << "Discarding message during interstitial.";
1402 return;
1403 }
1404
1405 // This will discard our pending entry if we cancelled the load (e.g., if we
1406 // decided to download the file instead of load it). Only discard the
1407 // pending entry if the URLs match, otherwise the user initiated a navigate
1408 // before the page loaded so that the discard would discard the wrong entry.
1409 NavigationEntry* pending_entry = controller_.pending_entry();
1410 if (pending_entry && pending_entry->url() == validated_url) {
1411 controller_.DiscardNonCommittedEntries();
1412 // Update the URL display.
1413 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1414 }
1415
1416 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1417 }
1418
1419 // Send out a notification that we failed a provisional load with an error.
1420 ProvisionalLoadDetails details(
1421 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091422 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181423 details.set_error_code(error_code);
1424
1425 NotificationService::current()->Notify(
1426 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1427 Source<NavigationController>(&controller_),
1428 Details<ProvisionalLoadDetails>(&details));
1429}
1430
1431void TabContents::OnDidLoadResourceFromMemoryCache(
1432 const GURL& url,
[email protected]724159a2010-12-30 01:11:181433 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191434 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181435 cache.Increment();
1436
1437 // Send out a notification that we loaded a resource from our memory cache.
1438 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1439 SSLManager::DeserializeSecurityInfo(security_info,
1440 &cert_id, &cert_status,
1441 &security_bits,
1442 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161443 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1444 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181445
1446 NotificationService::current()->Notify(
1447 NotificationType::LOAD_FROM_MEMORY_CACHE,
1448 Source<NavigationController>(&controller_),
1449 Details<LoadFromMemoryCacheDetails>(&details));
1450}
1451
1452void TabContents::OnDidDisplayInsecureContent() {
1453 displayed_insecure_content_ = true;
1454 SSLManager::NotifySSLInternalStateChanged();
1455}
1456
1457void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021458 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231459 LOG(INFO) << security_origin << " ran insecure content from "
1460 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181461 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1462}
1463
1464void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1465 controller_.DocumentLoadedInFrame();
1466 NotificationService::current()->Notify(
1467 NotificationType::FRAME_DOM_CONTENT_LOADED,
1468 Source<NavigationController>(&controller_),
1469 Details<int64>(&frame_id));
1470}
1471
1472void TabContents::OnDidFinishLoad(int64 frame_id) {
1473 NotificationService::current()->Notify(
1474 NotificationType::FRAME_DID_FINISH_LOAD,
1475 Source<NavigationController>(&controller_),
1476 Details<int64>(&frame_id));
1477}
1478
[email protected]c8f73ab2011-01-22 00:05:171479void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211480 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171481}
1482
1483void TabContents::OnPDFHasUnsupportedFeature() {
1484 PDFHasUnsupportedFeature(this);
1485}
1486
[email protected]96d185d2009-04-24 03:28:541487// Notifies the RenderWidgetHost instance about the fact that the page is
1488// loading, or done loading and calls the base implementation.
1489void TabContents::SetIsLoading(bool is_loading,
1490 LoadNotificationDetails* details) {
1491 if (is_loading == is_loading_)
1492 return;
1493
1494 if (!is_loading) {
1495 load_state_ = net::LOAD_STATE_IDLE;
1496 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561497 upload_size_ = 0;
1498 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541499 }
1500
1501 render_manager_.SetIsLoading(is_loading);
1502
1503 is_loading_ = is_loading;
1504 waiting_for_response_ = is_loading;
1505
[email protected]6ebdc9b2010-09-27 16:55:571506 if (delegate_)
1507 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351508 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541509
1510 NotificationType type = is_loading ? NotificationType::LOAD_START :
1511 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111512 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541513 if (details)
1514 det = Details<LoadNotificationDetails>(details);
1515 NotificationService::current()->Notify(type,
1516 Source<NavigationController>(&controller_),
1517 det);
1518}
1519
[email protected]b6c874582009-05-08 19:38:311520void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291521 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061522 // A page can't spawn popups (or do anything else, either) until its load
1523 // commits, so when we reach here, the popup was spawned by the
1524 // NavigationController's last committed entry, not the active entry. For
1525 // example, if a page opens a popup in an onunload() handler, then the active
1526 // entry is the page to be loaded as we navigate away from the unloading
1527 // page. For this reason, we can't use GetURL() to get the opener URL,
1528 // because it returns the active entry.
1529 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1530 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1531
1532 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491533 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091534 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491535 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1536 } else {
[email protected]c65e2f152010-10-14 15:30:401537 if (!blocked_contents_)
1538 blocked_contents_ = new BlockedContentContainer(this);
1539 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1540 true);
[email protected]55126132010-08-19 14:53:281541 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1542 std::string());
[email protected]8cc8d492010-02-02 10:40:491543 }
[email protected]b9681312008-11-07 00:08:261544}
[email protected]616ed5a2008-11-21 22:27:241545
[email protected]616ed5a2008-11-21 22:27:241546void TabContents::ExpireInfoBars(
1547 const NavigationController::LoadCommittedDetails& details) {
1548 // Only hide InfoBars when the user has done something that makes the main
1549 // frame load. We don't want various automatic or subframe navigations making
1550 // it disappear.
1551 if (!details.is_user_initiated_main_frame_load())
1552 return;
1553
[email protected]ec8f51162011-02-08 04:20:401554 // NOTE: It is not safe to change the following code to count upwards or use
1555 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1556 // list.
1557 for (size_t i = infobar_count(); i > 0; --i) {
1558 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051559 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241560 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241561 }
1562}
[email protected]fdd61c62009-04-22 19:22:571563
[email protected]d0980792011-02-13 19:41:401564WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581565 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541566 // that goes along with it to control the basic flags. For example, we want to
1567 // show the pending URL in the URL bar, so we want the display_url flag to
1568 // be from the pending entry.
1569 //
1570 // The confusion comes because there are multiple possibilities for the
1571 // initial load in a tab as a side effect of the way the RenderViewHostManager
1572 // works.
1573 //
[email protected]e0112912011-02-02 22:54:351574 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541575 // the pending one, and we want it to apply here.
1576 //
1577 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1578 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581579 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351580 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541581 //
1582 // This condition handles all of these cases:
1583 //
1584 // - First load in first tab: no committed nav entry + pending nav entry +
1585 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351586 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541587 //
1588 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351589 // no pending Web UI:
1590 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541591 //
1592 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351593 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541594 //
1595 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351596 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541597 if (controller_.pending_entry() &&
1598 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581599 render_manager_.pending_web_ui()))
1600 return render_manager_.pending_web_ui();
1601 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541602}
[email protected]420ae012009-04-24 05:16:321603
[email protected]1fd1a502011-03-30 16:55:561604WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1605 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1606}
1607
[email protected]420ae012009-04-24 05:16:321608void TabContents::DidNavigateMainFramePostCommit(
1609 const NavigationController::LoadCommittedDetails& details,
1610 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561611 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381612 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441613 // that opened the window, as long as both renderers have the same
1614 // privileges.
[email protected]1fd1a502011-03-30 16:55:561615 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1616 WebUI* web_ui = content::GetContentClient()->browser()->
1617 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581618 // web_ui might be NULL if the URL refers to a non-existent extension.
1619 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401620 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581621 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441622 }
1623 }
[email protected]1fd1a502011-03-30 16:55:561624 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441625 }
1626
[email protected]420ae012009-04-24 05:16:321627 if (details.is_user_initiated_main_frame_load()) {
1628 // Clear the status bubble. This is a workaround for a bug where WebKit
1629 // doesn't let us know that the cursor left an element during a
1630 // transition (this is also why the mouse cursor remains as a hand after
1631 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1632 // clear the bubble when a user navigates to a named anchor in the same
1633 // page.
1634 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321635 }
1636
[email protected]420ae012009-04-24 05:16:321637 // Allow the new page to set the title again.
1638 received_page_title_ = false;
1639
1640 // Get the favicon, either from history or request it from the net.
[email protected]16be5c32011-03-15 17:52:031641 favicon_helper_->FetchFavicon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321642
[email protected]0de80162010-02-03 04:52:351643 // Clear all page actions, blocked content notifications and browser actions
1644 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141645 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001646 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081647 if (service) {
1648 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571649 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081650 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521651 if (browser_action) {
1652 browser_action->ClearAllValuesForTab(controller().session_id().id());
1653 NotificationService::current()->Notify(
1654 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571655 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521656 NotificationService::NoDetails());
1657 }
[email protected]92c6f9b92009-10-24 04:35:081658
[email protected]5d246db22009-10-27 06:17:571659 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521660 service->extensions()->at(i)->page_action();
1661 if (page_action) {
1662 page_action->ClearAllValuesForTab(controller().session_id().id());
1663 PageActionStateChanged();
1664 }
[email protected]92c6f9b92009-10-24 04:35:081665 }
[email protected]aece2c7f2009-08-27 20:43:171666 }
[email protected]0de80162010-02-03 04:52:351667
1668 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401669 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341670 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401671 blocked_contents_->Destroy();
1672 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351673 }
1674
1675 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411676 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551677 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471678
1679 // Once the main frame is navigated, we're no longer considered to have
1680 // displayed insecure content.
1681 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171682 }
[email protected]ce5c4502009-05-06 16:46:111683
[email protected]8cc8d492010-02-02 10:40:491684 // Close constrained windows if necessary.
1685 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1686 details.previous_url, details.entry->url()))
1687 CloseConstrainedWindows();
1688
[email protected]3c9e1872010-11-18 16:17:491689 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171690 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491691 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321692}
1693
1694void TabContents::DidNavigateAnyFramePostCommit(
1695 RenderViewHost* render_view_host,
1696 const NavigationController::LoadCommittedDetails& details,
1697 const ViewHostMsg_FrameNavigate_Params& params) {
1698 // If we navigate, start showing messages again. This does nothing to prevent
1699 // a malicious script from spamming messages, since the script could just
1700 // reload the page to stop blocking.
1701 suppress_javascript_messages_ = false;
1702
[email protected]3c9e1872010-11-18 16:17:491703 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171704 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491705 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551706
1707 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581708 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321709}
1710
[email protected]8cc8d492010-02-02 10:40:491711void TabContents::CloseConstrainedWindows() {
1712 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331713 // To ensure that we iterate over every element in child_windows_ we
1714 // need to use a copy of child_windows_. Otherwise if
1715 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1716 // skipping some elements.
1717 ConstrainedWindowList child_windows_copy(child_windows_);
1718 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1719 it != child_windows_copy.end(); ++it) {
1720 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441721 if (window) {
[email protected]420ae012009-04-24 05:16:321722 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441723 BlockTabContent(false);
1724 }
[email protected]420ae012009-04-24 05:16:321725 }
1726}
1727
[email protected]420ae012009-04-24 05:16:321728void TabContents::UpdateAlternateErrorPageURL() {
1729 GURL url = GetAlternateErrorPageURL();
1730 render_view_host()->SetAlternateErrorPageURL(url);
1731}
1732
1733void TabContents::UpdateWebPreferences() {
1734 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1735}
1736
[email protected]d0b8d092010-10-25 04:05:171737void TabContents::UpdateZoomLevel() {
1738 render_view_host()->SetZoomLevel(GetZoomLevel());
1739}
1740
[email protected]420ae012009-04-24 05:16:321741void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1742 RenderViewHost* rvh) {
1743 // If we are creating a RVH for a restored controller, then we might
1744 // have more page IDs than the SiteInstance's current max page ID. We must
1745 // make sure that the max page ID is larger than any restored page ID.
1746 // Note that it is ok for conflicting page IDs to exist in another tab
1747 // (i.e., NavigationController), but if any page ID is larger than the max,
1748 // the back/forward list will get confused.
1749 int max_restored_page_id = controller_.max_restored_page_id();
1750 if (max_restored_page_id > 0) {
1751 int curr_max_page_id = site_instance->max_page_id();
1752 if (max_restored_page_id > curr_max_page_id) {
1753 // Need to update the site instance immediately.
1754 site_instance->UpdateMaxPageID(max_restored_page_id);
1755
1756 // Also tell the renderer to update its internal representation. We
1757 // need to reserve enough IDs to make all restored page IDs less than
1758 // the max.
1759 if (curr_max_page_id < 0)
1760 curr_max_page_id = 0;
1761 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1762 }
1763 }
1764}
1765
[email protected]ec0b6c42010-08-26 03:16:581766scoped_refptr<history::HistoryAddPageArgs>
1767TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541768 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471769 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321770 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581771 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1772 new history::HistoryAddPageArgs(
1773 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1774 params.redirects, params.transition, history::SOURCE_BROWSED,
1775 details.did_replace_entry));
1776 if (PageTransition::IsMainFrame(params.transition) &&
1777 virtual_url != params.url) {
1778 // Hack on the "virtual" URL so that it will appear in history. For some
1779 // types of URLs, we will display a magic URL that is different from where
1780 // the page is actually navigated. We want the user to see in history what
1781 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1782 // only applies to the main frame, as the virtual URL doesn't apply to
1783 // sub-frames.
1784 add_page_args->url = virtual_url;
1785 if (!add_page_args->redirects.empty())
1786 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321787 }
[email protected]ec0b6c42010-08-26 03:16:581788 return add_page_args;
[email protected]420ae012009-04-24 05:16:321789}
1790
1791bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1792 const std::wstring& title) {
1793 // For file URLs without a title, use the pathname instead. In the case of a
1794 // synthesized title, we don't want the update to count toward the "one set
1795 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251796 string16 final_title;
[email protected]420ae012009-04-24 05:16:321797 bool explicit_set;
1798 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251799 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321800 explicit_set = false; // Don't count synthetic titles toward the set limit.
1801 } else {
[email protected]e53668962010-06-23 15:35:251802 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321803 explicit_set = true;
1804 }
1805
[email protected]e53668962010-06-23 15:35:251806 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321807 return false; // Nothing changed, don't bother.
1808
[email protected]e53668962010-06-23 15:35:251809 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321810
[email protected]ec0b6c42010-08-26 03:16:581811 if (!received_page_title_) {
1812 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321813 received_page_title_ = explicit_set;
1814 }
1815
1816 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251817 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321818
[email protected]cbc0e1b2010-04-12 18:33:041819 NotificationService::current()->Notify(
1820 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1821 Source<TabContents>(this),
1822 NotificationService::NoDetails());
1823
[email protected]420ae012009-04-24 05:16:321824 return true;
1825}
1826
1827void TabContents::NotifySwapped() {
1828 // After sending out a swap notification, we need to send a disconnect
1829 // notification so that clients that pick up a pointer to |this| can NULL the
1830 // pointer. See Bug 1230284.
1831 notify_disconnection_ = true;
1832 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341833 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221834 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321835 NotificationService::NoDetails());
1836}
1837
1838void TabContents::NotifyConnected() {
1839 notify_disconnection_ = true;
1840 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341841 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221842 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321843 NotificationService::NoDetails());
1844}
1845
1846void TabContents::NotifyDisconnected() {
1847 if (!notify_disconnection_)
1848 return;
1849
1850 notify_disconnection_ = false;
1851 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341852 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221853 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321854 NotificationService::NoDetails());
1855}
1856
[email protected]7d472472011-01-22 01:30:251857void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541858 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1859 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1860 if (!entry)
1861 return;
1862 // Note that we don't call NavigationController::GotToOffset() as we don't
1863 // want to create a pending navigation entry (it might end up lingering
1864 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521865 entry->set_transition_type(entry->transition_type() |
1866 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541867 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1868 }
[email protected]bf5c2ff392009-07-08 16:24:331869}
1870
[email protected]38789d82010-11-17 06:03:441871void TabContents::OnDidGetApplicationInfo(int32 page_id,
1872 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511873 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331874
[email protected]ed5431872009-11-17 08:39:511875 if (delegate())
1876 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331877}
1878
[email protected]bb461532010-11-26 21:50:231879void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
1880 if (delegate())
1881 delegate()->OnInstallApplication(this, info);
1882}
1883
[email protected]a2cf65eb2010-01-18 08:20:381884void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381885 int32 page_id,
[email protected]e5106202010-06-11 21:12:361886 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101887 const std::string& language,
1888 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381889 // Don't index any https pages. People generally don't want their bank
1890 // accounts, etc. indexed on their computer, especially since some of these
1891 // things are not marked cachable.
1892 // TODO(brettw) we may want to consider more elaborate heuristics such as
1893 // the cachability of the page. We may also want to consider subframes (this
1894 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271895 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1896 // content indexing for chromeos in some future releases.
1897#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381898 if (!url.SchemeIsSecure()) {
1899 Profile* p = profile();
1900 if (p && !p->IsOffTheRecord()) {
1901 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1902 if (hs)
1903 hs->SetPageContents(url, contents);
1904 }
1905 }
[email protected]ccd40a52010-05-11 16:15:271906#endif
[email protected]a8a81292010-01-21 00:32:451907
[email protected]1c57b7b2010-07-12 17:38:101908 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451909
1910 std::string lang = language;
1911 NotificationService::current()->Notify(
1912 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151913 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451914 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521915
1916 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1917 if (CommandLine::ForCurrentProcess()->HasSwitch(
1918 switches::kEnableInBrowserThumbnailing)) {
1919 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1920 }
[email protected]a2cf65eb2010-01-18 08:20:381921}
1922
[email protected]7e0831b2010-02-01 08:45:151923void TabContents::OnPageTranslated(int32 page_id,
1924 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161925 const std::string& translated_lang,
1926 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551927 language_state_.set_current_language(translated_lang);
1928 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161929 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151930 NotificationService::current()->Notify(
1931 NotificationType::PAGE_TRANSLATED,
1932 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161933 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151934}
1935
[email protected]dcd5b332010-08-11 08:55:181936void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561937 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241938 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561939}
1940
[email protected]8d3347f2009-07-09 22:00:211941RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321942 return view_.get();
1943}
1944
[email protected]8d3347f2009-07-09 22:00:211945RenderViewHostDelegate::RendererManagement*
1946TabContents::GetRendererManagementDelegate() {
1947 return &render_manager_;
1948}
1949
[email protected]46ba9082010-06-22 10:00:581950RenderViewHostDelegate::ContentSettings*
1951TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551952 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581953}
1954
[email protected]1f18184a2010-07-21 19:34:491955RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1956 return GetSSLHelper();
1957}
1958
[email protected]fd571bb2010-03-19 01:23:541959AutomationResourceRoutingDelegate*
1960TabContents::GetAutomationResourceRoutingDelegate() {
1961 return delegate();
1962}
1963
[email protected]ced90ae12010-02-20 02:06:161964RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1965 return bookmark_drag_;
1966}
1967
1968void TabContents::SetBookmarkDragDelegate(
1969 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1970 bookmark_drag_ = bookmark_drag;
1971}
1972
[email protected]9fb83e82010-07-02 18:24:551973TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
1974 return content_settings_delegate_.get();
1975}
1976
[email protected]93623c5d2009-12-10 21:40:321977RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461978 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511979}
1980
[email protected]57c6a652009-05-04 07:58:341981TabContents* TabContents::GetAsTabContents() {
1982 return this;
1983}
1984
[email protected]7b291f92009-08-14 05:43:531985ViewType::Type TabContents::GetRenderViewType() const {
1986 return ViewType::TAB_CONTENTS;
1987}
1988
1989int TabContents::GetBrowserWindowID() const {
1990 return controller().window_id().id();
1991}
1992
[email protected]420ae012009-04-24 05:16:321993void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061994 NotificationService::current()->Notify(
1995 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1996 Source<TabContents>(this),
1997 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321998 NavigationEntry* entry = controller_.GetActiveEntry();
1999 if (!entry)
2000 return;
2001
2002 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352003 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562004 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582005 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322006
2007 if (entry->IsViewSourceMode()) {
2008 // Put the renderer in view source mode.
2009 render_view_host->Send(
2010 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2011 }
[email protected]0666aef2009-05-13 19:48:082012
2013 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322014}
2015
2016void TabContents::RenderViewReady(RenderViewHost* rvh) {
2017 if (rvh != render_view_host()) {
2018 // Don't notify the world, since this came from a renderer in the
2019 // background.
2020 return;
2021 }
2022
2023 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302024 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232025 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302026
2027 // Restore the focus to the tab (otherwise the focus will be on the top
2028 // window).
[email protected]484ae5912010-09-29 19:16:142029 if (was_crashed && !FocusLocationBarByDefault() &&
2030 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302031 Focus();
[email protected]484ae5912010-09-29 19:16:142032 }
[email protected]420ae012009-04-24 05:16:322033}
2034
[email protected]443b80e2010-12-14 00:42:232035void TabContents::RenderViewGone(RenderViewHost* rvh,
2036 base::TerminationStatus status,
2037 int error_code) {
[email protected]420ae012009-04-24 05:16:322038 if (rvh != render_view_host()) {
2039 // The pending page's RenderViewHost is gone.
2040 return;
2041 }
2042
[email protected]2e3f4572011-03-25 19:24:472043 // Let observers know first and give them a chance to act.
2044 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
2045
[email protected]420ae012009-04-24 05:16:322046 SetIsLoading(false, NULL);
2047 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232048 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322049
[email protected]ff9efc62010-02-18 22:10:542050 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402051 while (!infobar_delegates_.empty())
2052 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542053
[email protected]8e537302009-06-10 21:19:582054 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552055 // Only do this if we're not in browser shutdown, so that TabContents
2056 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2057 // visible do not flash a sad tab page.
2058 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162059 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322060
2061 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:292062 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322063}
2064
[email protected]2e4633c2009-07-09 16:58:062065void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2066 NotificationService::current()->Notify(
2067 NotificationType::RENDER_VIEW_HOST_DELETED,
2068 Source<TabContents>(this),
2069 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482070 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062071}
2072
[email protected]420ae012009-04-24 05:16:322073void TabContents::DidNavigate(RenderViewHost* rvh,
2074 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372075 int extra_invalidate_flags = 0;
2076
2077 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352078 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372079
[email protected]420ae012009-04-24 05:16:322080 render_manager_.DidNavigateMainFrame(rvh);
2081
[email protected]20ede072009-10-06 00:28:352082 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372083 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372084 }
2085
[email protected]420ae012009-04-24 05:16:322086 // Update the site of the SiteInstance if it doesn't have one yet.
2087 if (!GetSiteInstance()->has_site())
2088 GetSiteInstance()->SetSite(params.url);
2089
2090 // Need to update MIME type here because it's referred to in
2091 // UpdateNavigationCommands() called by RendererDidNavigate() to
2092 // determine whether or not to enable the encoding menu.
2093 // It's updated only for the main frame. For a subframe,
2094 // RenderView::UpdateURL does not set params.contents_mime_type.
2095 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2096 // TODO(jungshik): Add a test for the encoding menu to avoid
2097 // regressing it again.
2098 if (PageTransition::IsMainFrame(params.transition))
2099 contents_mime_type_ = params.contents_mime_type;
2100
2101 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372102 bool did_navigate = controller_.RendererDidNavigate(
2103 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392104
[email protected]a9c0bfe2010-09-17 08:35:222105 // Send notification about committed provisional loads. This notification is
2106 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2107 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2108 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072109 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2110 // that is not recorded in the navigation history. For the purpose of
2111 // tracking navigation events, we treat this event as a sub frame navigation
2112 // event.
2113 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2114 ProvisionalLoadDetails load_details(
[email protected]b9e8ea62011-03-04 06:29:092115 is_main_frame, details.is_in_page, params.url, std::string(),
[email protected]dd0aafd2010-12-02 13:13:412116 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222117 load_details.set_transition_type(params.transition);
2118 // Whether or not a page transition was triggered by going backward or
2119 // forward in the history is only stored in the navigation controller's
2120 // entry list.
2121 if (did_navigate &&
2122 (controller_.GetActiveEntry()->transition_type() &
2123 PageTransition::FORWARD_BACK)) {
2124 load_details.set_transition_type(
2125 params.transition | PageTransition::FORWARD_BACK);
2126 }
2127 NotificationService::current()->Notify(
2128 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2129 Source<NavigationController>(&controller_),
2130 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222131 }
2132
[email protected]3e90d4a2009-07-03 17:38:392133 // Update history. Note that this needs to happen after the entry is complete,
2134 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582135 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392136 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582137 // URLs, we use a data: URL as the real value. We actually want to save the
2138 // about: URL to the history db and keep the data: URL hidden. This is what
2139 // the TabContents' URL getter does.
2140 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2141 CreateHistoryAddPageArgs(GetURL(), details, params));
2142 if (!delegate() ||
2143 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2144 details.type)) {
2145 UpdateHistoryForNavigation(add_page_args);
2146 }
[email protected]3e90d4a2009-07-03 17:38:392147 }
2148
[email protected]76543b92009-08-31 17:27:452149 if (!did_navigate)
2150 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322151
2152 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2153 // for the appropriate notification (best) or you can add it to
2154 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2155 // necessary, please).
2156
2157 // Run post-commit tasks.
2158 if (details.is_main_frame)
2159 DidNavigateMainFramePostCommit(details, params);
2160 DidNavigateAnyFramePostCommit(rvh, details, params);
2161}
2162
2163void TabContents::UpdateState(RenderViewHost* rvh,
2164 int32 page_id,
2165 const std::string& state) {
2166 DCHECK(rvh == render_view_host());
2167
2168 // We must be prepared to handle state updates for any page, these occur
2169 // when the user is scrolling and entering form data, as well as when we're
2170 // leaving a page, in which case our state may have already been moved to
2171 // the next page. The navigation controller will look up the appropriate
2172 // NavigationEntry and update it when it is notified via the delegate.
2173
2174 int entry_index = controller_.GetEntryIndexWithPageID(
2175 GetSiteInstance(), page_id);
2176 if (entry_index < 0)
2177 return;
2178 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2179
2180 if (state == entry->content_state())
2181 return; // Nothing to update.
2182 entry->set_content_state(state);
2183 controller_.NotifyEntryChanged(entry, entry_index);
2184}
2185
2186void TabContents::UpdateTitle(RenderViewHost* rvh,
2187 int32 page_id, const std::wstring& title) {
2188 // If we have a title, that's a pretty good indication that we've started
2189 // getting useful data.
2190 SetNotWaitingForResponse();
2191
2192 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482193 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582194 page_id);
[email protected]420ae012009-04-24 05:16:322195 if (!entry || !UpdateTitleForEntry(entry, title))
2196 return;
2197
2198 // Broadcast notifications when the UI should be updated.
2199 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032200 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322201}
2202
[email protected]420ae012009-04-24 05:16:322203void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402204 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322205 set_encoding(encoding);
2206}
2207
2208void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2209 if (delegate())
2210 delegate()->UpdateTargetURL(this, url);
2211}
2212
[email protected]c4e98902010-06-01 10:20:142213void TabContents::UpdateInspectorSetting(const std::string& key,
2214 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052215 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082216}
2217
[email protected]45aafc92010-06-07 14:18:532218void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052219 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532220}
2221
[email protected]420ae012009-04-24 05:16:322222void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292223 // The UI may be in an event-tracking loop, such as between the
2224 // mouse-down and mouse-up in text selection or a button click.
2225 // Defer the close until after tracking is complete, so that we
2226 // don't free objects out from under the UI.
2227 // TODO(shess): This could probably be integrated with the
2228 // IsDoingDrag() test below. Punting for now because I need more
2229 // research to understand how this impacts platforms other than Mac.
2230 // TODO(shess): This could get more fine-grained. For instance,
2231 // closing a tab in another window while selecting text in the
2232 // current window's Omnibox should be just fine.
2233 if (view()->IsEventTracking()) {
2234 view()->CloseTabAfterEventTracking();
2235 return;
2236 }
2237
[email protected]24a4d1062009-07-10 23:10:422238 // If we close the tab while we're in the middle of a drag, we'll crash.
2239 // Instead, cancel the drag and close it as soon as the drag ends.
2240 if (view()->IsDoingDrag()) {
2241 view()->CancelDragAndCloseTab();
2242 return;
2243 }
2244
[email protected]420ae012009-04-24 05:16:322245 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2246 if (delegate() && rvh == render_view_host())
2247 delegate()->CloseContents(this);
2248}
2249
2250void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2251 if (delegate() && delegate()->IsPopup(this))
2252 delegate()->MoveContents(this, new_bounds);
2253}
2254
[email protected]7ab1e7d62009-10-14 23:32:012255void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322256 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492257
[email protected]c40d6232011-03-25 00:16:212258 if (delegate() && content_restrictions_) {
2259 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:212260 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002261 }
[email protected]3c9e1872010-11-18 16:17:492262
2263 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172264 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322265}
2266
[email protected]7ab1e7d62009-10-14 23:32:012267void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322268 scoped_ptr<LoadNotificationDetails> details;
2269
2270 NavigationEntry* entry = controller_.GetActiveEntry();
2271 // An entry may not exist for a stop when loading an initial blank page or
2272 // if an iframe injected by script into a blank page finishes loading.
2273 if (entry) {
[email protected]420ae012009-04-24 05:16:322274 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2275
2276 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542277 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322278 entry->transition_type(),
2279 elapsed,
2280 &controller_,
2281 controller_.GetCurrentEntryIndex()));
2282 }
2283
[email protected]420ae012009-04-24 05:16:322284 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492285
2286 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172287 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322288}
2289
[email protected]1a3c3cb2010-12-16 21:03:402290void TabContents::DidChangeLoadProgress(double progress) {
2291 if (delegate())
2292 delegate()->LoadProgressChanged(progress);
2293}
2294
[email protected]25497492010-09-11 15:15:082295void TabContents::DocumentOnLoadCompletedInMainFrame(
2296 RenderViewHost* render_view_host,
2297 int32 page_id) {
2298 NotificationService::current()->Notify(
2299 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2300 Source<TabContents>(this),
2301 Details<int>(&page_id));
2302}
2303
[email protected]420ae012009-04-24 05:16:322304void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2305 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582306 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352307 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322308 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2309 // generated suggestions).
2310 //
[email protected]e0112912011-02-02 22:54:352311 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162312 // want web sites to see a referrer of "chrome://blah" (and some
2313 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322314 // send to the site), so we send no referrer.
2315 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582316 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322317 } else {
2318 OpenURL(url, referrer, disposition, PageTransition::LINK);
2319 }
2320}
2321
[email protected]1ee614862009-07-06 20:29:182322void TabContents::DomOperationResponse(const std::string& json_string,
2323 int automation_id) {
2324}
2325
[email protected]badcca352011-02-12 01:08:082326void TabContents::ProcessWebUIMessage(
[email protected]44c49c92011-03-28 16:17:232327 const ExtensionHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582328 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442329 // This can happen if someone uses window.open() to open an extension URL
2330 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562331 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322332 return;
2333 }
[email protected]badcca352011-02-12 01:08:082334 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322335}
2336
2337void TabContents::ProcessExternalHostMessage(const std::string& message,
2338 const std::string& origin,
2339 const std::string& target) {
2340 if (delegate())
2341 delegate()->ForwardMessageToExternalHost(message, origin, target);
2342}
2343
[email protected]420ae012009-04-24 05:16:322344void TabContents::RunJavaScriptMessage(
2345 const std::wstring& message,
2346 const std::wstring& default_prompt,
2347 const GURL& frame_url,
2348 const int flags,
2349 IPC::Message* reply_msg,
2350 bool* did_suppress_message) {
2351 // Suppress javascript messages when requested and when inside a constrained
2352 // popup window (because that activates them and breaks them out of the
2353 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552354 // Also suppress messages when showing an interstitial. The interstitial is
2355 // shown over the previous page, we don't want the hidden page dialogs to
2356 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502357 bool suppress_this_message =
2358 suppress_javascript_messages_ ||
2359 showing_interstitial_page() ||
2360 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322361 if (delegate())
2362 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312363 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322364
2365 *did_suppress_message = suppress_this_message;
2366
2367 if (!suppress_this_message) {
2368 base::TimeDelta time_since_last_message(
2369 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2370 bool show_suppress_checkbox = false;
2371 // Show a checkbox offering to suppress further messages if this message is
2372 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2373 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152374 base::TimeDelta::FromMilliseconds(
2375 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322376 show_suppress_checkbox = true;
2377
[email protected]d6ad7442010-09-05 19:06:522378 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2379 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322380 } else {
2381 // If we are suppressing messages, just reply as is if the user immediately
2382 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542383 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322384 }
2385}
2386
2387void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2388 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292389 if (delegate())
2390 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502391 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2392 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2393 std::wstring());
2394 return;
2395 }
[email protected]7ab1e7d62009-10-14 23:32:012396 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222397 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322398}
2399
[email protected]420ae012009-04-24 05:16:322400GURL TabContents::GetAlternateErrorPageURL() const {
2401 GURL url;
2402 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2403 if (profile()->IsOffTheRecord())
2404 return url;
2405
2406 PrefService* prefs = profile()->GetPrefs();
2407 DCHECK(prefs);
2408 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152409 url = google_util::AppendGoogleLocaleParam(
2410 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322411 url = google_util::AppendGoogleTLDParam(url);
2412 }
2413 return url;
2414}
2415
2416WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062417 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582418 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082419 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582420 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082421
[email protected]9beff752010-09-22 19:35:432422 // Force accelerated compositing and 2d canvas off for chrome: and
2423 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432424 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2425 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082426 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432427 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082428 }
2429
[email protected]39553442010-09-09 00:01:552430#if defined(OS_MACOSX)
2431 // Disable accelerated compositing if IOSurface's are not supported,
2432 // as is the case in 10.5.
2433 if (!IOSurfaceSupport::Initialize())
2434 web_prefs.accelerated_compositing_enabled = false;
2435#endif
2436
[email protected]447021c2010-09-08 21:29:082437 return web_prefs;
[email protected]420ae012009-04-24 05:16:322438}
2439
[email protected]7d472472011-01-22 01:30:252440void TabContents::OnUserGesture() {
2441 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2442 DownloadRequestLimiter* limiter =
2443 g_browser_process->download_request_limiter();
2444 if (limiter)
2445 limiter->OnUserGesture(this);
2446 ExternalProtocolHandler::PermitLaunchUrl();
2447}
2448
[email protected]fa1cf0b82010-01-15 21:49:442449void TabContents::OnIgnoredUIEvent() {
2450 if (constrained_window_count()) {
2451 ConstrainedWindow* window = *constrained_window_begin();
2452 window->FocusConstrainedWindow();
2453 }
2454}
2455
[email protected]420ae012009-04-24 05:16:322456void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2457 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342458 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322459 // delivered to a pending RenderViewHost. We must first run the onunload
2460 // handler of the old RenderViewHost before we can allow it to proceed.
2461 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2462 new_request_id);
2463}
2464
[email protected]420ae012009-04-24 05:16:322465void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2466 bool is_during_unload) {
2467 if (is_during_unload) {
2468 // Hang occurred while firing the beforeunload/unload handler.
2469 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112470 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322471
2472 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2473 return;
2474
2475 // If the tab hangs in the beforeunload/unload handler there's really
2476 // nothing we can do to recover. Pretend the unload listeners have
2477 // all fired and close the tab. If the hang is in the beforeunload handler
2478 // then the user will not have the option of cancelling the close.
2479 Close(rvh);
2480 return;
2481 }
2482
[email protected]61b50092011-02-03 18:02:192483 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2484 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292485 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192486 }
[email protected]420ae012009-04-24 05:16:322487}
2488
2489void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292490 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322491}
2492
2493void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562494 net::LoadState load_state,
2495 uint64 upload_position,
2496 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322497 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562498 upload_position_ = upload_position;
2499 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292500 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192501 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292502 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422503 load_state_host_ = WideToUTF16Hack(
2504 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322505 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2506 SetNotWaitingForResponse();
2507 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502508 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322509}
2510
[email protected]1ee614862009-07-06 20:29:182511bool TabContents::IsExternalTabContainer() const {
2512 if (!delegate())
2513 return false;
2514
2515 return delegate()->IsExternalTabContainer();
2516}
2517
[email protected]1ee614862009-07-06 20:29:182518void TabContents::DidInsertCSS() {
2519 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322520}
2521
[email protected]546ae4e02010-12-08 14:57:192522void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352523 NotificationService::current()->Notify(
2524 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212525 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192526 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352527}
2528
[email protected]b75b8292010-10-01 07:28:252529void TabContents::UpdateZoomLimits(int minimum_percent,
2530 int maximum_percent,
2531 bool remember) {
2532 minimum_zoom_percent_ = minimum_percent;
2533 maximum_zoom_percent_ = maximum_percent;
2534 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382535}
2536
[email protected]7d472472011-01-22 01:30:252537void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442538 if (delegate())
2539 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252540}
2541
[email protected]420ae012009-04-24 05:16:322542void TabContents::BeforeUnloadFiredFromRenderManager(
2543 bool proceed,
2544 bool* proceed_to_fire_unload) {
2545 if (delegate())
2546 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2547}
2548
[email protected]3a3d47472010-07-15 21:03:542549void TabContents::DidStartLoadingFromRenderManager(
2550 RenderViewHost* render_view_host) {
2551 DidStartLoading();
2552}
2553
2554void TabContents::RenderViewGoneFromRenderManager(
2555 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232556 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2557 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542558}
2559
[email protected]420ae012009-04-24 05:16:322560void TabContents::UpdateRenderViewSizeForRenderManager() {
2561 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262562 gfx::Size size = view_->GetContainerSize();
2563 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2564 // here during container initialization and normal window size will be set
2565 // later. In case of tab duplication this resizing to 0x0 prevents setting
2566 // normal size later so just ignore it.
2567 if (!size.IsEmpty())
2568 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]3a3d47472010-07-15 21:03:542571void TabContents::NotifySwappedFromRenderManager() {
2572 NotifySwapped();
2573}
2574
2575NavigationController& TabContents::GetControllerForRenderManager() {
2576 return controller();
2577}
2578
[email protected]d0980792011-02-13 19:41:402579WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562580 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322581}
2582
2583NavigationEntry*
2584TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2585 return controller_.GetLastCommittedEntry();
2586}
2587
2588bool TabContents::CreateRenderViewForRenderManager(
2589 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322590 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522591
[email protected]674b3822010-08-04 04:02:512592 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322593 return false;
2594
2595 // Now that the RenderView has been created, we need to tell it its size.
2596 rwh_view->SetSize(view_->GetContainerSize());
2597
2598 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2599 render_view_host);
2600 return true;
2601}
2602
2603void TabContents::Observe(NotificationType type,
2604 const NotificationSource& source,
2605 const NotificationDetails& details) {
2606 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322607 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512608 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322609 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2610 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2611 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532612 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2613 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322614 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172615 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2616 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322617 } else {
2618 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2619 }
2620 break;
2621 }
2622 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2623 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2624 break;
2625
2626 case NotificationType::NAV_ENTRY_COMMITTED: {
2627 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2628
2629 NavigationController::LoadCommittedDetails& committed_details =
2630 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2631 ExpireInfoBars(committed_details);
2632 break;
2633 }
2634
[email protected]d3ba77272009-09-03 00:06:092635#if defined(OS_LINUX)
2636 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542637 renderer_preferences_util::UpdateFromSystemSettings(
2638 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092639 render_view_host()->SyncRendererPrefs();
2640 break;
2641 }
2642#endif
2643
[email protected]6c32ce72010-03-08 05:18:062644 case NotificationType::USER_STYLE_SHEET_UPDATED:
2645 UpdateWebPreferences();
2646 break;
2647
[email protected]79580c62010-02-02 02:36:252648 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452649 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252650 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492651 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292652 if (entry)
[email protected]da0c8e92010-02-09 23:25:492653 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292654 if (settings_details.ptr()->update_all() ||
2655 settings_details.ptr()->pattern().Matches(entry_url)) {
2656 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232657 profile()->GetHostContentSettingsMap()->
2658 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252659 }
2660 break;
2661 }
2662
[email protected]e5adff72010-06-14 18:13:062663 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572664 break;
[email protected]a888b29e62010-04-01 13:38:572665
2666 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572667 break;
[email protected]a888b29e62010-04-01 13:38:572668
[email protected]88152052010-10-01 04:05:182669 case NotificationType::GOOGLE_URL_UPDATED:
2670 UpdateAlternateErrorPageURL();
2671 break;
2672
[email protected]420ae012009-04-24 05:16:322673 default:
2674 NOTREACHED();
2675 }
2676}
[email protected]aacd7cc2009-09-02 14:51:102677
[email protected]9adb9692010-10-29 23:14:022678void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082679 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432680
[email protected]a888b29e62010-04-01 13:38:572681 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082682 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2683 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572684 extension,
[email protected]807871f2010-09-16 01:04:482685 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2686 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572687 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2688 Extension::EXTENSION_ICON_SMALLISH),
2689 ImageLoadingTracker::CACHE);
2690 } else {
[email protected]98aa0b52010-05-06 17:03:082691 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572692 }
2693}
2694
[email protected]9adb9692010-10-29 23:14:022695const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002696 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572697 if (!extensions_service)
2698 return NULL;
2699
[email protected]9adb9692010-10-29 23:14:022700 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572701 return extension ?
2702 extension : extensions_service->GetExtensionByWebExtent(url);
2703}
2704
[email protected]bd5174d2011-03-11 01:02:562705void TabContents::OnImageLoaded(SkBitmap* image,
2706 const ExtensionResource& resource,
[email protected]a888b29e62010-04-01 13:38:572707 int index) {
2708 if (image) {
[email protected]98aa0b52010-05-06 17:03:082709 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572710 NotifyNavigationStateChanged(INVALIDATE_TAB);
2711 }
2712}
2713
[email protected]beb440c2009-11-06 04:08:542714gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2715 return view_->GetTopLevelNativeWindow();
2716}
2717
2718void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2719 bool success,
2720 const std::wstring& prompt) {
2721 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2722 if (is_showing_before_unload_dialog_ && !success) {
2723 // If a beforeunload dialog is canceled, we need to stop the throbber from
2724 // spinning, since we forced it to start spinning in Navigate.
2725 DidStopLoading();
2726
2727 tab_close_start_time_ = base::TimeTicks();
2728 }
2729 is_showing_before_unload_dialog_ = false;
2730 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2731}
2732
2733void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2734 set_suppress_javascript_messages(suppress_message_boxes);
2735}
2736
[email protected]3a3d47472010-07-15 21:03:542737TabContents* TabContents::AsTabContents() {
2738 return this;
2739}
2740
2741ExtensionHost* TabContents::AsExtensionHost() {
2742 return NULL;
2743}
2744
[email protected]41fc0322009-09-04 22:23:402745void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102746 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2747}
[email protected]f45d2a72010-03-08 23:28:352748
2749void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2750 app_icon_ = app_icon;
2751 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2752}
[email protected]33f74972010-12-08 16:40:362753
2754void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2755 render_manager_.SwapInRenderViewHost(rvh);
2756}
2757
2758void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2759 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2760 rwh_view->SetSize(view()->GetContainerSize());
2761}
[email protected]e7d50892011-01-19 21:47:382762
[email protected]232a5812011-03-04 22:42:082763void TabContents::OnOnlineStateChanged(bool online) {
2764 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2765 render_view_host()->routing_id(), online));
2766}