blob: d1866ab4711edcd5fa8834acfc084ad2cc8053cc [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]36fb2c7c2011-04-04 15:49:0810#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1812#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5413#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]c65e2f152010-10-14 15:30:4017#include "chrome/browser/blocked_content_container.h"
[email protected]96d185d2009-04-24 03:28:5418#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5519#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1020#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4521#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3322#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5423#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1424#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2725#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3226#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0227#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0129#include "chrome/browser/download/download_request_limiter.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]36fb2c7c2011-04-04 15:49:0843#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3344#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5445#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3246#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1347#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1748#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2949#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4950#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5251#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1652#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3553#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2954#include "chrome/browser/ui/browser_dialogs.h"
[email protected]54ec6472010-04-09 19:39:5855#include "chrome/common/bindings_policy.h"
[email protected]1698f612011-03-11 11:28:1556#include "chrome/common/chrome_constants.h"
[email protected]35f7d212009-04-29 21:19:2757#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2158#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4959#include "chrome/common/extensions/extension.h"
[email protected]44c49c92011-03-28 16:17:2360#include "chrome/common/extensions/extension_messages.h"
[email protected]12802702010-07-09 19:43:0961#include "chrome/common/extensions/url_pattern.h"
initial.commit09911bf2008-07-26 23:55:2962#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3263#include "chrome/common/render_messages.h"
[email protected]96d185d2009-04-24 03:28:5464#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5065#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5666#include "content/browser/content_browser_client.h"
[email protected]567812d2011-02-24 17:40:5067#include "content/browser/host_zoom_map.h"
68#include "content/browser/in_process_webkit/session_storage_namespace.h"
69#include "content/browser/renderer_host/render_process_host.h"
70#include "content/browser/renderer_host/render_view_host.h"
71#include "content/browser/renderer_host/render_widget_host_view.h"
72#include "content/browser/renderer_host/resource_request_details.h"
73#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4474#include "content/browser/tab_contents/interstitial_page.h"
75#include "content/browser/tab_contents/navigation_entry.h"
76#include "content/browser/tab_contents/provisional_load_details.h"
77#include "content/browser/tab_contents/tab_contents_delegate.h"
78#include "content/browser/tab_contents/tab_contents_observer.h"
79#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]1fd1a502011-03-30 16:55:5680#include "content/browser/webui/web_ui_factory.h"
81#include "content/common/content_client.h"
[email protected]4dd57932011-03-17 06:06:1282#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3283#include "content/common/notification_service.h"
[email protected]2c5569662011-03-22 20:45:0284#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2985#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3286#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3487#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4689#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3890#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0391#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3192#include "webkit/glue/webpreferences.h"
93
94#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1295#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3196#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]420ae012009-04-24 05:16:3298// Cross-Site Navigations
99//
100// If a TabContents is told to navigate to a different web site (as determined
101// by SiteInstance), it will replace its current RenderViewHost with a new
102// RenderViewHost dedicated to the new SiteInstance. This works as follows:
103//
104// - Navigate determines whether the destination is cross-site, and if so,
105// it creates a pending_render_view_host_ and moves into the PENDING
106// RendererState.
107// - The pending RVH is "suspended," so that no navigation messages are sent to
108// its renderer until the onbeforeunload JavaScript handler has a chance to
109// run in the current RVH.
110// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
111// that it has a pending cross-site request. ResourceDispatcherHost will
112// check for this when the response arrives.
113// - The current RVH runs its onbeforeunload handler. If it returns false, we
114// cancel all the pending logic and go back to NORMAL. Otherwise we allow
115// the pending RVH to send the navigation request to its renderer.
116// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
117// checks CrossSiteRequestManager to see that the RVH responsible has a
118// pending cross-site request, and then installs a CrossSiteEventHandler.
119// - When RDH receives a response, the BufferedEventHandler determines whether
120// it is a download. If so, it sends a message to the new renderer causing
121// it to cancel the request, and the download proceeds in the download
122// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34123// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32124// doesn't affect any functionality.
125// - After RDH receives a response and determines that it is safe and not a
126// download, it pauses the response to first run the old page's onunload
127// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34128// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32129// to the current RVH.
130// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
131// the ResourceDispatcherHost, who unpauses the response. Data is then sent
132// to the pending RVH.
133// - The pending renderer sends a FrameNavigate message that invokes the
134// DidNavigate method. This replaces the current RVH with the
135// pending RVH and goes back to the NORMAL RendererState.
136
137namespace {
138
139// Amount of time we wait between when a key event is received and the renderer
140// is queried for its state and pushed to the NavigationEntry.
141const int kQueryStateDelay = 5000;
142
[email protected]6ebdc9b2010-09-27 16:55:57143const int kSyncWaitDelay = 40;
144
[email protected]420ae012009-04-24 05:16:32145// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51146const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32147 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17148 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32149 prefs::kWebKitJavaEnabled,
150 prefs::kWebKitJavascriptEnabled,
151 prefs::kWebKitLoadsImagesAutomatically,
152 prefs::kWebKitPluginsEnabled,
153 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10154 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32155 prefs::kWebKitSerifFontFamily,
156 prefs::kWebKitSansSerifFontFamily,
157 prefs::kWebKitFixedFontFamily,
158 prefs::kWebKitDefaultFontSize,
159 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13160 prefs::kWebKitMinimumFontSize,
161 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36162 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32163 prefs::kDefaultCharset
[email protected]420ae012009-04-24 05:16:32164};
165
166const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
167
[email protected]420ae012009-04-24 05:16:32168#if defined(OS_WIN)
169
170BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
171 // Note: erase is required to properly paint some widgets borders. This can
172 // be seen with textfields.
173 InvalidateRect(hwnd, NULL, TRUE);
174 return TRUE;
175}
176#endif
177
[email protected]2c5569662011-03-22 20:45:02178ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16179 Profile* profile, const NavigationEntry& entry,
180 NavigationController::ReloadType reload_type) {
181 switch (reload_type) {
182 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02183 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16184 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16186 case NavigationController::NO_RELOAD:
187 break; // Fall through to rest of function.
188 }
[email protected]5e369672009-11-03 23:48:30189
190 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
191 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30193
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30195}
196
[email protected]876bc832010-09-07 16:29:54197void MakeNavigateParams(const NavigationEntry& entry,
198 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16199 NavigationController::ReloadType reload_type,
200 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34201 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54202 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00203 params->current_history_list_offset = controller.last_committed_entry_index();
204 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34205 params->url = entry.url();
206 params->referrer = entry.referrer();
207 params->transition = entry.transition_type();
208 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00209 params->navigation_type =
210 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34211 params->request_time = base::Time::Now();
212}
213
[email protected]420ae012009-04-24 05:16:32214} // namespace
215
[email protected]f4f50ef2011-01-21 19:01:19216
217// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32218
[email protected]420ae012009-04-24 05:16:32219TabContents::TabContents(Profile* profile,
220 SiteInstance* site_instance,
221 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07222 const TabContents* base_tab_contents,
223 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42224 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07225 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
226 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13227 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22228 TabContentsView::Create(this))),
229 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06230 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34231 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23232 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
233 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34234 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34235 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57236 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56237 upload_size_(0),
238 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57239 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40240 blocked_contents_(NULL),
241 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49242 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47243 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57244 capturing_contents_(false),
245 is_being_destroyed_(false),
246 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57247#if defined(OS_WIN)
248 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
249#endif
[email protected]c2e74fe82009-09-03 17:57:44250 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01251 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56252 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16253 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38254 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25255 minimum_zoom_percent_(
256 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
257 maximum_zoom_percent_(
258 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00259 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59260 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54261 renderer_preferences_util::UpdateFromSystemSettings(
262 &renderer_preferences_, profile);
263
[email protected]9fb83e82010-07-02 18:24:55264 content_settings_delegate_.reset(
265 new TabSpecificContentSettings(this, profile));
266
[email protected]12636df2009-09-28 22:32:21267 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32268
[email protected]34ac70502009-09-25 17:07:23269 // We have the initial size of the view be based on the size of the passed in
270 // tab contents (normally a tab from the same window).
271 view_->CreateView(base_tab_contents ?
272 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32273
274 // Register for notifications about all interested prefs change.
275 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28276 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32277 if (prefs) {
278 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28279 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32280 }
281
[email protected]420ae012009-04-24 05:16:32282 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
283 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09284#if defined(OS_LINUX)
285 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
286 NotificationService::AllSources());
287#endif
[email protected]420ae012009-04-24 05:16:32288
[email protected]6c32ce72010-03-08 05:18:06289 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
290 NotificationService::AllSources());
291
[email protected]79580c62010-02-02 02:36:25292 // Register for notifications about content setting changes.
293 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
294 NotificationService::AllSources());
295
[email protected]a888b29e62010-04-01 13:38:57296 // Listen for extension changes so we can update extension_for_current_page_.
297 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
298 NotificationService::AllSources());
299 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
300 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57301
[email protected]969182a2011-03-03 14:53:23302 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18303 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
304 NotificationService::AllSources());
305
[email protected]c8865482009-07-23 20:40:10306 // Set-up the showing of the omnibox search infobar if applicable.
307 if (OmniboxSearchHint::IsEnabled(profile))
308 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53309
[email protected]b5a1d11c2011-02-17 03:09:42310 // Can only add observers after render_manager_.Init() is called, since that's
311 // what sets up the render_view_host which TabContentObserver's constructor
312 // uses to get the routing_id.
313 AddObservers();
[email protected]332af7732009-03-11 13:21:35314}
initial.commit09911bf2008-07-26 23:55:29315
316TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32317 is_being_destroyed_ = true;
318
[email protected]bfe4c1582009-10-02 18:11:09319 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32320 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28321 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32322
[email protected]420ae012009-04-24 05:16:32323 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29324 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32325
[email protected]420ae012009-04-24 05:16:32326 // First cleanly close all child windows.
327 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
328 // some of these to close. CloseWindows is async, so it might get called
329 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49330 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32331
[email protected]c65e2f152010-10-14 15:30:40332 // Close all blocked contents.
333 if (blocked_contents_)
334 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13335
[email protected]420ae012009-04-24 05:16:32336 // Notify any observer that have a reference on this tab contents.
337 NotificationService::current()->Notify(
338 NotificationType::TAB_CONTENTS_DESTROYED,
339 Source<TabContents>(this),
340 NotificationService::NoDetails());
341
[email protected]1e5e74f2009-05-27 20:55:12342 // Notify any lasting InfobarDelegates that have not yet been removed that
343 // whatever infobar they were handling in this TabContents has closed,
344 // because the TabContents is going away entirely.
345 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
346 // notification may trigger infobars calls that access their delegate. (and
347 // some implementations of InfoBarDelegate do delete themselves on
348 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40349 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12350 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
351 delegate->InfoBarClosed();
352 }
353 infobar_delegates_.clear();
354
[email protected]420ae012009-04-24 05:16:32355 // TODO(brettw) this should be moved to the view.
356#if defined(OS_WIN)
357 // If we still have a window handle, destroy it. GetNativeView can return
358 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42359 if (GetNativeView()) {
360 RenderViewHost* host = render_view_host();
361 if (host && host->view()) {
362 host->view()->WillWmDestroy();
363 }
[email protected]420ae012009-04-24 05:16:32364 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42365 }
[email protected]420ae012009-04-24 05:16:32366#endif
[email protected]7ab1e7d62009-10-14 23:32:01367
368 // OnCloseStarted isn't called in unit tests.
369 if (!tab_close_start_time_.is_null()) {
370 UMA_HISTOGRAM_TIMES("Tab.Close",
371 base::TimeTicks::Now() - tab_close_start_time_);
372 }
[email protected]b5a1d11c2011-02-17 03:09:42373
[email protected]07d490bc2011-03-07 17:05:26374 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08375
376 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42377}
378
379void TabContents::AddObservers() {
[email protected]16be5c32011-03-15 17:52:03380 favicon_helper_.reset(new FaviconHelper(this));
[email protected]b5a1d11c2011-02-17 03:09:42381 desktop_notification_handler_.reset(
382 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
383 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13384 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
385 this));
[email protected]232a5812011-03-04 22:42:08386 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29387}
388
[email protected]724159a2010-12-30 01:11:18389bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17390 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
391 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10392 while ((observer = it.GetNext()) != NULL)
393 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53394 return true;
[email protected]403415a2011-01-10 18:57:53395
[email protected]724159a2010-12-30 01:11:18396 bool handled = true;
397 bool message_is_ok = true;
398 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
399 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
400 OnDidStartProvisionalLoadForFrame)
401 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
402 OnDidRedirectProvisionalLoad)
403 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
404 OnDidFailProvisionalLoadWithError)
405 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
406 OnDidLoadResourceFromMemoryCache)
407 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
408 OnDidDisplayInsecureContent)
409 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
410 OnDidRunInsecureContent)
411 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
412 OnDocumentLoadedInFrame)
413 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17414 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
415 OnUpdateContentRestrictions)
416 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
417 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25418 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25419 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
420 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
[email protected]724159a2010-12-30 01:11:18421 IPC_MESSAGE_UNHANDLED(handled = false)
422 IPC_END_MESSAGE_MAP_EX()
423
424 if (!message_is_ok) {
425 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
426 GetRenderProcessHost()->ReceivedBadMessage();
427 }
428
429 return handled;
430}
431
[email protected]13367f72009-07-08 16:39:02432// Returns true if contains content rendered by an extension.
433bool TabContents::HostsExtension() const {
434 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34435}
436
[email protected]1f18184a2010-07-21 19:34:49437TabContentsSSLHelper* TabContents::GetSSLHelper() {
438 if (ssl_helper_.get() == NULL)
439 ssl_helper_.reset(new TabContentsSSLHelper(this));
440 return ssl_helper_.get();
441}
442
[email protected]8cb5d5b2010-02-09 11:36:16443RenderProcessHost* TabContents::GetRenderProcessHost() const {
444 return render_manager_.current_host()->process();
445}
446
[email protected]d5f942ba2008-09-26 19:30:34447const GURL& TabContents::GetURL() const {
448 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57449 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54450 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34451}
452
[email protected]96d185d2009-04-24 03:28:54453const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55454 // Transient entries take precedence. They are used for interstitial pages
455 // that are shown on top of existing pages.
456 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23457 if (entry) {
458 return entry->GetTitleForDisplay(profile()->GetPrefs()->
459 GetString(prefs::kAcceptLanguages));
460 }
[email protected]7ade2732011-02-10 00:13:58461 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
462 render_manager_.pending_web_ui() : render_manager_.web_ui();
463 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54464 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55465 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54466 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35467 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58468 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54469 if (!title.empty())
470 return title;
471 }
472 }
473
474 // We use the title for the last committed entry rather than a pending
475 // navigation entry. For example, when the user types in a URL, we want to
476 // keep the old page's title until the new load has committed and we get a new
477 // title.
[email protected]96d185d2009-04-24 03:28:54478 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23479 if (entry) {
480 return entry->GetTitleForDisplay(profile()->GetPrefs()->
481 GetString(prefs::kAcceptLanguages));
482 }
[email protected]96d185d2009-04-24 03:28:54483 return EmptyString16();
484}
485
[email protected]d5f942ba2008-09-26 19:30:34486int32 TabContents::GetMaxPageID() {
487 if (GetSiteInstance())
488 return GetSiteInstance()->max_page_id();
489 else
490 return max_page_id_;
491}
492
493void TabContents::UpdateMaxPageID(int32 page_id) {
494 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34495 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34496 // testing.
497 if (GetSiteInstance())
498 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16499 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34500}
501
[email protected]96d185d2009-04-24 03:28:54502SiteInstance* TabContents::GetSiteInstance() const {
503 return render_manager_.current_host()->site_instance();
504}
505
[email protected]96d185d2009-04-24 03:28:54506bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15507 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54508 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15509 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01510 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54511 return true;
[email protected]8ab24cc2009-11-13 20:56:15512 }
[email protected]83e3895b2009-06-11 00:07:16513
[email protected]2b9a06402011-02-16 04:57:10514 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56515 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10516 return true;
517
[email protected]d0980792011-02-13 19:41:40518 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58519 if (web_ui)
520 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54521 return true;
522}
523
[email protected]9b488bda2011-03-15 14:42:27524SkBitmap TabContents::GetFavicon() const {
[email protected]d5f942ba2008-09-26 19:30:34525 // Like GetTitle(), we also want to use the favicon for the last committed
526 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57527 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47528 if (entry)
529 return entry->favicon().bitmap();
530
[email protected]ce3fa3c2009-04-20 19:55:57531 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34532 if (entry)
533 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34534 return SkBitmap();
535}
536
[email protected]d8e74e82011-03-15 19:38:48537bool TabContents::FaviconIsValid() const {
[email protected]0b303cc2009-09-28 22:35:15538 NavigationEntry* entry = controller_.GetTransientEntry();
539 if (entry)
540 return entry->favicon().is_valid();
541
542 entry = controller_.GetLastCommittedEntry();
543 if (entry)
544 return entry->favicon().is_valid();
545
546 return false;
547}
548
[email protected]d8e74e82011-03-15 19:38:48549bool TabContents::ShouldDisplayFavicon() {
[email protected]96d185d2009-04-24 03:28:54550 // Always display a throbber during pending loads.
551 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
552 return true;
553
[email protected]d0980792011-02-13 19:41:40554 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58555 if (web_ui)
556 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54557 return true;
558}
559
[email protected]585b30362011-01-28 02:30:17560void TabContents::AddObserver(TabContentsObserver* observer) {
561 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49562}
563
[email protected]585b30362011-01-28 02:30:17564void TabContents::RemoveObserver(TabContentsObserver* observer) {
565 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49566}
567
[email protected]443b80e2010-12-14 00:42:23568void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
569 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34570 return;
571
[email protected]443b80e2010-12-14 00:42:23572 crashed_status_ = status;
573 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50574 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34575}
576
[email protected]d5f942ba2008-09-26 19:30:34577void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
578 if (delegate_)
579 delegate_->NavigationStateChanged(this, changed_flags);
580}
581
[email protected]96d185d2009-04-24 03:28:54582void TabContents::DidBecomeSelected() {
583 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16584 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
585 if (rwhv) {
586 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43587#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16588 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43589#endif
590 }
[email protected]96d185d2009-04-24 03:28:54591
[email protected]8cb5d5b2010-02-09 11:36:16592 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11593 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54594}
595
596void TabContents::WasHidden() {
597 if (!capturing_contents()) {
598 // |render_view_host()| can be NULL if the user middle clicks a link to open
599 // a tab in then background, then closes the tab before selecting it. This
600 // is because closing the tab calls TabContents::Destroy(), which removes
601 // the |render_view_host()|; then when we actually destroy the window,
602 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16603 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
604 if (rwhv)
605 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54606 }
607
608 NotificationService::current()->Notify(
609 NotificationType::TAB_CONTENTS_HIDDEN,
610 Source<TabContents>(this),
611 NotificationService::NoDetails());
612}
613
[email protected]d5f942ba2008-09-26 19:30:34614void TabContents::Activate() {
615 if (delegate_)
616 delegate_->ActivateContents(this);
617}
618
[email protected]ea42e7782010-08-23 23:58:12619void TabContents::Deactivate() {
620 if (delegate_)
621 delegate_->DeactivateContents(this);
622}
623
[email protected]96d185d2009-04-24 03:28:54624void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16625 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
626 if (rwhv)
627 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54628}
629
630void TabContents::HideContents() {
631 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
632 // our superclass HideContents(), because some callers want to be very picky
633 // about the order in which these get called. In addition to making the code
634 // here practically impossible to understand, this also means we end up
635 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34636 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54637 WasHidden();
638}
639
[email protected]5aab5e22010-12-08 22:13:29640bool TabContents::NeedToFireBeforeUnload() {
641 // TODO(creis): Should we fire even for interstitial pages?
642 return notify_disconnection() &&
643 !showing_interstitial_page() &&
644 !render_view_host()->SuddenTerminationAllowed();
645}
646
[email protected]c0588052008-10-27 23:01:50647void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34648 WindowOpenDisposition disposition,
649 PageTransition::Type transition) {
650 if (delegate_)
[email protected]c0588052008-10-27 23:01:50651 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34652}
653
[email protected]1ccb3568d2010-02-19 10:51:16654bool TabContents::NavigateToPendingEntry(
655 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54656 return NavigateToEntry(*controller_.pending_entry(), reload_type);
657}
[email protected]96d185d2009-04-24 03:28:54658
[email protected]876bc832010-09-07 16:29:54659bool TabContents::NavigateToEntry(
660 const NavigationEntry& entry,
661 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54662 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
663 if (!dest_render_view_host)
664 return false; // Unable to create the desired render view host.
665
[email protected]770dd8b2010-05-24 18:11:39666 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
667 dest_render_view_host->EnablePreferredSizeChangedMode(
668 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
669 }
[email protected]9fb325e2010-05-06 18:23:24670
[email protected]80a8fad2011-01-29 04:02:38671 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07672 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58673 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56674 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
675 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
676 entry.url());
[email protected]c09163a2011-02-15 00:05:55677 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
678 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58679
[email protected]96d185d2009-04-24 03:28:54680 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12681 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32682 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00683 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
684 dest_render_view_host,
685 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32686 }
[email protected]96d185d2009-04-24 03:28:54687
688 // Used for page load time metrics.
689 current_load_start_ = base::TimeTicks::Now();
690
691 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34692 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54693 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04694 if (delegate_) {
695 navigate_params.extra_headers =
696 delegate_->GetNavigationHeaders(navigate_params.url);
697 }
[email protected]056de2d2009-06-26 16:41:34698 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54699
700 if (entry.page_id() == -1) {
701 // HACK!! This code suppresses javascript: URLs from being added to
702 // session history, which is what we want to do for javascript: URLs that
703 // do not generate content. What we really need is a message from the
704 // renderer telling us that a new page was not created. The same message
705 // could be used for mailto: URLs and the like.
706 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
707 return false;
708 }
709
[email protected]3c9e1872010-11-18 16:17:49710 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17711 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54712
[email protected]1ccb3568d2010-02-19 10:51:16713 if (reload_type != NavigationController::NO_RELOAD &&
714 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48715 FaviconService* favicon_service =
716 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
717 if (favicon_service)
718 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54719 }
720
[email protected]d5f942ba2008-09-26 19:30:34721 return true;
722}
723
[email protected]96d185d2009-04-24 03:28:54724void TabContents::Stop() {
725 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47726 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54727}
728
[email protected]96d185d2009-04-24 03:28:54729void TabContents::DisassociateFromPopupCount() {
730 render_view_host()->DisassociateFromPopupCount();
731}
732
733TabContents* TabContents::Clone() {
734 // We create a new SiteInstance so that the new tab won't share processes
735 // with the old one. This can be changed in the future if we need it to share
736 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32737 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54738 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07739 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54740 tc->controller().CopyStateFrom(controller_);
[email protected]96d185d2009-04-24 03:28:54741 return tc;
742}
743
[email protected]4d677202009-07-19 07:37:12744void TabContents::ShowPageInfo(const GURL& url,
745 const NavigationEntry::SSLStatus& ssl,
746 bool show_history) {
747 if (!delegate_)
748 return;
749
[email protected]bb678332009-07-21 00:15:50750 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12751}
752
[email protected]ef0d04c2010-12-15 23:34:21753void TabContents::SaveFavicon() {
754 NavigationEntry* entry = controller_.GetActiveEntry();
755 if (!entry || entry->url().is_empty())
756 return;
757
758 // Make sure the page is in history, otherwise adding the favicon does
759 // nothing.
760 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
761 Profile::IMPLICIT_ACCESS);
762 if (!history)
763 return;
764 history->AddPageNoVisitForBookmark(entry->url());
765
766 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
767 Profile::IMPLICIT_ACCESS);
768 if (!service)
769 return;
770 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
771 if (!favicon.is_valid() || favicon.url().is_empty() ||
772 favicon.bitmap().empty()) {
773 return;
774 }
775 std::vector<unsigned char> image_data;
776 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
[email protected]849ccee2011-03-16 17:05:30777 service->SetFavicon(
778 entry->url(), favicon.url(), image_data, history::FAVICON);
[email protected]ef0d04c2010-12-15 23:34:21779}
780
initial.commit09911bf2008-07-26 23:55:29781ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28782 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29783 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28784 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33785 AddConstrainedDialog(window);
786 return window;
787}
788
789void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29790 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44791
792 if (child_windows_.size() == 1) {
793 window->ShowConstrainedWindow();
794 BlockTabContent(true);
795 }
initial.commit09911bf2008-07-26 23:55:29796}
797
[email protected]fa1cf0b82010-01-15 21:49:44798void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55799 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45800 // 70% opaque grey.
801 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55802 if (rwhv)
[email protected]1b072562010-12-13 19:37:45803 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44804 render_view_host()->set_ignore_input_events(blocked);
805 if (delegate_)
806 delegate_->SetTabContentBlocked(this, blocked);
807}
808
initial.commit09911bf2008-07-26 23:55:29809void TabContents::AddNewContents(TabContents* new_contents,
810 WindowOpenDisposition disposition,
811 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29812 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40813 if (all_contents_blocked_) {
814 if (!blocked_contents_)
815 blocked_contents_ = new BlockedContentContainer(this);
816 blocked_contents_->AddTabContents(
817 new_contents, disposition, initial_pos, user_gesture);
818 return;
819 }
820
initial.commit09911bf2008-07-26 23:55:29821 if (!delegate_)
822 return;
823
[email protected]35f7d212009-04-29 21:19:27824 if ((disposition == NEW_POPUP) && !user_gesture &&
825 !CommandLine::ForCurrentProcess()->HasSwitch(
826 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22827 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31828 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29829 delegate_->GetConstrainingContents(this)->AddPopup(
830 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31831 } else {
[email protected]0aa55312008-10-17 21:53:08832 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29833 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
834 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49835 NotificationService::current()->Notify(
836 NotificationType::TAB_ADDED,
837 Source<TabContentsDelegate>(delegate_),
838 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29839 }
initial.commit09911bf2008-07-26 23:55:29840
[email protected]8cc8d492010-02-02 10:40:49841 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40842 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]96d185d2009-04-24 03:28:54845void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49846 if (is_being_destroyed_)
847 return;
[email protected]9fb83e82010-07-02 18:24:55848 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49849 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40850 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54851}
852
[email protected]5c9e97a2009-09-09 23:48:30853gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54854 return view_->GetContentNativeView();
855}
856
857gfx::NativeView TabContents::GetNativeView() const {
858 return view_->GetNativeView();
859}
860
861void TabContents::GetContainerBounds(gfx::Rect *out) const {
862 view_->GetContainerBounds(out);
863}
864
865void TabContents::Focus() {
866 view_->Focus();
867}
868
[email protected]90daadb42009-06-08 21:27:28869void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54870 if (showing_interstitial_page()) {
871 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
872 return;
873 }
[email protected]96d185d2009-04-24 03:28:54874 render_view_host()->SetInitialFocus(reverse);
875}
876
877bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40878 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58879 if (web_ui)
880 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43881 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25882 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43883 return true;
[email protected]96d185d2009-04-24 03:28:54884 return false;
885}
886
[email protected]a26dc362010-04-23 01:48:58887void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38888 if (delegate())
[email protected]a26dc362010-04-23 01:48:58889 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38890}
891
[email protected]616ed5a2008-11-21 22:27:24892void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32893 if (delegate_ && !delegate_->infobars_enabled()) {
894 delegate->InfoBarClosed();
895 return;
896 }
897
[email protected]616ed5a2008-11-21 22:27:24898 // Look through the existing InfoBarDelegates we have for a match. If we've
899 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40900 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45901 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
902 // Tell the new infobar to close so that it can clean itself up.
903 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24904 return;
[email protected]6d27a7b2009-12-18 23:25:45905 }
[email protected]616ed5a2008-11-21 22:27:24906 }
907
908 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56909 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19910 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56911 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24912
913 // Add ourselves as an observer for navigations the first time a delegate is
914 // added. We use this notification to expire InfoBars that need to expire on
915 // page transitions.
916 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56917 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57918 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24919 }
920}
921
922void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32923 if (delegate_ && !delegate_->infobars_enabled()) {
924 return;
925 }
926
[email protected]616ed5a2008-11-21 22:27:24927 std::vector<InfoBarDelegate*>::iterator it =
928 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
929 if (it != infobar_delegates_.end()) {
930 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56931 NotificationService::current()->Notify(
932 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
933 Source<TabContents>(this),
934 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24935
[email protected]f4f50ef2011-01-21 19:01:19936 infobar_delegates_.erase(it);
937 // Remove ourselves as an observer if we are tracking no more InfoBars.
938 if (infobar_delegates_.empty()) {
939 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
940 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03941 }
[email protected]616ed5a2008-11-21 22:27:24942 }
943}
[email protected]3edd9522009-03-04 22:19:41944
[email protected]f81821c2009-08-07 01:29:47945void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
946 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:32947 if (delegate_ && !delegate_->infobars_enabled()) {
948 new_delegate->InfoBarClosed();
949 return;
950 }
951
[email protected]f81821c2009-08-07 01:29:47952 std::vector<InfoBarDelegate*>::iterator it =
953 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
954 DCHECK(it != infobar_delegates_.end());
955
956 // Notify the container about the change of plans.
957 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
958 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
959 old_delegate, new_delegate));
960 NotificationService::current()->Notify(
961 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
962 Source<TabContents>(this),
963 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
964
[email protected]f4f50ef2011-01-21 19:01:19965 // Remove the old one.
966 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:47967
968 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:08969 DCHECK(find(infobar_delegates_.begin(),
970 infobar_delegates_.end(), new_delegate) ==
971 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:47972 infobar_delegates_.push_back(new_delegate);
973}
974
[email protected]20ede072009-10-06 00:28:35975bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:27976 if (showing_interstitial_page())
977 return false;
978
[email protected]c8f74942010-09-03 10:04:14979 // Do not show bookmarks bar if bookmarks aren't enabled.
980 if (!browser_defaults::bookmarks_enabled)
981 return false;
982
[email protected]d0980792011-02-13 19:41:40983 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:54984 // similar, but for non-first loads, we want to use the committed entry. This
985 // is so the bookmarks bar disappears at the same time the page does.
986 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:35987 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:58988 return (render_manager_.web_ui() == NULL) ?
989 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54990 }
991
992 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:40993 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:54994 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:58995 if (render_manager_.pending_web_ui())
996 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
997 return (render_manager_.web_ui() == NULL) ?
998 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54999}
1000
[email protected]3edd9522009-03-04 22:19:411001void TabContents::ToolbarSizeChanged(bool is_animating) {
1002 TabContentsDelegate* d = delegate();
1003 if (d)
1004 d->ToolbarSizeChanged(this, is_animating);
1005}
[email protected]616ed5a2008-11-21 22:27:241006
[email protected]fc6fb7fb2009-11-07 02:35:041007bool TabContents::CanDownload(int request_id) {
1008 TabContentsDelegate* d = delegate();
1009 if (d)
1010 return d->CanDownload(request_id);
1011 return true;
1012}
1013
[email protected]d5f942ba2008-09-26 19:30:341014void TabContents::OnStartDownload(DownloadItem* download) {
1015 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341016
1017 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311018 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341019
[email protected]5b928b62010-08-03 11:46:511020 if (tab_contents && tab_contents->delegate())
1021 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411022}
[email protected]3edd9522009-03-04 22:19:411023
[email protected]d5f942ba2008-09-26 19:30:341024void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371025 ConstrainedWindowList::iterator i(
1026 std::find(child_windows_.begin(), child_windows_.end(), window));
1027 bool removed_topmost_window = i == child_windows_.begin();
1028 if (i != child_windows_.end())
1029 child_windows_.erase(i);
1030 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441031 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371032 } else {
1033 if (removed_topmost_window)
1034 child_windows_[0]->ShowConstrainedWindow();
1035 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441036 }
[email protected]66ba4932009-06-04 19:22:131037}
[email protected]d5f942ba2008-09-26 19:30:341038
[email protected]c65e2f152010-10-14 15:30:401039void TabContents::WillCloseBlockedContentContainer(
1040 BlockedContentContainer* container) {
1041 DCHECK(blocked_contents_ == container);
1042 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491043 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341044}
1045
[email protected]420ae012009-04-24 05:16:321046void TabContents::OnSavePage() {
1047 // If we can not save the page, try to download it.
1048 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1049 DownloadManager* dlm = profile()->GetDownloadManager();
1050 const GURL& current_page_url = GetURL();
1051 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221052 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321053 return;
1054 }
1055
1056 Stop();
1057
1058 // Create the save package and possibly prompt the user for the name to save
1059 // the page as. The user prompt is an asynchronous operation that runs on
1060 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421061 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321062 save_package_->GetSaveInfo();
1063}
1064
1065// Used in automated testing to bypass prompting the user for file names.
1066// Instead, the names and paths are hard coded rather than running them through
1067// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111068bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321069 SavePackage::SavePackageType save_type) {
1070 // Stop the page from navigating.
1071 Stop();
1072
[email protected]b5a1d11c2011-02-17 03:09:421073 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591074 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321075}
1076
[email protected]89d6e6e2009-12-03 23:06:511077void TabContents::EmailPageLocation() {
1078 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1079 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1080 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1081 title + "&body=%0A%0A" + page_url;
1082 platform_util::OpenExternal(GURL(mailto));
1083}
1084
[email protected]420ae012009-04-24 05:16:321085bool TabContents::PrintNow() {
1086 // We can't print interstitial page for now.
1087 if (showing_interstitial_page())
1088 return false;
1089
1090 return render_view_host()->PrintPages();
1091}
1092
[email protected]420ae012009-04-24 05:16:321093bool TabContents::IsActiveEntry(int32 page_id) {
1094 NavigationEntry* active_entry = controller_.GetActiveEntry();
1095 return (active_entry != NULL &&
1096 active_entry->site_instance() == GetSiteInstance() &&
1097 active_entry->page_id() == page_id);
1098}
1099
[email protected]b2fe07d12010-02-09 14:38:081100void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161101 set_encoding(encoding);
1102 render_view_host()->SetPageEncoding(encoding);
1103}
1104
[email protected]b2fe07d12010-02-09 14:38:081105void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161106 reset_encoding();
1107 render_view_host()->ResetPageEncodingToDefault();
1108}
1109
1110void TabContents::WindowMoveOrResizeStarted() {
1111 render_view_host()->WindowMoveOrResizeStarted();
1112}
1113
[email protected]c65e2f152010-10-14 15:30:401114void TabContents::SetAllContentsBlocked(bool value) {
1115 if (all_contents_blocked_ == value)
1116 return;
1117
1118 all_contents_blocked_ = value;
1119 if (!all_contents_blocked_ && blocked_contents_) {
1120 std::vector<TabContents*> blocked;
1121 blocked_contents_->GetBlockedContents(&blocked);
1122 for (size_t i = 0; i < blocked.size(); ++i)
1123 blocked_contents_->LaunchForContents(blocked[i]);
1124 }
1125}
1126
[email protected]3f8eb7f2009-10-02 23:58:051127void TabContents::LogNewTabTime(const std::string& event_name) {
1128 // Not all new tab pages get timed. In those cases, we don't have a
1129 // new_tab_start_time_.
1130 if (new_tab_start_time_.is_null())
1131 return;
1132
1133 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441134 MetricEventDurationDetails details(event_name,
1135 static_cast<int>(duration.InMilliseconds()));
1136
[email protected]7ab1e7d62009-10-14 23:32:011137 if (event_name == "Tab.NewTabScriptStart") {
1138 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1139 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1140 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1141 } else if (event_name == "Tab.NewTabOnload") {
1142 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051143 // The new tab page has finished loading; reset it.
1144 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441145 } else {
1146 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051147 }
[email protected]84abba62009-10-07 17:01:441148 NotificationService::current()->Notify(
1149 NotificationType::METRIC_EVENT_DURATION,
1150 Source<TabContents>(this),
1151 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051152}
1153
[email protected]7ab1e7d62009-10-14 23:32:011154void TabContents::OnCloseStarted() {
1155 if (tab_close_start_time_.is_null())
1156 tab_close_start_time_ = base::TimeTicks::Now();
1157}
1158
[email protected]46624bf2010-06-09 16:04:191159bool TabContents::ShouldAcceptDragAndDrop() const {
1160#if defined(OS_CHROMEOS)
1161 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1162 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201163 if (delegate() && delegate()->IsPopup(this))
1164 return false;
1165 return true;
[email protected]46624bf2010-06-09 16:04:191166#else
1167 return true;
1168#endif
1169}
1170
[email protected]7813bd72011-02-05 02:19:341171void TabContents::SystemDragEnded() {
1172 if (render_view_host())
1173 render_view_host()->DragSourceSystemDragEnded();
1174 if (delegate())
1175 delegate()->DragEnded();
1176}
1177
[email protected]ec0b6c42010-08-26 03:16:581178void TabContents::UpdateHistoryForNavigation(
1179 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1180 if (profile()->IsOffTheRecord())
1181 return;
1182
1183 // Add to history service.
1184 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1185 if (hs)
1186 hs->AddPage(*add_page_args);
1187}
1188
1189void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1190 if (profile()->IsOffTheRecord())
1191 return;
1192
1193 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1194 if (hs)
1195 hs->SetPageTitle(entry.virtual_url(), entry.title());
1196}
1197
[email protected]d0b8d092010-10-25 04:05:171198double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251199 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1200 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171201 return 0;
[email protected]b75b8292010-10-01 07:28:251202
1203 double zoom_level;
1204 if (temporary_zoom_settings_) {
1205 zoom_level = zoom_map->GetTemporaryZoomLevel(
1206 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1207 } else {
1208 zoom_level = zoom_map->GetZoomLevel(GetURL());
1209 }
[email protected]d0b8d092010-10-25 04:05:171210 return zoom_level;
1211}
[email protected]b75b8292010-10-01 07:28:251212
[email protected]d0b8d092010-10-25 04:05:171213int TabContents::GetZoomPercent(bool* enable_increment,
1214 bool* enable_decrement) {
1215 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251216 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171217 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251218 *enable_decrement = percent > minimum_zoom_percent_;
1219 *enable_increment = percent < maximum_zoom_percent_;
1220 return percent;
1221}
1222
[email protected]3c733bde2010-12-21 19:56:311223void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501224 if (!delegate_)
1225 return;
1226
1227 NavigationEntry* active_entry = controller().GetActiveEntry();
1228 if (!active_entry)
1229 return;
1230
1231 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121232}
1233
[email protected]932b7a12011-03-09 12:50:271234void TabContents::ViewFrameSource(const GURL& url,
1235 const std::string& content_state) {
1236 if (!delegate_)
1237 return;
1238
1239 delegate_->ViewSourceForFrame(this, url, content_state);
1240}
1241
[email protected]c40d6232011-03-25 00:16:211242void TabContents::SetContentRestrictions(int restrictions) {
1243 content_restrictions_ = restrictions;
1244 delegate()->ContentRestrictionsChanged(this);
1245}
1246
[email protected]724159a2010-12-30 01:11:181247void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1248 bool is_main_frame,
1249 const GURL& url) {
1250 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1251 GURL validated_url(url);
1252 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1253 GetRenderProcessHost()->id(), &validated_url);
1254
1255 ProvisionalLoadDetails details(
1256 is_main_frame,
1257 controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091258 validated_url, std::string(), is_error_page, frame_id);
[email protected]724159a2010-12-30 01:11:181259 NotificationService::current()->Notify(
1260 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1261 Source<NavigationController>(&controller_),
1262 Details<ProvisionalLoadDetails>(&details));
1263 if (is_main_frame) {
1264 // If we're displaying a network error page do not reset the content
1265 // settings delegate's cookies so the user has a chance to modify cookie
1266 // settings.
1267 if (!is_error_page)
1268 content_settings_delegate_->ClearCookieSpecificContentSettings();
1269 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381270
[email protected]4850a7f2011-03-08 23:36:591271 // Notify observers about the provisional change in the main frame URL.
1272 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1273 OnProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181274 }
1275}
1276
1277void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1278 const GURL& source_url,
1279 const GURL& target_url) {
1280 NavigationEntry* entry;
1281 if (page_id == -1)
1282 entry = controller_.pending_entry();
1283 else
1284 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1285 if (!entry || entry->url() != source_url)
1286 return;
1287 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381288
[email protected]4850a7f2011-03-08 23:36:591289 // Notify observers about the provisional change in the main frame URL.
1290 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1291 OnProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181292}
1293
1294void TabContents::OnDidFailProvisionalLoadWithError(
1295 int64 frame_id,
1296 bool is_main_frame,
1297 int error_code,
1298 const GURL& url,
1299 bool showing_repost_interstitial) {
1300 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1301 << ", error_code: " << error_code
1302 << " is_main_frame: " << is_main_frame
1303 << " showing_repost_interstitial: " << showing_repost_interstitial
1304 << " frame_id: " << frame_id;
1305 GURL validated_url(url);
1306 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1307 GetRenderProcessHost()->id(), &validated_url);
1308
1309 if (net::ERR_ABORTED == error_code) {
1310 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1311 // This means that the interstitial won't be torn down properly, which is
1312 // bad. But if we have an interstitial, go back to another tab type, and
1313 // then load the same interstitial again, we could end up getting the first
1314 // interstitial's "failed" message (as a result of the cancel) when we're on
1315 // the second one.
1316 //
1317 // We can't tell this apart, so we think we're tearing down the current page
1318 // which will cause a crash later one. There is also some code in
1319 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1320 // out because of this problem.
1321 //
1322 // http://code.google.com/p/chromium/issues/detail?id=2855
1323 // Because this will not tear down the interstitial properly, if "back" is
1324 // back to another tab type, the interstitial will still be somewhat alive
1325 // in the previous tab type. If you navigate somewhere that activates the
1326 // tab with the interstitial again, you'll see a flash before the new load
1327 // commits of the interstitial page.
1328 if (showing_interstitial_page()) {
1329 LOG(WARNING) << "Discarding message during interstitial.";
1330 return;
1331 }
1332
1333 // This will discard our pending entry if we cancelled the load (e.g., if we
1334 // decided to download the file instead of load it). Only discard the
1335 // pending entry if the URLs match, otherwise the user initiated a navigate
1336 // before the page loaded so that the discard would discard the wrong entry.
1337 NavigationEntry* pending_entry = controller_.pending_entry();
1338 if (pending_entry && pending_entry->url() == validated_url) {
1339 controller_.DiscardNonCommittedEntries();
1340 // Update the URL display.
1341 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1342 }
1343
1344 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1345 }
1346
1347 // Send out a notification that we failed a provisional load with an error.
1348 ProvisionalLoadDetails details(
1349 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091350 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181351 details.set_error_code(error_code);
1352
1353 NotificationService::current()->Notify(
1354 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1355 Source<NavigationController>(&controller_),
1356 Details<ProvisionalLoadDetails>(&details));
1357}
1358
1359void TabContents::OnDidLoadResourceFromMemoryCache(
1360 const GURL& url,
[email protected]724159a2010-12-30 01:11:181361 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191362 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181363 cache.Increment();
1364
1365 // Send out a notification that we loaded a resource from our memory cache.
1366 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1367 SSLManager::DeserializeSecurityInfo(security_info,
1368 &cert_id, &cert_status,
1369 &security_bits,
1370 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161371 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1372 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181373
1374 NotificationService::current()->Notify(
1375 NotificationType::LOAD_FROM_MEMORY_CACHE,
1376 Source<NavigationController>(&controller_),
1377 Details<LoadFromMemoryCacheDetails>(&details));
1378}
1379
1380void TabContents::OnDidDisplayInsecureContent() {
1381 displayed_insecure_content_ = true;
1382 SSLManager::NotifySSLInternalStateChanged();
1383}
1384
1385void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021386 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231387 LOG(INFO) << security_origin << " ran insecure content from "
1388 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181389 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1390}
1391
1392void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1393 controller_.DocumentLoadedInFrame();
1394 NotificationService::current()->Notify(
1395 NotificationType::FRAME_DOM_CONTENT_LOADED,
1396 Source<NavigationController>(&controller_),
1397 Details<int64>(&frame_id));
1398}
1399
1400void TabContents::OnDidFinishLoad(int64 frame_id) {
1401 NotificationService::current()->Notify(
1402 NotificationType::FRAME_DID_FINISH_LOAD,
1403 Source<NavigationController>(&controller_),
1404 Details<int64>(&frame_id));
1405}
1406
[email protected]c8f73ab2011-01-22 00:05:171407void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211408 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171409}
1410
1411void TabContents::OnPDFHasUnsupportedFeature() {
1412 PDFHasUnsupportedFeature(this);
1413}
1414
[email protected]96d185d2009-04-24 03:28:541415// Notifies the RenderWidgetHost instance about the fact that the page is
1416// loading, or done loading and calls the base implementation.
1417void TabContents::SetIsLoading(bool is_loading,
1418 LoadNotificationDetails* details) {
1419 if (is_loading == is_loading_)
1420 return;
1421
1422 if (!is_loading) {
1423 load_state_ = net::LOAD_STATE_IDLE;
1424 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561425 upload_size_ = 0;
1426 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541427 }
1428
1429 render_manager_.SetIsLoading(is_loading);
1430
1431 is_loading_ = is_loading;
1432 waiting_for_response_ = is_loading;
1433
[email protected]6ebdc9b2010-09-27 16:55:571434 if (delegate_)
1435 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351436 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541437
1438 NotificationType type = is_loading ? NotificationType::LOAD_START :
1439 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111440 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541441 if (details)
1442 det = Details<LoadNotificationDetails>(details);
1443 NotificationService::current()->Notify(type,
1444 Source<NavigationController>(&controller_),
1445 det);
1446}
1447
[email protected]b6c874582009-05-08 19:38:311448void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291449 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061450 // A page can't spawn popups (or do anything else, either) until its load
1451 // commits, so when we reach here, the popup was spawned by the
1452 // NavigationController's last committed entry, not the active entry. For
1453 // example, if a page opens a popup in an onunload() handler, then the active
1454 // entry is the page to be loaded as we navigate away from the unloading
1455 // page. For this reason, we can't use GetURL() to get the opener URL,
1456 // because it returns the active entry.
1457 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1458 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1459
1460 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491461 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091462 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491463 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1464 } else {
[email protected]c65e2f152010-10-14 15:30:401465 if (!blocked_contents_)
1466 blocked_contents_ = new BlockedContentContainer(this);
1467 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1468 true);
[email protected]55126132010-08-19 14:53:281469 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1470 std::string());
[email protected]8cc8d492010-02-02 10:40:491471 }
[email protected]b9681312008-11-07 00:08:261472}
[email protected]616ed5a2008-11-21 22:27:241473
[email protected]616ed5a2008-11-21 22:27:241474void TabContents::ExpireInfoBars(
1475 const NavigationController::LoadCommittedDetails& details) {
1476 // Only hide InfoBars when the user has done something that makes the main
1477 // frame load. We don't want various automatic or subframe navigations making
1478 // it disappear.
1479 if (!details.is_user_initiated_main_frame_load())
1480 return;
1481
[email protected]ec8f51162011-02-08 04:20:401482 // NOTE: It is not safe to change the following code to count upwards or use
1483 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1484 // list.
1485 for (size_t i = infobar_count(); i > 0; --i) {
1486 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051487 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241488 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241489 }
1490}
[email protected]fdd61c62009-04-22 19:22:571491
[email protected]d0980792011-02-13 19:41:401492WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581493 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541494 // that goes along with it to control the basic flags. For example, we want to
1495 // show the pending URL in the URL bar, so we want the display_url flag to
1496 // be from the pending entry.
1497 //
1498 // The confusion comes because there are multiple possibilities for the
1499 // initial load in a tab as a side effect of the way the RenderViewHostManager
1500 // works.
1501 //
[email protected]e0112912011-02-02 22:54:351502 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541503 // the pending one, and we want it to apply here.
1504 //
1505 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1506 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581507 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351508 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541509 //
1510 // This condition handles all of these cases:
1511 //
1512 // - First load in first tab: no committed nav entry + pending nav entry +
1513 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351514 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541515 //
1516 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351517 // no pending Web UI:
1518 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541519 //
1520 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351521 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541522 //
1523 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351524 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541525 if (controller_.pending_entry() &&
1526 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581527 render_manager_.pending_web_ui()))
1528 return render_manager_.pending_web_ui();
1529 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541530}
[email protected]420ae012009-04-24 05:16:321531
[email protected]1fd1a502011-03-30 16:55:561532WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1533 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1534}
1535
[email protected]420ae012009-04-24 05:16:321536void TabContents::DidNavigateMainFramePostCommit(
1537 const NavigationController::LoadCommittedDetails& details,
1538 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561539 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381540 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441541 // that opened the window, as long as both renderers have the same
1542 // privileges.
[email protected]1fd1a502011-03-30 16:55:561543 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1544 WebUI* web_ui = content::GetContentClient()->browser()->
1545 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581546 // web_ui might be NULL if the URL refers to a non-existent extension.
1547 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401548 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581549 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441550 }
1551 }
[email protected]1fd1a502011-03-30 16:55:561552 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441553 }
1554
[email protected]420ae012009-04-24 05:16:321555 if (details.is_user_initiated_main_frame_load()) {
1556 // Clear the status bubble. This is a workaround for a bug where WebKit
1557 // doesn't let us know that the cursor left an element during a
1558 // transition (this is also why the mouse cursor remains as a hand after
1559 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1560 // clear the bubble when a user navigates to a named anchor in the same
1561 // page.
1562 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321563 }
1564
[email protected]420ae012009-04-24 05:16:321565 // Allow the new page to set the title again.
1566 received_page_title_ = false;
1567
1568 // Get the favicon, either from history or request it from the net.
[email protected]16be5c32011-03-15 17:52:031569 favicon_helper_->FetchFavicon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321570
[email protected]0de80162010-02-03 04:52:351571 // Clear all page actions, blocked content notifications and browser actions
1572 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141573 if (!details.is_in_page) {
[email protected]0de80162010-02-03 04:52:351574 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401575 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341576 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401577 blocked_contents_->Destroy();
1578 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351579 }
1580
1581 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411582 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551583 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471584
1585 // Once the main frame is navigated, we're no longer considered to have
1586 // displayed insecure content.
1587 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171588 }
[email protected]ce5c4502009-05-06 16:46:111589
[email protected]8cc8d492010-02-02 10:40:491590 // Close constrained windows if necessary.
1591 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1592 details.previous_url, details.entry->url()))
1593 CloseConstrainedWindows();
1594
[email protected]3c9e1872010-11-18 16:17:491595 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171596 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491597 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321598}
1599
1600void TabContents::DidNavigateAnyFramePostCommit(
1601 RenderViewHost* render_view_host,
1602 const NavigationController::LoadCommittedDetails& details,
1603 const ViewHostMsg_FrameNavigate_Params& params) {
1604 // If we navigate, start showing messages again. This does nothing to prevent
1605 // a malicious script from spamming messages, since the script could just
1606 // reload the page to stop blocking.
1607 suppress_javascript_messages_ = false;
1608
[email protected]3c9e1872010-11-18 16:17:491609 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171610 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491611 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551612
1613 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581614 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321615}
1616
[email protected]8cc8d492010-02-02 10:40:491617void TabContents::CloseConstrainedWindows() {
1618 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331619 // To ensure that we iterate over every element in child_windows_ we
1620 // need to use a copy of child_windows_. Otherwise if
1621 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1622 // skipping some elements.
1623 ConstrainedWindowList child_windows_copy(child_windows_);
1624 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1625 it != child_windows_copy.end(); ++it) {
1626 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441627 if (window) {
[email protected]420ae012009-04-24 05:16:321628 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441629 BlockTabContent(false);
1630 }
[email protected]420ae012009-04-24 05:16:321631 }
1632}
1633
[email protected]420ae012009-04-24 05:16:321634void TabContents::UpdateAlternateErrorPageURL() {
1635 GURL url = GetAlternateErrorPageURL();
1636 render_view_host()->SetAlternateErrorPageURL(url);
1637}
1638
1639void TabContents::UpdateWebPreferences() {
1640 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1641}
1642
[email protected]d0b8d092010-10-25 04:05:171643void TabContents::UpdateZoomLevel() {
1644 render_view_host()->SetZoomLevel(GetZoomLevel());
1645}
1646
[email protected]420ae012009-04-24 05:16:321647void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1648 RenderViewHost* rvh) {
1649 // If we are creating a RVH for a restored controller, then we might
1650 // have more page IDs than the SiteInstance's current max page ID. We must
1651 // make sure that the max page ID is larger than any restored page ID.
1652 // Note that it is ok for conflicting page IDs to exist in another tab
1653 // (i.e., NavigationController), but if any page ID is larger than the max,
1654 // the back/forward list will get confused.
1655 int max_restored_page_id = controller_.max_restored_page_id();
1656 if (max_restored_page_id > 0) {
1657 int curr_max_page_id = site_instance->max_page_id();
1658 if (max_restored_page_id > curr_max_page_id) {
1659 // Need to update the site instance immediately.
1660 site_instance->UpdateMaxPageID(max_restored_page_id);
1661
1662 // Also tell the renderer to update its internal representation. We
1663 // need to reserve enough IDs to make all restored page IDs less than
1664 // the max.
1665 if (curr_max_page_id < 0)
1666 curr_max_page_id = 0;
1667 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1668 }
1669 }
1670}
1671
[email protected]ec0b6c42010-08-26 03:16:581672scoped_refptr<history::HistoryAddPageArgs>
1673TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541674 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471675 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321676 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581677 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1678 new history::HistoryAddPageArgs(
1679 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1680 params.redirects, params.transition, history::SOURCE_BROWSED,
1681 details.did_replace_entry));
1682 if (PageTransition::IsMainFrame(params.transition) &&
1683 virtual_url != params.url) {
1684 // Hack on the "virtual" URL so that it will appear in history. For some
1685 // types of URLs, we will display a magic URL that is different from where
1686 // the page is actually navigated. We want the user to see in history what
1687 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1688 // only applies to the main frame, as the virtual URL doesn't apply to
1689 // sub-frames.
1690 add_page_args->url = virtual_url;
1691 if (!add_page_args->redirects.empty())
1692 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321693 }
[email protected]ec0b6c42010-08-26 03:16:581694 return add_page_args;
[email protected]420ae012009-04-24 05:16:321695}
1696
1697bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1698 const std::wstring& title) {
1699 // For file URLs without a title, use the pathname instead. In the case of a
1700 // synthesized title, we don't want the update to count toward the "one set
1701 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251702 string16 final_title;
[email protected]420ae012009-04-24 05:16:321703 bool explicit_set;
1704 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251705 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321706 explicit_set = false; // Don't count synthetic titles toward the set limit.
1707 } else {
[email protected]e53668962010-06-23 15:35:251708 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321709 explicit_set = true;
1710 }
1711
[email protected]e53668962010-06-23 15:35:251712 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321713 return false; // Nothing changed, don't bother.
1714
[email protected]e53668962010-06-23 15:35:251715 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321716
[email protected]ec0b6c42010-08-26 03:16:581717 if (!received_page_title_) {
1718 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321719 received_page_title_ = explicit_set;
1720 }
1721
1722 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251723 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321724
[email protected]cbc0e1b2010-04-12 18:33:041725 NotificationService::current()->Notify(
1726 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1727 Source<TabContents>(this),
1728 NotificationService::NoDetails());
1729
[email protected]420ae012009-04-24 05:16:321730 return true;
1731}
1732
1733void TabContents::NotifySwapped() {
1734 // After sending out a swap notification, we need to send a disconnect
1735 // notification so that clients that pick up a pointer to |this| can NULL the
1736 // pointer. See Bug 1230284.
1737 notify_disconnection_ = true;
1738 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341739 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221740 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321741 NotificationService::NoDetails());
1742}
1743
1744void TabContents::NotifyConnected() {
1745 notify_disconnection_ = true;
1746 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341747 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221748 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321749 NotificationService::NoDetails());
1750}
1751
1752void TabContents::NotifyDisconnected() {
1753 if (!notify_disconnection_)
1754 return;
1755
1756 notify_disconnection_ = false;
1757 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341758 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221759 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321760 NotificationService::NoDetails());
1761}
1762
[email protected]7d472472011-01-22 01:30:251763void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541764 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1765 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1766 if (!entry)
1767 return;
1768 // Note that we don't call NavigationController::GotToOffset() as we don't
1769 // want to create a pending navigation entry (it might end up lingering
1770 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521771 entry->set_transition_type(entry->transition_type() |
1772 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541773 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1774 }
[email protected]bf5c2ff392009-07-08 16:24:331775}
1776
[email protected]a2cf65eb2010-01-18 08:20:381777void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381778 int32 page_id,
[email protected]e5106202010-06-11 21:12:361779 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101780 const std::string& language,
1781 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381782 // Don't index any https pages. People generally don't want their bank
1783 // accounts, etc. indexed on their computer, especially since some of these
1784 // things are not marked cachable.
1785 // TODO(brettw) we may want to consider more elaborate heuristics such as
1786 // the cachability of the page. We may also want to consider subframes (this
1787 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271788 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1789 // content indexing for chromeos in some future releases.
1790#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381791 if (!url.SchemeIsSecure()) {
1792 Profile* p = profile();
1793 if (p && !p->IsOffTheRecord()) {
1794 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1795 if (hs)
1796 hs->SetPageContents(url, contents);
1797 }
1798 }
[email protected]ccd40a52010-05-11 16:15:271799#endif
[email protected]a8a81292010-01-21 00:32:451800
[email protected]1c57b7b2010-07-12 17:38:101801 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451802
1803 std::string lang = language;
1804 NotificationService::current()->Notify(
1805 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151806 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451807 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521808
1809 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1810 if (CommandLine::ForCurrentProcess()->HasSwitch(
1811 switches::kEnableInBrowserThumbnailing)) {
1812 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1813 }
[email protected]a2cf65eb2010-01-18 08:20:381814}
1815
[email protected]7e0831b2010-02-01 08:45:151816void TabContents::OnPageTranslated(int32 page_id,
1817 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161818 const std::string& translated_lang,
1819 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551820 language_state_.set_current_language(translated_lang);
1821 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161822 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151823 NotificationService::current()->Notify(
1824 NotificationType::PAGE_TRANSLATED,
1825 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161826 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151827}
1828
[email protected]dcd5b332010-08-11 08:55:181829void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561830 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241831 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561832}
1833
[email protected]8d3347f2009-07-09 22:00:211834RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321835 return view_.get();
1836}
1837
[email protected]8d3347f2009-07-09 22:00:211838RenderViewHostDelegate::RendererManagement*
1839TabContents::GetRendererManagementDelegate() {
1840 return &render_manager_;
1841}
1842
[email protected]46ba9082010-06-22 10:00:581843RenderViewHostDelegate::ContentSettings*
1844TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551845 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581846}
1847
[email protected]1f18184a2010-07-21 19:34:491848RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1849 return GetSSLHelper();
1850}
1851
[email protected]fd571bb2010-03-19 01:23:541852AutomationResourceRoutingDelegate*
1853TabContents::GetAutomationResourceRoutingDelegate() {
1854 return delegate();
1855}
1856
[email protected]ced90ae12010-02-20 02:06:161857RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1858 return bookmark_drag_;
1859}
1860
1861void TabContents::SetBookmarkDragDelegate(
1862 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1863 bookmark_drag_ = bookmark_drag;
1864}
1865
[email protected]9fb83e82010-07-02 18:24:551866TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
1867 return content_settings_delegate_.get();
1868}
1869
[email protected]93623c5d2009-12-10 21:40:321870RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461871 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511872}
1873
[email protected]57c6a652009-05-04 07:58:341874TabContents* TabContents::GetAsTabContents() {
1875 return this;
1876}
1877
[email protected]7b291f92009-08-14 05:43:531878ViewType::Type TabContents::GetRenderViewType() const {
1879 return ViewType::TAB_CONTENTS;
1880}
1881
1882int TabContents::GetBrowserWindowID() const {
1883 return controller().window_id().id();
1884}
1885
[email protected]420ae012009-04-24 05:16:321886void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061887 NotificationService::current()->Notify(
1888 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1889 Source<TabContents>(this),
1890 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321891 NavigationEntry* entry = controller_.GetActiveEntry();
1892 if (!entry)
1893 return;
1894
1895 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351896 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561897 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581898 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321899
1900 if (entry->IsViewSourceMode()) {
1901 // Put the renderer in view source mode.
1902 render_view_host->Send(
1903 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1904 }
[email protected]0666aef2009-05-13 19:48:081905
1906 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321907}
1908
1909void TabContents::RenderViewReady(RenderViewHost* rvh) {
1910 if (rvh != render_view_host()) {
1911 // Don't notify the world, since this came from a renderer in the
1912 // background.
1913 return;
1914 }
1915
1916 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301917 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231918 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301919
1920 // Restore the focus to the tab (otherwise the focus will be on the top
1921 // window).
[email protected]484ae5912010-09-29 19:16:141922 if (was_crashed && !FocusLocationBarByDefault() &&
1923 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301924 Focus();
[email protected]484ae5912010-09-29 19:16:141925 }
[email protected]420ae012009-04-24 05:16:321926}
1927
[email protected]443b80e2010-12-14 00:42:231928void TabContents::RenderViewGone(RenderViewHost* rvh,
1929 base::TerminationStatus status,
1930 int error_code) {
[email protected]420ae012009-04-24 05:16:321931 if (rvh != render_view_host()) {
1932 // The pending page's RenderViewHost is gone.
1933 return;
1934 }
1935
[email protected]2e3f4572011-03-25 19:24:471936 // Let observers know first and give them a chance to act.
1937 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
1938
[email protected]420ae012009-04-24 05:16:321939 SetIsLoading(false, NULL);
1940 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231941 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321942
[email protected]ff9efc62010-02-18 22:10:541943 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:401944 while (!infobar_delegates_.empty())
1945 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:541946
[email protected]8e537302009-06-10 21:19:581947 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:551948 // Only do this if we're not in browser shutdown, so that TabContents
1949 // objects that are not in a browser (e.g., HTML dialogs) and thus are
1950 // visible do not flash a sad tab page.
1951 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:161952 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321953
1954 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:291955 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:321956}
1957
[email protected]2e4633c2009-07-09 16:58:061958void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481959 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061960}
1961
[email protected]420ae012009-04-24 05:16:321962void TabContents::DidNavigate(RenderViewHost* rvh,
1963 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:371964 int extra_invalidate_flags = 0;
1965
1966 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:351967 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:371968
[email protected]420ae012009-04-24 05:16:321969 render_manager_.DidNavigateMainFrame(rvh);
1970
[email protected]20ede072009-10-06 00:28:351971 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:371972 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:371973 }
1974
[email protected]420ae012009-04-24 05:16:321975 // Update the site of the SiteInstance if it doesn't have one yet.
1976 if (!GetSiteInstance()->has_site())
1977 GetSiteInstance()->SetSite(params.url);
1978
1979 // Need to update MIME type here because it's referred to in
1980 // UpdateNavigationCommands() called by RendererDidNavigate() to
1981 // determine whether or not to enable the encoding menu.
1982 // It's updated only for the main frame. For a subframe,
1983 // RenderView::UpdateURL does not set params.contents_mime_type.
1984 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1985 // TODO(jungshik): Add a test for the encoding menu to avoid
1986 // regressing it again.
1987 if (PageTransition::IsMainFrame(params.transition))
1988 contents_mime_type_ = params.contents_mime_type;
1989
1990 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:371991 bool did_navigate = controller_.RendererDidNavigate(
1992 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:391993
[email protected]a9c0bfe2010-09-17 08:35:221994 // Send notification about committed provisional loads. This notification is
1995 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1996 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1997 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071998 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1999 // that is not recorded in the navigation history. For the purpose of
2000 // tracking navigation events, we treat this event as a sub frame navigation
2001 // event.
2002 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2003 ProvisionalLoadDetails load_details(
[email protected]b9e8ea62011-03-04 06:29:092004 is_main_frame, details.is_in_page, params.url, std::string(),
[email protected]dd0aafd2010-12-02 13:13:412005 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222006 load_details.set_transition_type(params.transition);
2007 // Whether or not a page transition was triggered by going backward or
2008 // forward in the history is only stored in the navigation controller's
2009 // entry list.
2010 if (did_navigate &&
2011 (controller_.GetActiveEntry()->transition_type() &
2012 PageTransition::FORWARD_BACK)) {
2013 load_details.set_transition_type(
2014 params.transition | PageTransition::FORWARD_BACK);
2015 }
2016 NotificationService::current()->Notify(
2017 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2018 Source<NavigationController>(&controller_),
2019 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222020 }
2021
[email protected]3e90d4a2009-07-03 17:38:392022 // Update history. Note that this needs to happen after the entry is complete,
2023 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582024 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392025 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582026 // URLs, we use a data: URL as the real value. We actually want to save the
2027 // about: URL to the history db and keep the data: URL hidden. This is what
2028 // the TabContents' URL getter does.
2029 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2030 CreateHistoryAddPageArgs(GetURL(), details, params));
2031 if (!delegate() ||
2032 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2033 details.type)) {
2034 UpdateHistoryForNavigation(add_page_args);
2035 }
[email protected]3e90d4a2009-07-03 17:38:392036 }
2037
[email protected]76543b92009-08-31 17:27:452038 if (!did_navigate)
2039 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322040
2041 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2042 // for the appropriate notification (best) or you can add it to
2043 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2044 // necessary, please).
2045
2046 // Run post-commit tasks.
2047 if (details.is_main_frame)
2048 DidNavigateMainFramePostCommit(details, params);
2049 DidNavigateAnyFramePostCommit(rvh, details, params);
2050}
2051
2052void TabContents::UpdateState(RenderViewHost* rvh,
2053 int32 page_id,
2054 const std::string& state) {
2055 DCHECK(rvh == render_view_host());
2056
2057 // We must be prepared to handle state updates for any page, these occur
2058 // when the user is scrolling and entering form data, as well as when we're
2059 // leaving a page, in which case our state may have already been moved to
2060 // the next page. The navigation controller will look up the appropriate
2061 // NavigationEntry and update it when it is notified via the delegate.
2062
2063 int entry_index = controller_.GetEntryIndexWithPageID(
2064 GetSiteInstance(), page_id);
2065 if (entry_index < 0)
2066 return;
2067 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2068
2069 if (state == entry->content_state())
2070 return; // Nothing to update.
2071 entry->set_content_state(state);
2072 controller_.NotifyEntryChanged(entry, entry_index);
2073}
2074
2075void TabContents::UpdateTitle(RenderViewHost* rvh,
2076 int32 page_id, const std::wstring& title) {
2077 // If we have a title, that's a pretty good indication that we've started
2078 // getting useful data.
2079 SetNotWaitingForResponse();
2080
2081 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482082 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582083 page_id);
[email protected]420ae012009-04-24 05:16:322084 if (!entry || !UpdateTitleForEntry(entry, title))
2085 return;
2086
2087 // Broadcast notifications when the UI should be updated.
2088 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032089 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322090}
2091
[email protected]420ae012009-04-24 05:16:322092void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402093 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322094 set_encoding(encoding);
2095}
2096
2097void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2098 if (delegate())
2099 delegate()->UpdateTargetURL(this, url);
2100}
2101
[email protected]c4e98902010-06-01 10:20:142102void TabContents::UpdateInspectorSetting(const std::string& key,
2103 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052104 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082105}
2106
[email protected]45aafc92010-06-07 14:18:532107void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052108 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532109}
2110
[email protected]420ae012009-04-24 05:16:322111void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292112 // The UI may be in an event-tracking loop, such as between the
2113 // mouse-down and mouse-up in text selection or a button click.
2114 // Defer the close until after tracking is complete, so that we
2115 // don't free objects out from under the UI.
2116 // TODO(shess): This could probably be integrated with the
2117 // IsDoingDrag() test below. Punting for now because I need more
2118 // research to understand how this impacts platforms other than Mac.
2119 // TODO(shess): This could get more fine-grained. For instance,
2120 // closing a tab in another window while selecting text in the
2121 // current window's Omnibox should be just fine.
2122 if (view()->IsEventTracking()) {
2123 view()->CloseTabAfterEventTracking();
2124 return;
2125 }
2126
[email protected]24a4d1062009-07-10 23:10:422127 // If we close the tab while we're in the middle of a drag, we'll crash.
2128 // Instead, cancel the drag and close it as soon as the drag ends.
2129 if (view()->IsDoingDrag()) {
2130 view()->CancelDragAndCloseTab();
2131 return;
2132 }
2133
[email protected]420ae012009-04-24 05:16:322134 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2135 if (delegate() && rvh == render_view_host())
2136 delegate()->CloseContents(this);
2137}
2138
2139void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2140 if (delegate() && delegate()->IsPopup(this))
2141 delegate()->MoveContents(this, new_bounds);
2142}
2143
[email protected]7ab1e7d62009-10-14 23:32:012144void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322145 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492146
[email protected]c40d6232011-03-25 00:16:212147 if (delegate() && content_restrictions_) {
2148 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:212149 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002150 }
[email protected]3c9e1872010-11-18 16:17:492151
2152 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172153 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322154}
2155
[email protected]7ab1e7d62009-10-14 23:32:012156void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322157 scoped_ptr<LoadNotificationDetails> details;
2158
2159 NavigationEntry* entry = controller_.GetActiveEntry();
2160 // An entry may not exist for a stop when loading an initial blank page or
2161 // if an iframe injected by script into a blank page finishes loading.
2162 if (entry) {
[email protected]420ae012009-04-24 05:16:322163 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2164
2165 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542166 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322167 entry->transition_type(),
2168 elapsed,
2169 &controller_,
2170 controller_.GetCurrentEntryIndex()));
2171 }
2172
[email protected]420ae012009-04-24 05:16:322173 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492174
2175 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172176 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322177}
2178
[email protected]1a3c3cb2010-12-16 21:03:402179void TabContents::DidChangeLoadProgress(double progress) {
2180 if (delegate())
2181 delegate()->LoadProgressChanged(progress);
2182}
2183
[email protected]25497492010-09-11 15:15:082184void TabContents::DocumentOnLoadCompletedInMainFrame(
2185 RenderViewHost* render_view_host,
2186 int32 page_id) {
2187 NotificationService::current()->Notify(
2188 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2189 Source<TabContents>(this),
2190 Details<int>(&page_id));
2191}
2192
[email protected]420ae012009-04-24 05:16:322193void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2194 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582195 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352196 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322197 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2198 // generated suggestions).
2199 //
[email protected]e0112912011-02-02 22:54:352200 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162201 // want web sites to see a referrer of "chrome://blah" (and some
2202 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322203 // send to the site), so we send no referrer.
2204 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582205 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322206 } else {
2207 OpenURL(url, referrer, disposition, PageTransition::LINK);
2208 }
2209}
2210
[email protected]1ee614862009-07-06 20:29:182211void TabContents::DomOperationResponse(const std::string& json_string,
2212 int automation_id) {
2213}
2214
[email protected]badcca352011-02-12 01:08:082215void TabContents::ProcessWebUIMessage(
[email protected]44c49c92011-03-28 16:17:232216 const ExtensionHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582217 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442218 // This can happen if someone uses window.open() to open an extension URL
2219 // from a non-extension context.
[email protected]553602e12011-04-05 17:01:182220 render_view_host()->Send(new ExtensionMsg_Response(
2221 render_view_host()->routing_id(), params.request_id, false, "",
2222 "Access to extension API denied."));
[email protected]420ae012009-04-24 05:16:322223 return;
2224 }
[email protected]badcca352011-02-12 01:08:082225 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322226}
2227
2228void TabContents::ProcessExternalHostMessage(const std::string& message,
2229 const std::string& origin,
2230 const std::string& target) {
2231 if (delegate())
2232 delegate()->ForwardMessageToExternalHost(message, origin, target);
2233}
2234
[email protected]420ae012009-04-24 05:16:322235void TabContents::RunJavaScriptMessage(
2236 const std::wstring& message,
2237 const std::wstring& default_prompt,
2238 const GURL& frame_url,
2239 const int flags,
2240 IPC::Message* reply_msg,
2241 bool* did_suppress_message) {
2242 // Suppress javascript messages when requested and when inside a constrained
2243 // popup window (because that activates them and breaks them out of the
2244 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552245 // Also suppress messages when showing an interstitial. The interstitial is
2246 // shown over the previous page, we don't want the hidden page dialogs to
2247 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502248 bool suppress_this_message =
2249 suppress_javascript_messages_ ||
2250 showing_interstitial_page() ||
2251 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322252 if (delegate())
2253 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312254 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322255
2256 *did_suppress_message = suppress_this_message;
2257
2258 if (!suppress_this_message) {
2259 base::TimeDelta time_since_last_message(
2260 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2261 bool show_suppress_checkbox = false;
2262 // Show a checkbox offering to suppress further messages if this message is
2263 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2264 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152265 base::TimeDelta::FromMilliseconds(
2266 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322267 show_suppress_checkbox = true;
2268
[email protected]d6ad7442010-09-05 19:06:522269 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2270 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322271 } else {
2272 // If we are suppressing messages, just reply as is if the user immediately
2273 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542274 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322275 }
2276}
2277
2278void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2279 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292280 if (delegate())
2281 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502282 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2283 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2284 std::wstring());
2285 return;
2286 }
[email protected]7ab1e7d62009-10-14 23:32:012287 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222288 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322289}
2290
[email protected]420ae012009-04-24 05:16:322291GURL TabContents::GetAlternateErrorPageURL() const {
2292 GURL url;
2293 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2294 if (profile()->IsOffTheRecord())
2295 return url;
2296
2297 PrefService* prefs = profile()->GetPrefs();
2298 DCHECK(prefs);
2299 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152300 url = google_util::AppendGoogleLocaleParam(
2301 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322302 url = google_util::AppendGoogleTLDParam(url);
2303 }
2304 return url;
2305}
2306
2307WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062308 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582309 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082310 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582311 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082312
[email protected]9beff752010-09-22 19:35:432313 // Force accelerated compositing and 2d canvas off for chrome: and
2314 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432315 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2316 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082317 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432318 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082319 }
2320
[email protected]39553442010-09-09 00:01:552321#if defined(OS_MACOSX)
2322 // Disable accelerated compositing if IOSurface's are not supported,
2323 // as is the case in 10.5.
2324 if (!IOSurfaceSupport::Initialize())
2325 web_prefs.accelerated_compositing_enabled = false;
2326#endif
2327
[email protected]447021c2010-09-08 21:29:082328 return web_prefs;
[email protected]420ae012009-04-24 05:16:322329}
2330
[email protected]7d472472011-01-22 01:30:252331void TabContents::OnUserGesture() {
2332 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2333 DownloadRequestLimiter* limiter =
2334 g_browser_process->download_request_limiter();
2335 if (limiter)
2336 limiter->OnUserGesture(this);
2337 ExternalProtocolHandler::PermitLaunchUrl();
2338}
2339
[email protected]fa1cf0b82010-01-15 21:49:442340void TabContents::OnIgnoredUIEvent() {
2341 if (constrained_window_count()) {
2342 ConstrainedWindow* window = *constrained_window_begin();
2343 window->FocusConstrainedWindow();
2344 }
2345}
2346
[email protected]420ae012009-04-24 05:16:322347void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2348 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342349 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322350 // delivered to a pending RenderViewHost. We must first run the onunload
2351 // handler of the old RenderViewHost before we can allow it to proceed.
2352 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2353 new_request_id);
2354}
2355
[email protected]420ae012009-04-24 05:16:322356void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2357 bool is_during_unload) {
2358 if (is_during_unload) {
2359 // Hang occurred while firing the beforeunload/unload handler.
2360 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112361 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322362
2363 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2364 return;
2365
2366 // If the tab hangs in the beforeunload/unload handler there's really
2367 // nothing we can do to recover. Pretend the unload listeners have
2368 // all fired and close the tab. If the hang is in the beforeunload handler
2369 // then the user will not have the option of cancelling the close.
2370 Close(rvh);
2371 return;
2372 }
2373
[email protected]61b50092011-02-03 18:02:192374 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2375 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292376 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192377 }
[email protected]420ae012009-04-24 05:16:322378}
2379
2380void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292381 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322382}
2383
2384void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562385 net::LoadState load_state,
2386 uint64 upload_position,
2387 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322388 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562389 upload_position_ = upload_position;
2390 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292391 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192392 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292393 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422394 load_state_host_ = WideToUTF16Hack(
2395 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322396 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2397 SetNotWaitingForResponse();
2398 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502399 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322400}
2401
[email protected]1ee614862009-07-06 20:29:182402bool TabContents::IsExternalTabContainer() const {
2403 if (!delegate())
2404 return false;
2405
2406 return delegate()->IsExternalTabContainer();
2407}
2408
[email protected]1ee614862009-07-06 20:29:182409void TabContents::DidInsertCSS() {
2410 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322411}
2412
[email protected]546ae4e02010-12-08 14:57:192413void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352414 NotificationService::current()->Notify(
2415 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212416 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192417 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352418}
2419
[email protected]b75b8292010-10-01 07:28:252420void TabContents::UpdateZoomLimits(int minimum_percent,
2421 int maximum_percent,
2422 bool remember) {
2423 minimum_zoom_percent_ = minimum_percent;
2424 maximum_zoom_percent_ = maximum_percent;
2425 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382426}
2427
[email protected]7d472472011-01-22 01:30:252428void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442429 if (delegate())
2430 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252431}
2432
[email protected]420ae012009-04-24 05:16:322433void TabContents::BeforeUnloadFiredFromRenderManager(
2434 bool proceed,
2435 bool* proceed_to_fire_unload) {
2436 if (delegate())
2437 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2438}
2439
[email protected]3a3d47472010-07-15 21:03:542440void TabContents::DidStartLoadingFromRenderManager(
2441 RenderViewHost* render_view_host) {
2442 DidStartLoading();
2443}
2444
2445void TabContents::RenderViewGoneFromRenderManager(
2446 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232447 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2448 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542449}
2450
[email protected]420ae012009-04-24 05:16:322451void TabContents::UpdateRenderViewSizeForRenderManager() {
2452 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262453 gfx::Size size = view_->GetContainerSize();
2454 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2455 // here during container initialization and normal window size will be set
2456 // later. In case of tab duplication this resizing to 0x0 prevents setting
2457 // normal size later so just ignore it.
2458 if (!size.IsEmpty())
2459 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322460}
2461
[email protected]3a3d47472010-07-15 21:03:542462void TabContents::NotifySwappedFromRenderManager() {
2463 NotifySwapped();
2464}
2465
2466NavigationController& TabContents::GetControllerForRenderManager() {
2467 return controller();
2468}
2469
[email protected]d0980792011-02-13 19:41:402470WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562471 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322472}
2473
2474NavigationEntry*
2475TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2476 return controller_.GetLastCommittedEntry();
2477}
2478
2479bool TabContents::CreateRenderViewForRenderManager(
2480 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322481 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522482
[email protected]674b3822010-08-04 04:02:512483 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322484 return false;
2485
2486 // Now that the RenderView has been created, we need to tell it its size.
2487 rwh_view->SetSize(view_->GetContainerSize());
2488
2489 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2490 render_view_host);
2491 return true;
2492}
2493
2494void TabContents::Observe(NotificationType type,
2495 const NotificationSource& source,
2496 const NotificationDetails& details) {
2497 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322498 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512499 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322500 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2501 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2502 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532503 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2504 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322505 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172506 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2507 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322508 } else {
2509 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2510 }
2511 break;
2512 }
2513 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2514 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2515 break;
2516
2517 case NotificationType::NAV_ENTRY_COMMITTED: {
2518 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2519
2520 NavigationController::LoadCommittedDetails& committed_details =
2521 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2522 ExpireInfoBars(committed_details);
2523 break;
2524 }
2525
[email protected]d3ba77272009-09-03 00:06:092526#if defined(OS_LINUX)
2527 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542528 renderer_preferences_util::UpdateFromSystemSettings(
2529 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092530 render_view_host()->SyncRendererPrefs();
2531 break;
2532 }
2533#endif
2534
[email protected]6c32ce72010-03-08 05:18:062535 case NotificationType::USER_STYLE_SHEET_UPDATED:
2536 UpdateWebPreferences();
2537 break;
2538
[email protected]79580c62010-02-02 02:36:252539 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452540 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252541 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492542 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292543 if (entry)
[email protected]da0c8e92010-02-09 23:25:492544 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292545 if (settings_details.ptr()->update_all() ||
2546 settings_details.ptr()->pattern().Matches(entry_url)) {
2547 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232548 profile()->GetHostContentSettingsMap()->
2549 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252550 }
2551 break;
2552 }
2553
[email protected]e5adff72010-06-14 18:13:062554 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572555 break;
[email protected]a888b29e62010-04-01 13:38:572556
2557 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572558 break;
[email protected]a888b29e62010-04-01 13:38:572559
[email protected]88152052010-10-01 04:05:182560 case NotificationType::GOOGLE_URL_UPDATED:
2561 UpdateAlternateErrorPageURL();
2562 break;
2563
[email protected]420ae012009-04-24 05:16:322564 default:
2565 NOTREACHED();
2566 }
2567}
[email protected]aacd7cc2009-09-02 14:51:102568
[email protected]beb440c2009-11-06 04:08:542569gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2570 return view_->GetTopLevelNativeWindow();
2571}
2572
2573void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2574 bool success,
2575 const std::wstring& prompt) {
2576 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2577 if (is_showing_before_unload_dialog_ && !success) {
2578 // If a beforeunload dialog is canceled, we need to stop the throbber from
2579 // spinning, since we forced it to start spinning in Navigate.
2580 DidStopLoading();
2581
2582 tab_close_start_time_ = base::TimeTicks();
2583 }
2584 is_showing_before_unload_dialog_ = false;
2585 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2586}
2587
2588void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2589 set_suppress_javascript_messages(suppress_message_boxes);
2590}
2591
[email protected]3a3d47472010-07-15 21:03:542592TabContents* TabContents::AsTabContents() {
2593 return this;
2594}
2595
2596ExtensionHost* TabContents::AsExtensionHost() {
2597 return NULL;
2598}
2599
[email protected]41fc0322009-09-04 22:23:402600void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102601 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2602}
[email protected]f45d2a72010-03-08 23:28:352603
2604void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2605 app_icon_ = app_icon;
2606 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2607}
[email protected]33f74972010-12-08 16:40:362608
2609void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2610 render_manager_.SwapInRenderViewHost(rvh);
2611}
2612
2613void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2614 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2615 rwh_view->SetSize(view()->GetContainerSize());
2616}
[email protected]e7d50892011-01-19 21:47:382617
[email protected]232a5812011-03-04 22:42:082618void TabContents::OnOnlineStateChanged(bool online) {
2619 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2620 render_view_host()->routing_id(), online));
2621}